diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2017-02-16 19:15:30 +0100 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2017-02-20 14:36:27 +0100 |
commit | 03a14ff0003e976a4ded70d284bc80adf54bc6c9 (patch) | |
tree | 0a8058af32427e598fcfbc614f0096a37b5aa4ea /platform/darwin/src/run_loop.cpp | |
parent | e2d8a83664a2705edc762ac00dcaf7eead2ae6fd (diff) | |
download | qtlocation-mapboxgl-03a14ff0003e976a4ded70d284bc80adf54bc6c9.tar.gz |
[darwin] move RunLoop initialization to static variable
Diffstat (limited to 'platform/darwin/src/run_loop.cpp')
-rw-r--r-- | platform/darwin/src/run_loop.cpp | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/platform/darwin/src/run_loop.cpp b/platform/darwin/src/run_loop.cpp index 63bd8d2f53..bae8164ab6 100644 --- a/platform/darwin/src/run_loop.cpp +++ b/platform/darwin/src/run_loop.cpp @@ -7,7 +7,11 @@ namespace mbgl { namespace util { -static ThreadLocal<RunLoop>& current = *new ThreadLocal<RunLoop>; +// Use a static function to avoid the static initialization order fiasco. +static auto& current() { + static ThreadLocal<RunLoop> tl; + return tl; +}; class RunLoop::Impl { public: @@ -15,19 +19,20 @@ public: }; RunLoop* RunLoop::Get() { - assert(current.get()); - return current.get(); + assert(current().get()); + return current().get(); } RunLoop::RunLoop(Type) : impl(std::make_unique<Impl>()) { - assert(!current.get()); - current.set(this); + assert(!current().get()); + current().set(this); impl->async = std::make_unique<AsyncTask>(std::bind(&RunLoop::process, this)); } RunLoop::~RunLoop() { - current.set(nullptr); + assert(current().get()); + current().set(nullptr); } void RunLoop::push(std::shared_ptr<WorkTask> task) { |