@@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user