summaryrefslogtreecommitdiff
path: root/platform/darwin
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2017-02-16 19:15:30 +0100
committerKonstantin Käfer <mail@kkaefer.com>2017-02-20 14:36:27 +0100
commit03a14ff0003e976a4ded70d284bc80adf54bc6c9 (patch)
tree0a8058af32427e598fcfbc614f0096a37b5aa4ea /platform/darwin
parente2d8a83664a2705edc762ac00dcaf7eead2ae6fd (diff)
downloadqtlocation-mapboxgl-03a14ff0003e976a4ded70d284bc80adf54bc6c9.tar.gz
[darwin] move RunLoop initialization to static variable
Diffstat (limited to 'platform/darwin')
-rw-r--r--platform/darwin/src/MGLFoundation.mm4
-rw-r--r--platform/darwin/src/MGLFoundation_Private.h5
-rw-r--r--platform/darwin/src/run_loop.cpp17
3 files changed, 20 insertions, 6 deletions
diff --git a/platform/darwin/src/MGLFoundation.mm b/platform/darwin/src/MGLFoundation.mm
new file mode 100644
index 0000000000..1cc56de298
--- /dev/null
+++ b/platform/darwin/src/MGLFoundation.mm
@@ -0,0 +1,4 @@
+#import "MGLFoundation_Private.h"
+
+/// Initializes the run loop shim that lives on the main thread.
+mbgl::util::RunLoop mgl_runLoop;
diff --git a/platform/darwin/src/MGLFoundation_Private.h b/platform/darwin/src/MGLFoundation_Private.h
new file mode 100644
index 0000000000..940bb1df69
--- /dev/null
+++ b/platform/darwin/src/MGLFoundation_Private.h
@@ -0,0 +1,5 @@
+#import "MGLFoundation.h"
+
+#include <mbgl/util/run_loop.hpp>
+
+extern mbgl::util::RunLoop mgl_runLoop;
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) {