Chromium Code Reviews| Index: include/core/SkInstCnt.h |
| diff --git a/include/core/SkInstCnt.h b/include/core/SkInstCnt.h |
| index e38c42d917a41bc3bc0dcec1e9cf218f525f7828..b3bd23e61dd901643b6f476ca5c613d1789f18ad 100644 |
| --- a/include/core/SkInstCnt.h |
| +++ b/include/core/SkInstCnt.h |
| @@ -20,11 +20,14 @@ |
| #include "SkTypes.h" |
| #if SK_ENABLE_INST_COUNT |
| +#include "SkOnce.h" |
| #include "SkTArray.h" |
| #include "SkThread_platform.h" |
| 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,15 +43,15 @@ extern bool gPrintInstCount; |
| public: \ |
| typedef int (*PFCheckInstCnt)(int level, bool cleanUp); \ |
| SkInstanceCountHelper() { \ |
| - static bool gInited; \ |
| - if (!gInited) { \ |
| - initStep \ |
| - GetChildren() = new SkTArray<PFCheckInstCnt>; \ |
| - gInited = true; \ |
| - } \ |
| + SK_DECLARE_STATIC_ONCE(once); \ |
| + SkOnce<void*>(&once, init, NULL); \ |
| sk_atomic_inc(GetInstanceCountPtr()); \ |
| } \ |
| \ |
| + static void init(void*) { \ |
| + initStep \ |
| + } \ |
| + \ |
| SkInstanceCountHelper(const SkInstanceCountHelper&) { \ |
| sk_atomic_inc(GetInstanceCountPtr()); \ |
| } \ |
| @@ -86,7 +89,7 @@ extern bool gPrintInstCount; |
| if (NULL == SkInstanceCountHelper::GetChildren()) { \ |
| return GetInstanceCount(); \ |
| } \ |
| - SkTArray<int (*)(int, bool)>* children = \ |
| + SkTArray<typename SkInstanceCountHelper::PFCheckInstCnt>* children = \ |
| SkInstanceCountHelper::GetChildren(); \ |
| int childCount = children->count(); \ |
| int count = GetInstanceCount(); \ |
| @@ -105,8 +108,12 @@ extern bool gPrintInstCount; |
| } \ |
| \ |
| static void AddInstChild(int (*childCheckInstCnt)(int, bool)) { \ |
| - if (CheckInstanceCount != childCheckInstCnt && \ |
| - NULL != SkInstanceCountHelper::GetChildren()) { \ |
| + if (CheckInstanceCount != childCheckInstCnt) { \ |
| + SkAutoMutexAcquire ama(SkGetInstCntAddInstChildMutex()); \ |
|
mtklein
2013/12/05 16:06:54
Does this one really need to be a global mutex? S
Kimmo Kinnunen
2013/12/09 07:54:51
Well, they could.. I didn't think they should.
Ch
|
| + if (NULL == SkInstanceCountHelper::GetChildren()) { \ |
| + SkInstanceCountHelper::GetChildren() = \ |
| + new SkTArray<typename SkInstanceCountHelper::PFCheckInstCnt>; \ |
| + } \ |
| SkInstanceCountHelper::GetChildren()->push_back(childCheckInstCnt); \ |
| } \ |
| } |