Open Lighting Architecture  0.9.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | List of all members
ola::thread::ExecutorInterface Class Reference

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:
ola::thread::ExecutorThread ola::thread::SchedulingExecutorInterface ola::io::SelectServerInterface ola::io::SelectServer ola::PluginAdaptor

Public Member Functions

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

Member Function Documentation

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 ether need to ensure that either:

  • The objects used in the callback outlive the ExecutorInterface
  • That the calback 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: