|
KiwiScheduler
|
The manager of tasks. More...
Classes | |
| class | Task |
| The task that can be added to a scheduler. More... | |
| class | Timer |
| The timer is the pure virtual class that used by task. More... | |
Public Types | |
| using | id_t = uint32_t |
| using | time_point_t = size_t |
Public Member Functions | |
| void | prepare (id_t const queue_id) |
| Prepare the scheduler for a specific queue. More... | |
| void | perform (time_point_t const time) |
| Performs the tasks until the specified time. More... | |
| void | add (Task &task, time_point_t const time) |
| Adds a task at a specified time. More... | |
| void | remove (Task &task) |
| Removes a task. More... | |
The manager of tasks.
The scheduler manages a set of tasks inside several queues. It a single consumer but it can accepts several producer defined by ids, that match with queues. So to add several events in a concurrency context, you need a use a different id for each thread. And of course, you can use several ids inside the same thread.
| void add | ( | Task & | task, |
| time_point_t const | time | ||
| ) |
Adds a task at a specified time.
The method performs adds a task of to its queues, and allocate a new queue if needed. Only one instance of a task can be added to a queue because the task owns its time point, so if the queue owns two instances of the same task one of these instances won't have the right time. Therefore, the task is removed from the queue if it has already been added and not consumed. The task is already defined by a queue's id, so at the end only one instance of a task can be added to a scheduler.
| task | The task to add. |
| time | The time point where the task should be inserted. |
| void perform | ( | time_point_t const | time | ) |
Performs the tasks until the specified time.
The method performs all the tasks of all the queues, until the defined time point. So for each queue, the method calls all the task before the specified time and then adds tasks that could have been added during this operation.
| time | The time point. |
| void prepare | ( | id_t const | queue_id | ) |
Prepare the scheduler for a specific queue.
If a queue has never been used, the first use of queue calls its allocator. If for some case, you want to avoid this allocation, for example in the audio thead, you can this method to pre-allocate the queue.
| queue_id | The id of the queue to prepare. |
| void remove | ( | Task & | task | ) |
Removes a task.
This method removes a task from its queue.
| task | The task to remove. |
1.8.11