blob: cfad70d8dd0afa8b749a6723f89391bcd9b4fc64 (
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
31
32
33
34
35
36
37
38
39
|
#include <mbgl/util/async_task.hpp>
#include "async_task_impl.hpp"
#include <mbgl/util/run_loop.hpp>
namespace mbgl {
namespace util {
AsyncTask::Impl::Impl(std::function<void()>&& fn)
: runLoop(RunLoop::Get()),
task(std::move(fn)) {
connect(this, SIGNAL(send(void)), this, SLOT(runTask(void)), Qt::QueuedConnection);
}
void AsyncTask::Impl::maySend() {
if (!queued.test_and_set()) {
emit send();
}
}
void AsyncTask::Impl::runTask() {
queued.clear();
task();
}
AsyncTask::AsyncTask(std::function<void()>&& fn)
: impl(std::make_unique<Impl>(std::move(fn))) {
}
AsyncTask::~AsyncTask() {
}
void AsyncTask::send() {
impl->maySend();
}
}
}
|