summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvo van Dongen <info@ivovandongen.nl>2017-07-27 17:27:51 +0300
committerIvo van Dongen <info@ivovandongen.nl>2017-08-09 12:13:01 +0300
commit617759d0c8f3c66256c260f966d9b05e3c701f68 (patch)
tree08f2a29cb169c8db63547a30201d579ba986a1a3
parent66ce50d4c33a16d6c7dee3254f89373a543b77b0 (diff)
downloadqtlocation-mapboxgl-upstream/ivd-current-scheduler.tar.gz
[all] add delayed message delivery on run loopupstream/ivd-current-scheduler
-rw-r--r--platform/android/src/run_loop.cpp8
-rw-r--r--platform/darwin/src/run_loop.cpp11
-rw-r--r--platform/default/run_loop.cpp5
-rw-r--r--platform/node/src/node_thread_pool.hpp6
-rw-r--r--platform/qt/src/run_loop.cpp5
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 <mbgl/util/platform.hpp>
-#include <mbgl/util/thread_local.hpp>
#include <mbgl/util/thread.hpp>
#include <mbgl/util/timer.hpp>
+#include <mbgl/util/scheduled_timer.hpp>
#include <mbgl/actor/scheduler.hpp>
#include <android/looper.h>
@@ -200,7 +200,7 @@ Milliseconds RunLoop::Impl::processRunnables() {
}
RunLoop* RunLoop::Get() {
- assert(static_cast<RunLoop*>(Scheduler::GetCurrent()));
+ assert(dynamic_cast<RunLoop*>(Scheduler::GetCurrent()));
return static_cast<RunLoop*>(Scheduler::GetCurrent());
}
@@ -258,5 +258,9 @@ void RunLoop::removeWatch(int) {
throw std::runtime_error("Not implemented.");
}
+std::unique_ptr<Scheduler::Scheduled> RunLoop::schedule(Duration timeout, std::weak_ptr<Mailbox> mailbox, std::unique_ptr<Message> message) {
+ return std::make_unique<ScheduledTimer>(*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 <mbgl/util/run_loop.hpp>
#include <mbgl/util/async_task.hpp>
+#include <mbgl/util/timer.hpp>
+#include <mbgl/util/platform.hpp>
+#include <mbgl/actor/mailbox.hpp>
+#include <mbgl/actor/message.hpp>
#include <mbgl/actor/scheduler.hpp>
+#include <mbgl/util/scheduled_timer.hpp>
#include <CoreFoundation/CoreFoundation.h>
@@ -13,7 +18,7 @@ public:
};
RunLoop* RunLoop::Get() {
- assert(static_cast<RunLoop*>(Scheduler::GetCurrent()));
+ assert(dynamic_cast<RunLoop*>(Scheduler::GetCurrent()));
return static_cast<RunLoop*>(Scheduler::GetCurrent());
}
@@ -45,6 +50,10 @@ void RunLoop::runOnce() {
void RunLoop::stop() {
invoke([&] { CFRunLoopStop(CFRunLoopGetCurrent()); });
}
+
+std::unique_ptr<Scheduler::Scheduled> RunLoop::schedule(Duration timeout, std::weak_ptr<Mailbox> mailbox, std::unique_ptr<Message> message) {
+ return std::make_unique<ScheduledTimer>(*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 <mbgl/util/run_loop.hpp>
#include <mbgl/util/async_task.hpp>
#include <mbgl/util/thread_local.hpp>
+#include <mbgl/util/scheduled_timer.hpp>
#include <mbgl/actor/scheduler.hpp>
#include <uv.h>
@@ -215,6 +216,10 @@ void RunLoop::removeWatch(int fd) {
uv_close(reinterpret_cast<uv_handle_t*>(&watch->poll), &Watch::onClose);
}
+
+std::unique_ptr<Scheduler::Scheduled> RunLoop::schedule(Duration timeout, std::weak_ptr<Mailbox> mailbox, std::unique_ptr<Message> message) {
+ return std::make_unique<ScheduledTimer>(*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<mbgl::Mailbox>) override;
+
+ std::unique_ptr<Scheduled> schedule(mbgl::Duration, std::weak_ptr<mbgl::Mailbox>, std::unique_ptr<mbgl::Message>) override {
+ // Not implemented
+ assert(false);
+ return {};
+ };
private:
util::AsyncQueue<std::weak_ptr<mbgl::Mailbox>>* 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 <mbgl/actor/scheduler.hpp>
+#include <mbgl/util/scheduled_timer.hpp>
#include <QCoreApplication>
@@ -119,6 +120,10 @@ void RunLoop::removeWatch(int fd) {
impl->readPoll.erase(readPollIter);
}
}
+
+std::unique_ptr<Scheduler::Scheduled> RunLoop::schedule(Duration timeout, std::weak_ptr<Mailbox> mailbox, std::unique_ptr<Message> message) {
+ return std::make_unique<ScheduledTimer>(*this, timeout, std::move(mailbox), std::move(message));
+}
}
}