From eb7f02849c978daa8a415ceebc5d3a8b30d7eaf9 Mon Sep 17 00:00:00 2001 From: Gosha <284210+Lordron@users.noreply.github.com> Date: Sun, 7 May 2023 00:59:37 +0300 Subject: Core/Misc: TaskScheduler cleanup (#28862) -Pass std::chrono types by value, they are small enough to not be passed around by const& -Same applied to Optional -Replace EmptyCallback with nullptr Co-authored-by: Shauren --- src/common/Utilities/TaskScheduler.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'src/common/Utilities/TaskScheduler.cpp') diff --git a/src/common/Utilities/TaskScheduler.cpp b/src/common/Utilities/TaskScheduler.cpp index 4874885eed6..8a5feffd12c 100644 --- a/src/common/Utilities/TaskScheduler.cpp +++ b/src/common/Utilities/TaskScheduler.cpp @@ -24,21 +24,21 @@ TaskScheduler& TaskScheduler::ClearValidator() return *this; } -TaskScheduler& TaskScheduler::Update(success_t const& callback) +TaskScheduler& TaskScheduler::Update(success_t const& callback/* = nullptr*/) { _now = clock_t::now(); Dispatch(callback); return *this; } -TaskScheduler& TaskScheduler::Update(size_t const milliseconds, success_t const& callback) +TaskScheduler& TaskScheduler::Update(size_t const milliseconds, success_t const& callback/* = nullptr*/) { return Update(std::chrono::milliseconds(milliseconds), callback); } -TaskScheduler& TaskScheduler::Async(std::function const& callable) +TaskScheduler& TaskScheduler::Async(std::function callable) { - _asyncHolder.push(callable); + _asyncHolder.emplace(std::move(callable)); return *this; } @@ -73,7 +73,7 @@ TaskScheduler& TaskScheduler::InsertTask(TaskContainer task) return *this; } -void TaskScheduler::Dispatch(success_t const& callback) +void TaskScheduler::Dispatch(success_t const& callback/* = nullptr*/) { // If the validation failed abort the dispatching here. if (!_predicate()) @@ -108,12 +108,13 @@ void TaskScheduler::Dispatch(success_t const& callback) } // On finish call the final callback - callback(); + if (callback) + callback(); } void TaskScheduler::TaskQueue::Push(TaskContainer&& task) { - container.insert(task); + container.emplace(std::move(task)); } auto TaskScheduler::TaskQueue::Pop() -> TaskContainer @@ -164,7 +165,7 @@ bool TaskScheduler::TaskQueue::IsEmpty() const TaskContext& TaskContext::Dispatch(std::function const& apply) { - if (auto const owner = _owner.lock()) + if (std::shared_ptr owner = _owner.lock()) apply(*owner); return *this; -- cgit v1.2.3