C/C++ API Reference
Loading...
Searching...
No Matches
pw::async::Dispatcher Class Referenceabstract

Overview

Abstract base class for an asynchronous dispatcher loop.

Dispatchers 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:

  • Dispatchers can make more efficient use of system resources, since they don't need to maintain separate thread stacks.
  • Dispatchers can run on systems without thread support, such as no-RTOS embedded environments.
  • Dispatchers 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.

Inheritance diagram for pw::async::Dispatcher:
pw::chrono::VirtualClock< SystemClock > pw::async::BasicDispatcher pw::async::FunctionDispatcher pw::async::HeapDispatcher

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
 
- Public Member Functions inherited from pw::chrono::VirtualClock< SystemClock >
virtual SystemClock::time_point now ()=0
 Returns the current time.
 

Additional Inherited Members

- Static Public Member Functions inherited from pw::chrono::VirtualClock< SystemClock >
static VirtualClock< SystemClock > & RealClock ()
 Returns a reference to the real system clock to aid instantiation.
 

The documentation for this class was generated from the following file: