We use futures to synchronize tasks. Currently tasks can only be function objects which then are executed in one pice (whitout pause).
This diff extends tasks to also include "repeating tasks". "repeating tasks" do after a delay re-invoke the function object untill an invokation returns Repeating::Result::Stop or the task is canceled externaly (via .CancelOrWait()).
TaskManager
To make it easier to write more "algorithms" the TaskManager should be as flexible as possible. It should not handle rescheduling.
The TaskManager has to be extendet to delay a task.
There is a new queue. Which holds a struct with a task and a timepoint. The timepoint coresponds to the time when the task should be executed. The queue is ordered (std::priority_queue) by the time when it should be executed first (chronological) first (queue order).
Every WorkerThread which is waiting on the m_ConditionVariable does waikup after some time (wait_for instead of wait).
Before checking for a TaskPriority::NORMAL task the new queue is checked. If the execution time of the first task is in the past that task is poped and executed.
The wakeup of the m_ConditionVariable could be adopted to the execution time of the first task (that's not implemented).
Future
If i make a RepeatingFuture type (which knows how to delay and repeat) it is complicated to send the signal to that RepeatingFuture. A thread would have to be waiting on the a condition_variable or the SharedState would have to store a refference to the RepeatingFuture which in turn would make it hard to make the RepeatingFuture moveable. The solution i came up with is that "the thing which knows how to repeat" is not the Future type but the PackagedTask. That does also enable me to reuse the existing Future.
There is a new ShareState which holds in addition to the function object the delay duration and the scheduler in which the task can be scheduled.
There is a new PackagedTask which (like the old PackagedTask) only holds a pointer to the SharedState. The reason that there is a new one is that It does (know how to) delay and repeat the task.
In my git branch the SharedState knows how to delay and repeat itself. So there is no extra PackagedTask.