summaryrefslogtreecommitdiff
path: root/platform/darwin/src/run_loop.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'platform/darwin/src/run_loop.cpp')
-rw-r--r--platform/darwin/src/run_loop.cpp17
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) {