diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2019-04-07 13:55:47 +0200 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2019-04-08 14:41:16 +0200 |
commit | 8f331f5ae39820b01775df77064419c6cadefa16 (patch) | |
tree | 4e882de96c8945622c2fd89d95548255c1d9cf0b /src | |
parent | 9c8ee53cd8fe22a024627edb8050d1ab8c3da905 (diff) | |
download | qtlocation-mapboxgl-8f331f5ae39820b01775df77064419c6cadefa16.tar.gz |
[core] refactor ThreadLocal backend
Diffstat (limited to 'src')
-rw-r--r-- | src/mbgl/util/thread_local.hpp | 38 |
1 files changed, 25 insertions, 13 deletions
diff --git a/src/mbgl/util/thread_local.hpp b/src/mbgl/util/thread_local.hpp index b0e26356b4..cf5579a2ba 100644 --- a/src/mbgl/util/thread_local.hpp +++ b/src/mbgl/util/thread_local.hpp @@ -1,29 +1,41 @@ #pragma once -#include <mbgl/util/noncopyable.hpp> - -#include <memory> +#include <type_traits> namespace mbgl { namespace util { +namespace impl { + +class ThreadLocalBase { +protected: + ThreadLocalBase(); + ~ThreadLocalBase(); + + void* get(); + void set(void*); + +private: + std::aligned_storage_t<sizeof(void*), alignof(void*)> storage; +}; + +} // namespace impl template <class T> -class ThreadLocal : public noncopyable { +class ThreadLocal : public impl::ThreadLocalBase { public: + ThreadLocal() = default; + ThreadLocal(T* val) { - ThreadLocal(); set(val); } - ThreadLocal(); - ~ThreadLocal(); - - T* get(); - void set(T* ptr); + T* get() { + return reinterpret_cast<T*>(impl::ThreadLocalBase::get()); + } -private: - class Impl; - std::unique_ptr<Impl> impl; + void set(T* ptr) { + impl::ThreadLocalBase::set(ptr); + } }; } // namespace util |