Chromium Code Reviews| Index: include/core/SkInstCnt.h |
| diff --git a/include/core/SkInstCnt.h b/include/core/SkInstCnt.h |
| index e38c42d917a41bc3bc0dcec1e9cf218f525f7828..be1b06ef7c7da73298df4c18d219fab5cadcee62 100644 |
| --- a/include/core/SkInstCnt.h |
| +++ b/include/core/SkInstCnt.h |
| @@ -25,6 +25,8 @@ |
| extern bool gPrintInstCount; |
| +SkBaseMutex& SkGetInstCntAddInstChildMutex(); |
| + |
| // The non-root classes just register themselves with their parent |
| #define SK_DECLARE_INST_COUNT(className) \ |
| SK_DECLARE_INST_COUNT_INTERNAL(className, \ |
| @@ -40,13 +42,14 @@ extern bool gPrintInstCount; |
| public: \ |
| typedef int (*PFCheckInstCnt)(int level, bool cleanUp); \ |
| SkInstanceCountHelper() { \ |
| - static bool gInited; \ |
| - if (!gInited) { \ |
| - initStep \ |
| - GetChildren() = new SkTArray<PFCheckInstCnt>; \ |
| - gInited = true; \ |
| + if (0 == sk_atomic_inc(GetInstanceCountPtr())) { \ |
| + sk_membar_aquire__after_atomic_dec(); \ |
| + static bool gInited; \ |
|
bsalomon
2013/12/04 15:04:19
Perhaps we should use SK_DECLARE_STATIC_ONCE()/SkO
bungeman-skia
2013/12/04 15:24:45
Seconded.
Kimmo Kinnunen
2013/12/05 08:03:23
Done.
|
| + if (!gInited) { \ |
| + initStep \ |
| + gInited = true; \ |
| + } \ |
| } \ |
| - sk_atomic_inc(GetInstanceCountPtr()); \ |
| } \ |
| \ |
| SkInstanceCountHelper(const SkInstanceCountHelper&) { \ |
| @@ -105,8 +108,11 @@ extern bool gPrintInstCount; |
| } \ |
| \ |
| static void AddInstChild(int (*childCheckInstCnt)(int, bool)) { \ |
| - if (CheckInstanceCount != childCheckInstCnt && \ |
| - NULL != SkInstanceCountHelper::GetChildren()) { \ |
| + if (CheckInstanceCount != childCheckInstCnt) { \ |
| + SkAutoMutexAcquire ama(SkGetInstCntAddInstChildMutex()); \ |
| + if (NULL == SkInstanceCountHelper::GetChildren()) { \ |
|
robertphillips
2013/12/04 14:01:22
Why not use PFCheckInstCnt here?
Kimmo Kinnunen
2013/12/05 08:03:23
I was confused with the previous need for separate
|
| + SkInstanceCountHelper::GetChildren() = new SkTArray<int (*)(int, bool)>; \ |
| + } \ |
| SkInstanceCountHelper::GetChildren()->push_back(childCheckInstCnt); \ |
| } \ |
| } |