aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/gpu/GrResourceKey.h
diff options
context:
space:
mode:
authorGravatar bsalomon <bsalomon@google.com>2015-12-17 08:15:47 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2015-12-17 08:15:47 -0800
commitf0795ab1f2556b5ef45ee48983c32d5d0be0a8da (patch)
treec9233f587f55895cb8dddd4e1bf41bcf8234c66a /include/gpu/GrResourceKey.h
parentc834ab178e56009875dee8d2265dba35cf6e1e55 (diff)
Fix thread-unsafe construction of GrUniqueKey in GR_DEFINE_STATIC_UNIQUE_KEY
Diffstat (limited to 'include/gpu/GrResourceKey.h')
-rw-r--r--include/gpu/GrResourceKey.h10
1 files changed, 6 insertions, 4 deletions
diff --git a/include/gpu/GrResourceKey.h b/include/gpu/GrResourceKey.h
index 9958cfc872..ff83a43104 100644
--- a/include/gpu/GrResourceKey.h
+++ b/include/gpu/GrResourceKey.h
@@ -293,11 +293,13 @@ private:
#define GR_DECLARE_STATIC_UNIQUE_KEY(name) SK_DECLARE_STATIC_ONCE(name##_once)
/** Place inside function where the key is used. */
-#define GR_DEFINE_STATIC_UNIQUE_KEY(name) \
- static GrUniqueKey name; \
- SkOnce(&name##_once, gr_init_static_unique_key_once, &name)
+#define GR_DEFINE_STATIC_UNIQUE_KEY(name) \
+ static SkAlignedSTStorage<1, GrUniqueKey> name##_storage; \
+ SkOnce(&name##_once, gr_init_static_unique_key_once, &name##_storage); \
+ static const GrUniqueKey& name = *reinterpret_cast<GrUniqueKey*>(name##_storage.get());
-static inline void gr_init_static_unique_key_once(GrUniqueKey* key) {
+static inline void gr_init_static_unique_key_once(SkAlignedSTStorage<1,GrUniqueKey>* keyStorage) {
+ GrUniqueKey* key = new (keyStorage->get()) GrUniqueKey;
GrUniqueKey::Builder builder(key, GrUniqueKey::GenerateDomain(), 0);
}