summaryrefslogtreecommitdiff
path: root/src/mbgl/util/worker.cpp
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2015-05-02 13:31:56 -0400
committerJohn Firebaugh <john.firebaugh@gmail.com>2015-05-04 15:09:19 -0700
commit5c7867f435f9d94109ce11fcbbd153b016e02fe0 (patch)
tree5879bdf22b3f8d757c730378b0a2dc49a81fa15d /src/mbgl/util/worker.cpp
parente476fcbf3be861b4b080d647fd7d7fa71570c86a (diff)
downloadqtlocation-mapboxgl-5c7867f435f9d94109ce11fcbbd153b016e02fe0.tar.gz
Join worker tasks before destroying TileData
Fixes #1309
Diffstat (limited to 'src/mbgl/util/worker.cpp')
-rw-r--r--src/mbgl/util/worker.cpp14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/mbgl/util/worker.cpp b/src/mbgl/util/worker.cpp
index 9792f1a099..7f5620e1fa 100644
--- a/src/mbgl/util/worker.cpp
+++ b/src/mbgl/util/worker.cpp
@@ -2,6 +2,7 @@
#include <mbgl/platform/platform.hpp>
#include <cassert>
+#include <future>
namespace mbgl {
@@ -9,8 +10,8 @@ class Worker::Impl {
public:
Impl(uv_loop_t*) {}
- void doWork(Fn work) {
- work();
+ void doWork(std::packaged_task<void ()>& task) {
+ task();
}
};
@@ -22,9 +23,14 @@ Worker::Worker(std::size_t count) {
Worker::~Worker() = default;
-void Worker::send(Fn&& work, Fn&& after) {
- threads[current]->invokeWithResult(&Worker::Impl::doWork, std::move(after), std::move(work));
+WorkRequest Worker::send(Fn work, Fn after) {
+ std::packaged_task<void ()> task(work);
+ std::future<void> future = task.get_future();
+
+ threads[current]->invokeWithResult(&Worker::Impl::doWork, std::move(after), task);
+
current = (current + 1) % threads.size();
+ return WorkRequest(std::move(future));
}
}