summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/mbgl/util/run_loop.hpp12
-rw-r--r--platform/android/src/run_loop.cpp7
-rw-r--r--platform/darwin/src/run_loop.cpp7
-rw-r--r--platform/default/run_loop.cpp7
-rw-r--r--platform/qt/src/run_loop.cpp7
5 files changed, 16 insertions, 24 deletions
diff --git a/include/mbgl/util/run_loop.hpp b/include/mbgl/util/run_loop.hpp
index acbea80273..ecb18c857b 100644
--- a/include/mbgl/util/run_loop.hpp
+++ b/include/mbgl/util/run_loop.hpp
@@ -76,16 +76,20 @@ private:
using Queue = std::queue<std::shared_ptr<WorkTask>>;
- void push(std::shared_ptr<WorkTask>);
+ // Wakes up the RunLoop so that it starts processing items in the queue.
+ void wake();
- void withMutex(std::function<void()>&& fn) {
+ // Adds a WorkTask to the queue, and wakes it up.
+ void push(std::shared_ptr<WorkTask> task) {
std::lock_guard<std::mutex> lock(mutex);
- fn();
+ queue.push(std::move(task));
+ wake();
}
void process() {
+ std::unique_lock<std::mutex> lock(mutex);
Queue queue_;
- withMutex([&] { queue_.swap(queue); });
+ lock.unlock();
while (!queue_.empty()) {
(*(queue_.front()))();
diff --git a/platform/android/src/run_loop.cpp b/platform/android/src/run_loop.cpp
index 1d284a9e72..34366d836a 100644
--- a/platform/android/src/run_loop.cpp
+++ b/platform/android/src/run_loop.cpp
@@ -216,11 +216,8 @@ LOOP_HANDLE RunLoop::getLoopHandle() {
return Get()->impl.get();
}
-void RunLoop::push(std::shared_ptr<WorkTask> task) {
- withMutex([&] {
- queue.push(std::move(task));
- impl->wake();
- });
+void RunLoop::wake() {
+ impl->wake();
}
void RunLoop::run() {
diff --git a/platform/darwin/src/run_loop.cpp b/platform/darwin/src/run_loop.cpp
index d60a88cf52..0778b004e5 100644
--- a/platform/darwin/src/run_loop.cpp
+++ b/platform/darwin/src/run_loop.cpp
@@ -29,11 +29,8 @@ RunLoop::~RunLoop() {
Scheduler::SetCurrent(nullptr);
}
-void RunLoop::push(std::shared_ptr<WorkTask> task) {
- withMutex([&] {
- queue.push(std::move(task));
- impl->async->send();
- });
+void RunLoop::wake() {
+ impl->async->send();
}
void RunLoop::run() {
diff --git a/platform/default/run_loop.cpp b/platform/default/run_loop.cpp
index 5bccd21d56..868ee72114 100644
--- a/platform/default/run_loop.cpp
+++ b/platform/default/run_loop.cpp
@@ -129,11 +129,8 @@ LOOP_HANDLE RunLoop::getLoopHandle() {
return Get()->impl->loop;
}
-void RunLoop::push(std::shared_ptr<WorkTask> task) {
- withMutex([&] {
- queue.push(std::move(task));
- impl->async->send();
- });
+void RunLoop::wake() {
+ impl->async->send();
}
void RunLoop::run() {
diff --git a/platform/qt/src/run_loop.cpp b/platform/qt/src/run_loop.cpp
index af0c50ebb9..c25243c8e7 100644
--- a/platform/qt/src/run_loop.cpp
+++ b/platform/qt/src/run_loop.cpp
@@ -52,11 +52,8 @@ LOOP_HANDLE RunLoop::getLoopHandle() {
return nullptr;
}
-void RunLoop::push(std::shared_ptr<WorkTask> task) {
- withMutex([&] {
- queue.push(std::move(task));
- impl->async->send();
- });
+void RunLoop::wake() {
+ impl->async->send();
}
void RunLoop::run() {