diff options
author | Thiago Marcos P. Santos <thiago@mapbox.com> | 2016-08-03 17:53:34 +0300 |
---|---|---|
committer | Thiago Marcos P. Santos <thiago@mapbox.com> | 2017-01-24 11:36:59 +0200 |
commit | 37b748e546e8ab0f1d922891bcdf00906be5ac24 (patch) | |
tree | 9566bff3f19fa5542c69908f74247830748f36c7 | |
parent | 1f3424fafab32431f02c6348382266437bb08aea (diff) | |
download | qtlocation-mapboxgl-37b748e546e8ab0f1d922891bcdf00906be5ac24.tar.gz |
[core] Do not use pthreads on ClassDictionary
Use our own tls abstraction instead.
-rw-r--r-- | src/mbgl/style/class_dictionary.cpp | 16 |
1 files changed, 4 insertions, 12 deletions
diff --git a/src/mbgl/style/class_dictionary.cpp b/src/mbgl/style/class_dictionary.cpp index ec06ee7d9d..42a6e4215a 100644 --- a/src/mbgl/style/class_dictionary.cpp +++ b/src/mbgl/style/class_dictionary.cpp @@ -1,6 +1,6 @@ #include <mbgl/style/class_dictionary.hpp> -#include <pthread.h> +#include <mbgl/util/thread_local.hpp> namespace mbgl { namespace style { @@ -8,20 +8,12 @@ namespace style { ClassDictionary::ClassDictionary() {} ClassDictionary &ClassDictionary::Get() { - static pthread_once_t store_once = PTHREAD_ONCE_INIT; - static pthread_key_t store_key; + static util::ThreadLocal<ClassDictionary> dictionary; - // Create the key. - pthread_once(&store_once, []() { - pthread_key_create(&store_key, [](void *ptr) { - delete reinterpret_cast<ClassDictionary *>(ptr); - }); - }); - - ClassDictionary *ptr = reinterpret_cast<ClassDictionary *>(pthread_getspecific(store_key)); + ClassDictionary *ptr = dictionary.get(); if (ptr == nullptr) { ptr = new ClassDictionary(); - pthread_setspecific(store_key, ptr); + dictionary.set(ptr); } return *ptr; |