From 617759d0c8f3c66256c260f966d9b05e3c701f68 Mon Sep 17 00:00:00 2001 From: Ivo van Dongen Date: Thu, 27 Jul 2017 17:27:51 +0300 Subject: [all] add delayed message delivery on run loop --- platform/android/src/run_loop.cpp | 8 ++++++-- platform/darwin/src/run_loop.cpp | 11 ++++++++++- platform/default/run_loop.cpp | 5 +++++ platform/node/src/node_thread_pool.hpp | 6 ++++++ platform/qt/src/run_loop.cpp | 5 +++++ 5 files changed, 32 insertions(+), 3 deletions(-) diff --git a/platform/android/src/run_loop.cpp b/platform/android/src/run_loop.cpp index dff7d1d984..9ce9278b8c 100644 --- a/platform/android/src/run_loop.cpp +++ b/platform/android/src/run_loop.cpp @@ -1,9 +1,9 @@ #include "run_loop_impl.hpp" #include -#include #include #include +#include #include #include @@ -200,7 +200,7 @@ Milliseconds RunLoop::Impl::processRunnables() { } RunLoop* RunLoop::Get() { - assert(static_cast(Scheduler::GetCurrent())); + assert(dynamic_cast(Scheduler::GetCurrent())); return static_cast(Scheduler::GetCurrent()); } @@ -258,5 +258,9 @@ void RunLoop::removeWatch(int) { throw std::runtime_error("Not implemented."); } +std::unique_ptr RunLoop::schedule(Duration timeout, std::weak_ptr mailbox, std::unique_ptr message) { + return std::make_unique(*this, timeout, std::move(mailbox), std::move(message)); +} + } // namespace util } // namespace mbgl diff --git a/platform/darwin/src/run_loop.cpp b/platform/darwin/src/run_loop.cpp index 2ba8f8415b..206fee0531 100644 --- a/platform/darwin/src/run_loop.cpp +++ b/platform/darwin/src/run_loop.cpp @@ -1,6 +1,11 @@ #include #include +#include +#include +#include +#include #include +#include #include @@ -13,7 +18,7 @@ public: }; RunLoop* RunLoop::Get() { - assert(static_cast(Scheduler::GetCurrent())); + assert(dynamic_cast(Scheduler::GetCurrent())); return static_cast(Scheduler::GetCurrent()); } @@ -45,6 +50,10 @@ void RunLoop::runOnce() { void RunLoop::stop() { invoke([&] { CFRunLoopStop(CFRunLoopGetCurrent()); }); } + +std::unique_ptr RunLoop::schedule(Duration timeout, std::weak_ptr mailbox, std::unique_ptr message) { + return std::make_unique(*this, timeout, std::move(mailbox), std::move(message)); +} } // namespace util } // namespace mbgl diff --git a/platform/default/run_loop.cpp b/platform/default/run_loop.cpp index 6375dba78e..a3c659ecf4 100644 --- a/platform/default/run_loop.cpp +++ b/platform/default/run_loop.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include @@ -215,6 +216,10 @@ void RunLoop::removeWatch(int fd) { uv_close(reinterpret_cast(&watch->poll), &Watch::onClose); } + +std::unique_ptr RunLoop::schedule(Duration timeout, std::weak_ptr mailbox, std::unique_ptr message) { + return std::make_unique(*this, timeout, std::move(mailbox), std::move(message)); +} } // namespace util } // namespace mbgl diff --git a/platform/node/src/node_thread_pool.hpp b/platform/node/src/node_thread_pool.hpp index d412e53d3d..91e4ed48a8 100644 --- a/platform/node/src/node_thread_pool.hpp +++ b/platform/node/src/node_thread_pool.hpp @@ -18,6 +18,12 @@ public: ~NodeThreadPool(); void schedule(std::weak_ptr) override; + + std::unique_ptr schedule(mbgl::Duration, std::weak_ptr, std::unique_ptr) override { + // Not implemented + assert(false); + return {}; + }; private: util::AsyncQueue>* queue; diff --git a/platform/qt/src/run_loop.cpp b/platform/qt/src/run_loop.cpp index 71ea19032a..c4af173e7f 100644 --- a/platform/qt/src/run_loop.cpp +++ b/platform/qt/src/run_loop.cpp @@ -1,6 +1,7 @@ #include "run_loop_impl.hpp" #include +#include #include @@ -119,6 +120,10 @@ void RunLoop::removeWatch(int fd) { impl->readPoll.erase(readPollIter); } } + +std::unique_ptr RunLoop::schedule(Duration timeout, std::weak_ptr mailbox, std::unique_ptr message) { + return std::make_unique(*this, timeout, std::move(mailbox), std::move(message)); +} } } -- cgit v1.2.1