blob: 9792f1a0998cef9332791ddeacc1779b79abc769 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
#include <mbgl/util/worker.hpp>
#include <mbgl/platform/platform.hpp>
#include <cassert>
namespace mbgl {
class Worker::Impl {
public:
Impl(uv_loop_t*) {}
void doWork(Fn work) {
work();
}
};
Worker::Worker(std::size_t count) {
for (std::size_t i = 0; i < count; i++) {
threads.emplace_back(util::make_unique<util::Thread<Impl>>("Worker", util::ThreadPriority::Low));
}
}
Worker::~Worker() = default;
void Worker::send(Fn&& work, Fn&& after) {
threads[current]->invokeWithResult(&Worker::Impl::doWork, std::move(after), std::move(work));
current = (current + 1) % threads.size();
}
}
|