openthread-br
0.3.0-72c0388
|
#include <src/common/task_runner.hpp>
Public Types | |
template<class T > | |
using | Task = std::function< T(void)> |
typedef uint64_t | TaskId |
Public Member Functions | |
TaskRunner (void) | |
~TaskRunner (void) override | |
void | Post (Task< void > aTask) |
TaskId | Post (Milliseconds aDelay, Task< void > aTask) |
void | Cancel (TaskId aTaskId) |
template<class T > | |
T | PostAndWait (const Task< T > &aTask) |
void | Update (MainloopContext &aMainloop) override |
void | Process (const MainloopContext &aMainloop) override |
This class implements the Task Runner that executes tasks on the mainloop.
using otbr::TaskRunner::Task = std::function<T(void)> |
This type represents the generic executable task.
typedef uint64_t otbr::TaskRunner::TaskId |
This type represents a unique task ID to an delayed task.
Note: A valid task ID is never zero.
otbr::TaskRunner::TaskRunner | ( | void | ) |
This constructor initializes the Task Runner instance.
|
override |
This destructor destroys the Task Runner instance.
void otbr::TaskRunner::Cancel | ( | TaskRunner::TaskId | aTaskId | ) |
This method cancels a delayed task from the task runner. It is safe to call this method in different threads concurrently.
[in] | aTaskId | The unique task ID of the delayed task to cancel. |
TaskRunner::TaskId otbr::TaskRunner::Post | ( | Milliseconds | aDelay, |
Task< void > | aTask | ||
) |
This method posts a task to the task runner and returns immediately.
The task will be executed on the mainloop after aDelay
milliseconds from now. It is safe to call this method in different threads concurrently.
[in] | aDelay | The delay before executing the task (in milliseconds). |
[in] | aTask | The task to be executed. |
void otbr::TaskRunner::Post | ( | Task< void > | aTask | ) |
This method posts a task to the task runner and returns immediately.
Tasks are executed sequentially and follow the First-Come-First-Serve rule. It is safe to call this method in different threads concurrently.
[in] | aTask | The task to be executed. |
|
inline |
This method posts a task and waits for the completion of the task.
Tasks are executed sequentially and follow the First-Come-First-Serve rule. This method must be called in a thread other than the mainloop thread. Otherwise, the caller will be blocked forever.
aTask
.
|
overridevirtual |
This method processes mainloop events.
[in] | aMainloop | A reference to the mainloop context. |
Implements otbr::MainloopProcessor.
|
overridevirtual |
This method updates the mainloop context.
[in,out] | aMainloop | A reference to the mainloop to be updated. |
Implements otbr::MainloopProcessor.