From 126838e7c74f2a8e9fa9333049eccc4585d53024 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Thu, 14 Jul 2022 15:52:31 -0400 Subject: [PATCH] Thanks to `std::swap` and move semantics, there's no need for indirection here. --- Concurrency/AsyncUpdater.hpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/Concurrency/AsyncUpdater.hpp b/Concurrency/AsyncUpdater.hpp index 62625d452..cf241c590 100644 --- a/Concurrency/AsyncUpdater.hpp +++ b/Concurrency/AsyncUpdater.hpp @@ -21,16 +21,15 @@ template class AsyncUpdater { public: template AsyncUpdater(Args&&... args) : performer(std::forward(args)...), - actions_(std::make_unique()), performer_thread_{ [this] { Time::Nanos last_fired = Time::nanos_now(); - auto actions = std::make_unique(); + ActionVector actions; while(!should_quit) { // Wait for new actions to be signalled, and grab them. std::unique_lock lock(condition_mutex_); - while(actions_->empty()) { + while(actions_.empty()) { condition_.wait(lock); } std::swap(actions, actions_); @@ -42,10 +41,10 @@ template class AsyncUpdater { last_fired = time_now; // Perform the actions. - for(const auto& action: *actions) { + for(const auto& action: actions) { action(); } - actions->clear(); + actions.clear(); } } } {} @@ -58,7 +57,7 @@ template class AsyncUpdater { /// Actions may be elided, void update(const std::function &post_action) { std::lock_guard guard(condition_mutex_); - actions_->push_back(post_action); + actions_.push_back(post_action); condition_.notify_all(); } @@ -81,7 +80,7 @@ template class AsyncUpdater { // The list of actions waiting be performed. These will be elided, // increasing their latency, if the emulation thread falls behind. using ActionVector = std::vector>; - std::unique_ptr actions_; + ActionVector actions_; // Necessary synchronisation parts. std::atomic should_quit = false;