Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Unified Diff: include/core/SkInstCnt.h

Issue 99483003: Make leak counters thread-safe (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: aling some slashes Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « gm/convexpaths.cpp ('k') | include/core/SkOnce.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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); \
} \
}
« no previous file with comments | « gm/convexpaths.cpp ('k') | include/core/SkOnce.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698