Join worker tasks before destroying TileData

Fixes #1309
This commit is contained in:
John Firebaugh
2015-05-02 13:31:56 -04:00
parent e476fcbf3b
commit 5c7867f435
11 changed files with 111 additions and 40 deletions

View File

@@ -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));
}
}