Abstract base class for an asynchronous dispatcher loop.
Dispatcher
s run many short, non-blocking units of work on a single thread. This approach has a number of advantages compared with executing concurrent tasks on separate threads:
Dispatcher
s can make more efficient use of system resources, since they don't need to maintain separate thread stacks.Dispatcher
s can run on systems without thread support, such as no-RTOS embedded environments.Dispatcher
s allow tasks to communicate with one another without the synchronization overhead of locks, atomics, fences, or volatile
.Thread support: Dispatcher
methods may be safely invoked from any thread, but the resulting tasks will always execute on a single thread. Whether or not methods may be invoked from interrupt context is implementation-defined.
VirtualSystemClock
: Dispatcher
implements VirtualSystemClock
in order to provide a consistent source of (possibly mocked) time information to tasks.
A simple default dispatcher implementation is provided by pw_async_basic
.
Public Member Functions | |
virtual void | Post (Task &task) |
virtual void | PostAfter (Task &task, chrono::SystemClock::duration delay) |
virtual void | PostAt (Task &task, chrono::SystemClock::time_point time)=0 |
virtual bool | Cancel (Task &task)=0 |
![]() | |
virtual SystemClock::time_point | now ()=0 |
Returns the current time. | |
Additional Inherited Members | |
![]() | |
static VirtualClock< SystemClock > & | RealClock () |
Returns a reference to the real system clock to aid instantiation. | |