mirror of
https://github.com/TomHarte/CLK.git
synced 2024-11-22 12:33:29 +00:00
Switch to unique_ptr
.
This commit is contained in:
parent
8ba1b4e0cf
commit
e994910ff6
@ -88,16 +88,17 @@ DeferringAsyncTaskQueue::~DeferringAsyncTaskQueue() {
|
||||
|
||||
void DeferringAsyncTaskQueue::defer(std::function<void(void)> function) {
|
||||
if(!deferred_tasks_) {
|
||||
deferred_tasks_ = std::make_shared<std::list<std::function<void(void)>>>();
|
||||
deferred_tasks_ = std::make_unique<std::list<std::function<void(void)>>>();
|
||||
}
|
||||
deferred_tasks_->push_back(function);
|
||||
}
|
||||
|
||||
void DeferringAsyncTaskQueue::perform() {
|
||||
if(!deferred_tasks_) return;
|
||||
std::shared_ptr<std::list<std::function<void(void)>>> deferred_tasks = deferred_tasks_;
|
||||
auto deferred_tasks_raw = deferred_tasks_.release();
|
||||
deferred_tasks_.reset();
|
||||
enqueue([deferred_tasks] {
|
||||
enqueue([deferred_tasks_raw] {
|
||||
std::unique_ptr<std::list<std::function<void(void)>>> deferred_tasks(deferred_tasks_raw);
|
||||
for(const auto &function : *deferred_tasks) {
|
||||
function();
|
||||
}
|
||||
|
@ -93,9 +93,7 @@ class DeferringAsyncTaskQueue: public AsyncTaskQueue {
|
||||
void flush();
|
||||
|
||||
private:
|
||||
// TODO: this is a shared_ptr because of the issues capturing moveables in C++11;
|
||||
// switch to a unique_ptr if/when adapting to C++14
|
||||
std::shared_ptr<std::list<std::function<void(void)>>> deferred_tasks_;
|
||||
std::unique_ptr<std::list<std::function<void(void)>>> deferred_tasks_;
|
||||
};
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user