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> | 2016-09-08 18:17:33 -0700 |
commit | ea33c3db0f15321e9259a1ddd61012c9f4e7825d (patch) | |
tree | 80050fbe3fc4b33d92702593d390271c6d2cc093 | |
parent | 6687ea8eb9aa90003a55bff02260f053a3f33ea5 (diff) | |
download | qtlocation-mapboxgl-ea33c3db0f15321e9259a1ddd61012c9f4e7825d.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; |