aboutsummaryrefslogtreecommitdiff
path: root/src/server/shared/Utilities/TaskScheduler.cpp
diff options
context:
space:
mode:
authorNaios <naios-dev@live.de>2015-06-03 18:24:21 +0200
committerNaios <naios-dev@live.de>2015-06-03 18:37:41 +0200
commitdf80f1900d8ffc5f366ede8e19bfbeaeb82c954c (patch)
treecc70b310f932e48e17db35bfff584d3054b4ac2f /src/server/shared/Utilities/TaskScheduler.cpp
parent45eaeff5537f01256fed944de8587d775aca6b39 (diff)
Core/Shared: Hide the internal shared_ptr of the TaskContext
* use . operator instead of -> to access the TaskContext now. * Add TaskContext::IsExpired to check whether the owner has expired. (cherry picked from commit 151a0f5c5e1133a21c46a8d55c834ff52061c3fa)
Diffstat (limited to 'src/server/shared/Utilities/TaskScheduler.cpp')
-rw-r--r--src/server/shared/Utilities/TaskScheduler.cpp40
1 files changed, 22 insertions, 18 deletions
diff --git a/src/server/shared/Utilities/TaskScheduler.cpp b/src/server/shared/Utilities/TaskScheduler.cpp
index c945ad4dab0..4b261413fd9 100644
--- a/src/server/shared/Utilities/TaskScheduler.cpp
+++ b/src/server/shared/Utilities/TaskScheduler.cpp
@@ -62,7 +62,7 @@ TaskScheduler& TaskScheduler::CancelGroupsOf(std::vector<group_t> const& groups)
TaskScheduler& TaskScheduler::InsertTask(TaskContainer task)
{
- _task_holder.Push(std::forward<TaskContainer>(task));
+ _task_holder.Push(std::move(task));
return *this;
}
@@ -82,11 +82,10 @@ void TaskScheduler::Dispatch()
// Perfect forward the context to the handler
// Use weak references to catch destruction before callbacks.
- TaskContext context(new TaskContextInstance(_task_holder.Pop(),
- std::weak_ptr<TaskScheduler>(self_reference)));
+ TaskContext context(_task_holder.Pop(), std::weak_ptr<TaskScheduler>(self_reference));
// Invoke the context
- context->Invoke();
+ context.Invoke();
}
}
@@ -141,7 +140,7 @@ bool TaskScheduler::TaskQueue::IsEmpty() const
return container.empty();
}
-TaskContextInstance& TaskContextInstance::Dispatch(std::function<TaskScheduler&(TaskScheduler&)> const& apply)
+TaskContext& TaskContext::Dispatch(std::function<TaskScheduler&(TaskScheduler&)> const& apply)
{
if (auto const owner = _owner.lock())
apply(*owner);
@@ -149,56 +148,61 @@ TaskContextInstance& TaskContextInstance::Dispatch(std::function<TaskScheduler&(
return *this;
}
-bool TaskContextInstance::IsInGroup(TaskScheduler::group_t const group) const
+bool TaskContext::IsExpired() const
+{
+ return _owner.expired();
+}
+
+bool TaskContext::IsInGroup(TaskScheduler::group_t const group) const
{
return _task->IsInGroup(group);
}
-TaskContextInstance& TaskContextInstance::SetGroup(TaskScheduler::group_t const group)
+TaskContext& TaskContext::SetGroup(TaskScheduler::group_t const group)
{
_task->_group = group;
return *this;
}
-TaskContextInstance& TaskContextInstance::ClearGroup()
+TaskContext& TaskContext::ClearGroup()
{
_task->_group = boost::none;
return *this;
}
-TaskScheduler::repeated_t TaskContextInstance::GetRepeatCounter() const
+TaskScheduler::repeated_t TaskContext::GetRepeatCounter() const
{
return _task->_repeated;
}
-TaskContextInstance& TaskContextInstance::Async(std::function<void()> const& callable)
+TaskContext& TaskContext::Async(std::function<void()> const& callable)
{
return Dispatch(std::bind(&TaskScheduler::Async, std::placeholders::_1, callable));
}
-TaskContextInstance& TaskContextInstance::CancelAll()
+TaskContext& TaskContext::CancelAll()
{
return Dispatch(std::mem_fn(&TaskScheduler::CancelAll));
}
-TaskContextInstance& TaskContextInstance::CancelGroup(TaskScheduler::group_t const group)
+TaskContext& TaskContext::CancelGroup(TaskScheduler::group_t const group)
{
return Dispatch(std::bind(&TaskScheduler::CancelGroup, std::placeholders::_1, group));
}
-TaskContextInstance& TaskContextInstance::CancelGroupsOf(std::vector<TaskScheduler::group_t> const& groups)
+TaskContext& TaskContext::CancelGroupsOf(std::vector<TaskScheduler::group_t> const& groups)
{
- return Dispatch(std::bind(&TaskScheduler::CancelGroupsOf, std::placeholders::_1, groups));
+ return Dispatch(std::bind(&TaskScheduler::CancelGroupsOf, std::placeholders::_1, std::cref(groups)));
}
-void TaskContextInstance::AssertOnConsumed()
+void TaskContext::AssertOnConsumed() const
{
// This was adapted to TC to prevent static analysis tools from complaining.
// If you encounter this assertion check if you repeat a TaskContext more then 1 time!
- ASSERT(_task && "Bad task logic, task context was consumed already!");
+ ASSERT(!(*_consumed) && "Bad task logic, task context was consumed already!");
}
-void TaskContextInstance::Invoke()
+void TaskContext::Invoke()
{
- _task->_task(shared_from_this());
+ _task->_task(*this);
}