1
0
mirror of https://github.com/TomHarte/CLK.git synced 2026-04-20 10:17:05 +00:00

Adds DeferringAsyncTaskQueue as a base concurrency primitive.

This commit is contained in:
Thomas Harte
2017-12-15 22:14:09 -05:00
parent d66a33f249
commit eb6b612052
2 changed files with 48 additions and 0 deletions
+17
View File
@@ -79,3 +79,20 @@ void AsyncTaskQueue::flush() {
flush_condition->wait(lock);
#endif
}
void DeferringAsyncTaskQueue::defer(std::function<void(void)> function) {
if(!deferred_tasks_) {
deferred_tasks_.reset(new std::list<std::function<void(void)>>);
}
deferred_tasks_->push_back(function);
}
void DeferringAsyncTaskQueue::perform() {
std::shared_ptr<std::list<std::function<void(void)>>> deferred_tasks = deferred_tasks_;
deferred_tasks_.reset();
enqueue([deferred_tasks] {
for(auto &function : *deferred_tasks) {
function();
}
});
}