1
/* libs/graphics/sgl/SkGlobals.cpp
3
** Copyright 2006, The Android Open Source Project
5
** Licensed under the Apache License, Version 2.0 (the "License");
6
** you may not use this file except in compliance with the License.
7
** You may obtain a copy of the License at
9
** http://www.apache.org/licenses/LICENSE-2.0
11
** Unless required by applicable law or agreed to in writing, software
12
** distributed under the License is distributed on an "AS IS" BASIS,
13
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
** See the License for the specific language governing permissions and
15
** limitations under the License.
18
#include "SkGlobals.h"
21
SkGlobals::Rec::~Rec()
25
SkGlobals::Rec* SkGlobals::Find(uint32_t tag, Rec* (*create_proc)())
27
SkGlobals::BootStrap& bootstrap = SkGlobals::GetBootStrap();
29
Rec* rec = bootstrap.fHead;
37
if (create_proc == NULL) // no create proc, just return not found
40
// if we get here, we may need to create one. First grab the mutex, and
41
// search again, creating one if its not found the 2nd time.
43
bootstrap.fMutex.acquire();
45
// search again, now that we have the mutex. Odds are it won't be there, but we check again
46
// just in case it was added by another thread before we grabbed the mutex
48
Rec*& head = bootstrap.fHead;
57
if (rec == NULL && (rec = create_proc()) != NULL)
61
bootstrap.fHead = rec;
64
bootstrap.fMutex.release();
68
void SkGlobals::Init()
72
void SkGlobals::Term()
74
SkGlobals::BootStrap& bootstrap = SkGlobals::GetBootStrap();
76
bootstrap.fMutex.acquire();
78
Rec*& head = bootstrap.fHead;
83
Rec* next = rec->fNext;
88
bootstrap.fHead = NULL;
89
bootstrap.fMutex.release();