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

Unified Diff: include/core/SkInstCnt.h

Issue 99483003: Make leak counters thread-safe (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: 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 | « no previous file | src/core/SkInstCnt.cpp » ('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..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); \
} \
}
« no previous file with comments | « no previous file | src/core/SkInstCnt.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698