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

Unified Diff: include/core/SkInstCnt.h

Issue 419113002: Fix thread unsafe mutex initialization. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 5 months 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
Index: include/core/SkInstCnt.h
diff --git a/include/core/SkInstCnt.h b/include/core/SkInstCnt.h
index 1839ee1dbdc6720d9c6b0870ea10e52dbe901c7a..a401071d80ad3804d4d5100952d94e4fed6d1638 100644
--- a/include/core/SkInstCnt.h
+++ b/include/core/SkInstCnt.h
@@ -73,10 +73,16 @@ extern bool gPrintInstCount;
return gChildren; \
} \
\
+ static void create_mutex(SkMutex** mutex) { \
+ *mutex = SkNEW(SkMutex); \
+ } \
static SkBaseMutex& GetChildrenMutex() { \
- SK_DECLARE_STATIC_MUTEX(childrenMutex); \
- return childrenMutex; \
+ static SkMutex* childrenMutex = (SkMutex*)className::SkInstanceCountHelper::nil; \
mtklein 2014/07/25 12:35:33 Just curious, how come static SkMutex* childrenMut
bungeman-skia 2014/07/25 14:40:40 Because that would require an out of line definiti
+ SK_DECLARE_STATIC_ONCE(once); \
mtklein 2014/07/25 12:35:33 Can't we still use SK_DECLARE_STATIC_MUTEX to make
bungeman-skia 2014/07/25 14:40:40 See above, it's the same situation as the pointer,
+ SkOnce(&once, create_mutex, &childrenMutex); \
+ return *childrenMutex; \
} \
+ static const intptr_t nil = (intptr_t)NULL; \
\
} fInstanceCountHelper; \
\
« no previous file with comments | « bench/MutexBench.cpp ('k') | include/core/SkThread.h » ('j') | src/ports/SkMutex_pthread.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698