Open Lighting Architecture: ola::thread::ExecutorInterface Class Reference

| Open Lighting Architecture 0.10.9

Loading...
Searching...
No Matches
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:

## 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

## ◆ DrainCallbacks()

virtual void ola::thread::ExecutorInterface::DrainCallbacks | ( |  | ) |
| pure virtual

Run all callbacks until there are none left.

Implemented in ola::client::SelectServer, ola::io::SelectServer, ola::plugin::karate::PluginAdaptor, ola::plugin::opendmx::PluginAdaptor, ola::PluginAdaptor, ola::SelectServer, ola::thread::ExecutorThread, ola::thread::SelectServer, and SelectServer.

## ◆ Execute()

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

Execute the supplied callback at some point in the future.

Parameters

  callback | the 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::client::SelectServer, ola::io::SelectServer, ola::plugin::karate::PluginAdaptor, ola::plugin::opendmx::PluginAdaptor, ola::PluginAdaptor, ola::SelectServer, ola::thread::ExecutorThread, ola::thread::SelectServer, and SelectServer.

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

- include/ola/thread/ExecutorInterface.h