Fix thread unsafe mutex initialization.
BUG=skia:2779 Committed: https://skia.googlesource.com/skia/+/d6aeb6dc8fe21066f1a2c4813a4256a3acd3edf5 R=robertphillips@google.com, mtklein@google.com, reed@android.com, bsalomon@google.com Author: bungeman@google.com Review URL: https://codereview.chromium.org/419113002
This commit is contained in:
parent
048f422ec6
commit
1ef960b01b
@ -89,11 +89,13 @@ private:
|
||||
#define SK_BASE_MUTEX_INIT { PTHREAD_MUTEX_INITIALIZER, SkDEBUGCODE(0) }
|
||||
|
||||
// Using POD-style initialization prevents the generation of a static initializer.
|
||||
//
|
||||
// Without magic statics there are no thread safety guarantees on initialization
|
||||
// of local statics (even POD).
|
||||
// As a result, it is illegal to SK_DECLARE_STATIC_MUTEX in a function.
|
||||
#define SK_DECLARE_STATIC_MUTEX(name) \
|
||||
static inline void SK_MACRO_APPEND_LINE(name)(){} \
|
||||
static SkBaseMutex name = SK_BASE_MUTEX_INIT
|
||||
// of local statics (even POD). As a result, it is illegal to use
|
||||
// SK_DECLARE_STATIC_MUTEX in a function.
|
||||
//
|
||||
// Because SkBaseMutex is not a primitive, a static SkBaseMutex cannot be
|
||||
// initialized in a class with this macro.
|
||||
#define SK_DECLARE_STATIC_MUTEX(name) namespace {} static SkBaseMutex name = SK_BASE_MUTEX_INIT
|
||||
|
||||
#endif
|
||||
|
@ -74,8 +74,6 @@ class SkMutex : public SkBaseMutex { };
|
||||
|
||||
// Windows currently provides no documented means of POD initializing a CRITICAL_SECTION.
|
||||
// As a result, it is illegal to SK_DECLARE_STATIC_MUTEX in a function.
|
||||
#define SK_DECLARE_STATIC_MUTEX(name) \
|
||||
static inline void SK_MACRO_APPEND_LINE(name)(){} \
|
||||
static SkBaseMutex name
|
||||
#define SK_DECLARE_STATIC_MUTEX(name) namespace{} static SkBaseMutex name
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user