aboutsummaryrefslogtreecommitdiff
path: root/src/common/Utilities/TaskScheduler.cpp
diff options
context:
space:
mode:
authorGosha <284210+Lordron@users.noreply.github.com>2023-05-07 00:59:37 +0300
committerGitHub <noreply@github.com>2023-05-06 23:59:37 +0200
commiteb7f02849c978daa8a415ceebc5d3a8b30d7eaf9 (patch)
tree6aeebd3ac2a13895be155552b188e9d8509c9af3 /src/common/Utilities/TaskScheduler.cpp
parent145bb98ecbc4bb265d5c33cc2bb8358a639d5e98 (diff)
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<group_t> -Replace EmptyCallback with nullptr Co-authored-by: Shauren <shauren.trinity@gmail.com>
Diffstat (limited to 'src/common/Utilities/TaskScheduler.cpp')
-rw-r--r--src/common/Utilities/TaskScheduler.cpp17
1 files changed, 9 insertions, 8 deletions
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<void()> const& callable)
+TaskScheduler& TaskScheduler::Async(std::function<void()> 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<TaskScheduler&(TaskScheduler&)> const& apply)
{
- if (auto const owner = _owner.lock())
+ if (std::shared_ptr<TaskScheduler> owner = _owner.lock())
apply(*owner);
return *this;