Open Lighting Architecture  Latest Git
Public Member Functions | List of all members
ola::thread::ExecutorInterface Class Referenceabstract

Detailed Description

Defer execution of a callback.

The executor interface provides a method to defer execution of a callback. Often we want to break the call stack, say if we need to run a callback that modify / delete a non-reentrant object in our call stack.

Inheritance diagram for ola::thread::ExecutorInterface:
Inheritance graph
[legend]

Public Member Functions

virtual void Execute (ola::BaseCallback0< void > *callback)=0
 Execute the supplied callback at some point in the future. More...
 
virtual void DrainCallbacks ()=0
 Run all callbacks until there are none left.
 

Member Function Documentation

◆ Execute()

virtual void ola::thread::ExecutorInterface::Execute ( ola::BaseCallback0< void > *  callback)
pure virtual

Execute the supplied callback at some point in the future.

Parameters
callbackthe callback to run.

This method provides the following guarantees:

  • The callback will not be run immediately.
  • The callback will be run at some point in the future. That is, the callback will not leak. Any remaining pending callbacks will be run during the destruction of the class implementing ExecutorInterface.
  • For a given thread, callbacks will be run in the order in which they were added.

When queuing callbacks, you need to ensure that either:

  • The objects used in the callback outlive the ExecutorInterface
  • That the callback is run before the objects are deleted.

To achieve the latter it's common to keep track of the number of outstanding callbacks and then call DrainCallbacks() in the destructor if the number of outstanding callbacks is non-0.

Implemented in ola::io::SelectServer, ola::PluginAdaptor, and ola::thread::ExecutorThread.


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