diff options
author | Ivo van Dongen <info@ivovandongen.nl> | 2017-07-25 15:46:16 +0300 |
---|---|---|
committer | Ivo van Dongen <info@ivovandongen.nl> | 2017-08-08 16:17:00 +0300 |
commit | 1cef65fd431b108ae49cee63678ef61c2e5892df (patch) | |
tree | d55a97ebf86bca7eaaebe0e465071553c93ee305 | |
parent | edd7948893fcd40a24d96b790e21d3dd028cecbe (diff) | |
download | qtlocation-mapboxgl-1cef65fd431b108ae49cee63678ef61c2e5892df.tar.gz |
[core] current scheduler
- Adds a way to set the current scheduler on the thread to be used whenever a mailbox is created that needs to reply on this thread
-rw-r--r-- | cmake/core-files.cmake | 1 | ||||
-rw-r--r-- | include/mbgl/actor/scheduler.hpp | 4 | ||||
-rw-r--r-- | platform/default/thread_local.cpp | 2 | ||||
-rw-r--r-- | src/mbgl/actor/scheduler.cpp | 19 |
4 files changed, 25 insertions, 1 deletions
diff --git a/cmake/core-files.cmake b/cmake/core-files.cmake index 1bbe739256..1a86da6f24 100644 --- a/cmake/core-files.cmake +++ b/cmake/core-files.cmake @@ -8,6 +8,7 @@ set(MBGL_CORE_FILES include/mbgl/actor/message.hpp include/mbgl/actor/scheduler.hpp src/mbgl/actor/mailbox.cpp + src/mbgl/actor/scheduler.cpp # algorithm src/mbgl/algorithm/covered_by_children.hpp diff --git a/include/mbgl/actor/scheduler.hpp b/include/mbgl/actor/scheduler.hpp index 83689c3348..1e8a49c0a7 100644 --- a/include/mbgl/actor/scheduler.hpp +++ b/include/mbgl/actor/scheduler.hpp @@ -33,6 +33,10 @@ class Scheduler { public: virtual ~Scheduler() = default; virtual void schedule(std::weak_ptr<Mailbox>) = 0; + + // Set/Get the current Scheduler for this thread + static Scheduler* GetCurrent(); + static void SetCurrent(Scheduler*); }; } // namespace mbgl diff --git a/platform/default/thread_local.cpp b/platform/default/thread_local.cpp index 7abbaa0146..db70773c12 100644 --- a/platform/default/thread_local.cpp +++ b/platform/default/thread_local.cpp @@ -58,8 +58,8 @@ void ThreadLocal<T>::set(T* ptr) { } } -template class ThreadLocal<RunLoop>; template class ThreadLocal<BackendScope>; +template class ThreadLocal<Scheduler>; template class ThreadLocal<int>; // For unit tests } // namespace util diff --git a/src/mbgl/actor/scheduler.cpp b/src/mbgl/actor/scheduler.cpp new file mode 100644 index 0000000000..d7cdb2737b --- /dev/null +++ b/src/mbgl/actor/scheduler.cpp @@ -0,0 +1,19 @@ +#include <mbgl/actor/scheduler.hpp> +#include <mbgl/util/thread_local.hpp> + +namespace mbgl { + +static auto& current() { + static util::ThreadLocal<Scheduler> scheduler; + return scheduler; +}; + +void Scheduler::SetCurrent(Scheduler* scheduler) { + current().set(scheduler); +} + +Scheduler* Scheduler::GetCurrent() { + return current().get(); +} + +} //namespace mbgl |