diff options
author | Ivo van Dongen <info@ivovandongen.nl> | 2017-07-25 18:35:38 +0300 |
---|---|---|
committer | Ivo van Dongen <ivovandongen@users.noreply.github.com> | 2017-08-09 12:08:21 +0300 |
commit | f4f4d13b70cfc26e44c7cbc679acbe9609ae2936 (patch) | |
tree | f8dcd4f78ddf2f5d3e0227add7cd6bc3603515dd | |
parent | 2a8cc4b3e15037554fb357f882a67472adb4161e (diff) | |
download | qtlocation-mapboxgl-f4f4d13b70cfc26e44c7cbc679acbe9609ae2936.tar.gz |
[all] ensure runloop is the current scheduler
-rw-r--r-- | platform/android/src/file_source.cpp | 4 | ||||
-rw-r--r-- | platform/android/src/run_loop.cpp | 11 | ||||
-rw-r--r-- | platform/darwin/src/MGLOfflineStorage.mm | 3 | ||||
-rw-r--r-- | platform/darwin/src/run_loop.cpp | 20 | ||||
-rw-r--r-- | platform/default/run_loop.cpp | 13 | ||||
-rw-r--r-- | platform/qt/src/run_loop.cpp | 16 | ||||
-rw-r--r-- | platform/qt/src/thread_local.cpp | 4 |
7 files changed, 30 insertions, 41 deletions
diff --git a/platform/android/src/file_source.cpp b/platform/android/src/file_source.cpp index 5d19c506bc..262e3d3c6a 100644 --- a/platform/android/src/file_source.cpp +++ b/platform/android/src/file_source.cpp @@ -1,9 +1,9 @@ #include "file_source.hpp" #include <mbgl/actor/actor.hpp> +#include <mbgl/actor/scheduler.hpp> #include <mbgl/storage/resource_transform.hpp> #include <mbgl/util/logging.hpp> -#include <mbgl/util/run_loop.hpp> #include "asset_manager_file_source.hpp" #include "jni/generic_global_ref_deleter.hpp" @@ -45,7 +45,7 @@ void FileSource::setAPIBaseUrl(jni::JNIEnv& env, jni::String url) { void FileSource::setResourceTransform(jni::JNIEnv& env, jni::Object<FileSource::ResourceTransformCallback> transformCallback) { if (transformCallback) { - resourceTransform = std::make_unique<Actor<ResourceTransform>>(*util::RunLoop::Get(), + resourceTransform = std::make_unique<Actor<ResourceTransform>>(*Scheduler::GetCurrent(), // Capture the ResourceTransformCallback object as a managed global into // the lambda. It is released automatically when we're setting a new ResourceTransform in // a subsequent call. diff --git a/platform/android/src/run_loop.cpp b/platform/android/src/run_loop.cpp index 3c605b70e8..dff7d1d984 100644 --- a/platform/android/src/run_loop.cpp +++ b/platform/android/src/run_loop.cpp @@ -4,6 +4,7 @@ #include <mbgl/util/thread_local.hpp> #include <mbgl/util/thread.hpp> #include <mbgl/util/timer.hpp> +#include <mbgl/actor/scheduler.hpp> #include <android/looper.h> @@ -23,7 +24,6 @@ namespace { using namespace mbgl::util; -static ThreadLocal<RunLoop>& current = *new ThreadLocal<RunLoop>; int looperCallbackNew(int fd, int, void* data) { int buffer[1]; @@ -200,19 +200,20 @@ Milliseconds RunLoop::Impl::processRunnables() { } RunLoop* RunLoop::Get() { - return current.get(); + assert(static_cast<RunLoop*>(Scheduler::GetCurrent())); + return static_cast<RunLoop*>(Scheduler::GetCurrent()); } RunLoop::RunLoop(Type type) : impl(std::make_unique<Impl>(this, type)) { - current.set(this); + Scheduler::SetCurrent(this); } RunLoop::~RunLoop() { - current.set(nullptr); + Scheduler::SetCurrent(nullptr); } LOOP_HANDLE RunLoop::getLoopHandle() { - return current.get()->impl.get(); + return Get()->impl.get(); } void RunLoop::push(std::shared_ptr<WorkTask> task) { diff --git a/platform/darwin/src/MGLOfflineStorage.mm b/platform/darwin/src/MGLOfflineStorage.mm index 2ddfa649e9..7085aa58e5 100644 --- a/platform/darwin/src/MGLOfflineStorage.mm +++ b/platform/darwin/src/MGLOfflineStorage.mm @@ -11,6 +11,7 @@ #import "NSValue+MGLAdditions.h" #include <mbgl/actor/actor.hpp> +#include <mbgl/actor/scheduler.hpp> #include <mbgl/storage/resource_transform.hpp> #include <mbgl/util/run_loop.hpp> #include <mbgl/util/string.hpp> @@ -81,7 +82,7 @@ NSString * const MGLOfflinePackMaximumCountUserInfoKey = MGLOfflinePackUserInfoK - (void)setDelegate:(id<MGLOfflineStorageDelegate>)newValue { _delegate = newValue; if ([self.delegate respondsToSelector:@selector(offlineStorage:URLForResourceOfKind:withURL:)]) { - _mbglResourceTransform = std::make_unique<mbgl::Actor<mbgl::ResourceTransform>>(*mbgl::util::RunLoop::Get(), [offlineStorage = self](auto kind_, const std::string&& url_) -> std::string { + _mbglResourceTransform = std::make_unique<mbgl::Actor<mbgl::ResourceTransform>>(*mbgl::Scheduler::GetCurrent(), [offlineStorage = self](auto kind_, const std::string&& url_) -> std::string { NSURL* url = [NSURL URLWithString:[[NSString alloc] initWithBytes:url_.data() length:url_.length() diff --git a/platform/darwin/src/run_loop.cpp b/platform/darwin/src/run_loop.cpp index bae8164ab6..2ba8f8415b 100644 --- a/platform/darwin/src/run_loop.cpp +++ b/platform/darwin/src/run_loop.cpp @@ -1,38 +1,32 @@ #include <mbgl/util/run_loop.hpp> #include <mbgl/util/async_task.hpp> -#include <mbgl/util/thread_local.hpp> +#include <mbgl/actor/scheduler.hpp> #include <CoreFoundation/CoreFoundation.h> namespace mbgl { namespace util { -// Use a static function to avoid the static initialization order fiasco. -static auto& current() { - static ThreadLocal<RunLoop> tl; - return tl; -}; - class RunLoop::Impl { public: std::unique_ptr<AsyncTask> async; }; RunLoop* RunLoop::Get() { - assert(current().get()); - return current().get(); + assert(static_cast<RunLoop*>(Scheduler::GetCurrent())); + return static_cast<RunLoop*>(Scheduler::GetCurrent()); } RunLoop::RunLoop(Type) : impl(std::make_unique<Impl>()) { - assert(!current().get()); - current().set(this); + assert(!Scheduler::GetCurrent()); + Scheduler::SetCurrent(this); impl->async = std::make_unique<AsyncTask>(std::bind(&RunLoop::process, this)); } RunLoop::~RunLoop() { - assert(current().get()); - current().set(nullptr); + assert(Scheduler::GetCurrent()); + Scheduler::SetCurrent(nullptr); } void RunLoop::push(std::shared_ptr<WorkTask> task) { diff --git a/platform/default/run_loop.cpp b/platform/default/run_loop.cpp index 98d1badcb5..6375dba78e 100644 --- a/platform/default/run_loop.cpp +++ b/platform/default/run_loop.cpp @@ -1,6 +1,7 @@ #include <mbgl/util/run_loop.hpp> #include <mbgl/util/async_task.hpp> #include <mbgl/util/thread_local.hpp> +#include <mbgl/actor/scheduler.hpp> #include <uv.h> @@ -10,9 +11,6 @@ namespace { -using namespace mbgl::util; -static ThreadLocal<RunLoop>& current = *new ThreadLocal<RunLoop>; - void dummyCallback(uv_async_t*) {} } // namespace @@ -53,7 +51,8 @@ struct Watch { }; RunLoop* RunLoop::Get() { - return current.get(); + assert(static_cast<RunLoop*>(Scheduler::GetCurrent())); + return static_cast<RunLoop*>(Scheduler::GetCurrent()); } class RunLoop::Impl { @@ -98,12 +97,12 @@ RunLoop::RunLoop(Type type) : impl(std::make_unique<Impl>()) { impl->type = type; - current.set(this); + Scheduler::SetCurrent(this); impl->async = std::make_unique<AsyncTask>(std::bind(&RunLoop::process, this)); } RunLoop::~RunLoop() { - current.set(nullptr); + Scheduler::SetCurrent(nullptr); // Close the dummy handle that we have // just to keep the main loop alive. @@ -127,7 +126,7 @@ RunLoop::~RunLoop() { } LOOP_HANDLE RunLoop::getLoopHandle() { - return current.get()->impl->loop; + return Get()->impl->loop; } void RunLoop::push(std::shared_ptr<WorkTask> task) { diff --git a/platform/qt/src/run_loop.cpp b/platform/qt/src/run_loop.cpp index c44f284852..71ea19032a 100644 --- a/platform/qt/src/run_loop.cpp +++ b/platform/qt/src/run_loop.cpp @@ -1,6 +1,6 @@ #include "run_loop_impl.hpp" -#include <mbgl/util/thread_local.hpp> +#include <mbgl/actor/scheduler.hpp> #include <QCoreApplication> @@ -8,13 +8,6 @@ #include <functional> #include <utility> -namespace { - -using namespace mbgl::util; -static ThreadLocal<RunLoop>& current = *new ThreadLocal<RunLoop>; - -} - namespace mbgl { namespace util { @@ -27,7 +20,8 @@ void RunLoop::Impl::onWriteEvent(int fd) { } RunLoop* RunLoop::Get() { - return current.get(); + assert(static_cast<RunLoop*>(Scheduler::GetCurrent())); + return static_cast<RunLoop*>(Scheduler::GetCurrent()); } RunLoop::RunLoop(Type type) : impl(std::make_unique<Impl>()) { @@ -42,14 +36,14 @@ RunLoop::RunLoop(Type type) : impl(std::make_unique<Impl>()) { impl->type = type; - current.set(this); + Scheduler::SetCurrent(this); impl->async = std::make_unique<AsyncTask>(std::bind(&RunLoop::process, this)); } RunLoop::~RunLoop() { MBGL_VERIFY_THREAD(tid); - current.set(nullptr); + Scheduler::SetCurrent(nullptr); } LOOP_HANDLE RunLoop::getLoopHandle() { diff --git a/platform/qt/src/thread_local.cpp b/platform/qt/src/thread_local.cpp index bf2103c98f..467bfb0d05 100644 --- a/platform/qt/src/thread_local.cpp +++ b/platform/qt/src/thread_local.cpp @@ -1,6 +1,6 @@ #include <mbgl/util/thread_local.hpp> -#include <mbgl/util/run_loop.hpp> +#include <mbgl/actor/scheduler.hpp> #include <mbgl/renderer/backend_scope.hpp> #include <array> @@ -41,7 +41,7 @@ void ThreadLocal<T>::set(T* ptr) { impl->local.localData()[0] = ptr; } -template class ThreadLocal<RunLoop>; +template class ThreadLocal<Scheduler>; template class ThreadLocal<BackendScope>; template class ThreadLocal<int>; // For unit tests |