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

Side by Side 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2012 Google Inc. 2 * Copyright 2012 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 8
9 #ifndef SkInstCnt_DEFINED 9 #ifndef SkInstCnt_DEFINED
10 #define SkInstCnt_DEFINED 10 #define SkInstCnt_DEFINED
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 static int32_t* GetInstanceCountPtr() { \ 66 static int32_t* GetInstanceCountPtr() { \
67 static int32_t gInstanceCount; \ 67 static int32_t gInstanceCount; \
68 return &gInstanceCount; \ 68 return &gInstanceCount; \
69 } \ 69 } \
70 \ 70 \
71 static SkTArray<int (*)(int, bool)>*& GetChildren() { \ 71 static SkTArray<int (*)(int, bool)>*& GetChildren() { \
72 static SkTArray<int (*)(int, bool)>* gChildren; \ 72 static SkTArray<int (*)(int, bool)>* gChildren; \
73 return gChildren; \ 73 return gChildren; \
74 } \ 74 } \
75 \ 75 \
76 static void create_mutex(SkMutex** mutex) { \
77 *mutex = SkNEW(SkMutex); \
78 } \
76 static SkBaseMutex& GetChildrenMutex() { \ 79 static SkBaseMutex& GetChildrenMutex() { \
77 SK_DECLARE_STATIC_MUTEX(childrenMutex); \ 80 static SkMutex* childrenMutex = (SkMutex*)className::SkInstanceCount Helper::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
78 return childrenMutex; \ 81 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,
82 SkOnce(&once, create_mutex, &childrenMutex); \
83 return *childrenMutex; \
79 } \ 84 } \
85 static const intptr_t nil = (intptr_t)NULL; \
80 \ 86 \
81 } fInstanceCountHelper; \ 87 } fInstanceCountHelper; \
82 \ 88 \
83 static int32_t GetInstanceCount() { \ 89 static int32_t GetInstanceCount() { \
84 return *SkInstanceCountHelper::GetInstanceCountPtr(); \ 90 return *SkInstanceCountHelper::GetInstanceCountPtr(); \
85 } \ 91 } \
86 \ 92 \
87 static void exitPrint() { \ 93 static void exitPrint() { \
88 CheckInstanceCount(0, true); \ 94 CheckInstanceCount(0, true); \
89 } \ 95 } \
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 #define SK_DECLARE_INST_COUNT(className) static void AddInstChild() { INHERITED: :AddInstChild(); } 139 #define SK_DECLARE_INST_COUNT(className) static void AddInstChild() { INHERITED: :AddInstChild(); }
134 #define SK_DECLARE_INST_COUNT_ROOT(className) static void AddInstChild() { } 140 #define SK_DECLARE_INST_COUNT_ROOT(className) static void AddInstChild() { }
135 #endif 141 #endif
136 142
137 // Following are deprecated. They are defined only for backwards API compatibili ty. 143 // Following are deprecated. They are defined only for backwards API compatibili ty.
138 #define SK_DECLARE_INST_COUNT_TEMPLATE(className) SK_DECLARE_INST_COUNT(classNam e) 144 #define SK_DECLARE_INST_COUNT_TEMPLATE(className) SK_DECLARE_INST_COUNT(classNam e)
139 #define SK_DEFINE_INST_COUNT(className) 145 #define SK_DEFINE_INST_COUNT(className)
140 #define SK_DEFINE_INST_COUNT_TEMPLATE(templateInfo, className) 146 #define SK_DEFINE_INST_COUNT_TEMPLATE(templateInfo, className)
141 147
142 #endif // SkInstCnt_DEFINED 148 #endif // SkInstCnt_DEFINED
OLDNEW
« 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