Kallisto Linux API
Library for interacting with Kallisto devices
Executor Class Reference

#include <executor.hpp>

Public Types

typedef std::function< void()> ExecutorRunnable
 

Public Member Functions

 Executor (std::string tag, unsigned int nr_threads)
 
 ~Executor ()
 
error::KallistoDetailedResult execute (ExecutorRunnable runnable)
 
error::KallistoDetailedResult shutdown ()
 
error::KallistoDetailedResult shutdownNow ()
 
void awaitShutdown ()
 

Static Public Attributes

static const unsigned int MAXIMUM_NUMBER_THREADS
 
static const unsigned int MINIMUM_NUMBER_THREADS
 

Detailed Description

Class used to schedule ExecutorRunnable to a queue to be run in a background thread. A ExecutorRunnable is a simple std::function<void()> that can be used to run anything needed:

Executor executor("myExecutor", 1);
executor.execute([=](){
doSomething();
});
...

If only one thread is specified, each runnable will be executed sequentially.

Member Typedef Documentation

◆ ExecutorRunnable

typedef std::function<void()> ExecutorRunnable

Declaration of the function to be executed by the Executor.

Constructor & Destructor Documentation

◆ Executor()

Executor ( std::string  tag,
unsigned int  nr_threads 
)

Constructor.

Parameters
tagTag used in logging messages.
nr_threadsNumber of concurrent threads. If the value is > Executor::MAXIMUM_NUMBER_OF_THREADS or < Executor::MINIMUM_NUMBER_OF_THREADS it will be truncated.

◆ ~Executor()

~Executor ( )

Destructor.

Member Function Documentation

◆ awaitShutdown()

void awaitShutdown ( )

Waits for this executor threads termination. Beware that this function does not shutdown the executor.

◆ execute()

Schedules a new runnable to be executed by the Executor.

Parameters
runnableThe function to be executed.
Returns
A detailed result.

◆ shutdown()

Signal threads to finish the runnables in the the backlog and to exit. After this call, no new runnables can be scheduled. This function does not wait for thread termination. Use awaitShutdown() for that.

Returns
A detailed result.

◆ shutdownNow()

Signal threads to exit ASAP. After this call, no new runnables can be scheduled. This function does not wait for thread termination. Use awaitShutdown() for that.

Returns
A detailed result.

Field Documentation

◆ MAXIMUM_NUMBER_THREADS

const unsigned int MAXIMUM_NUMBER_THREADS
static

Maximum number of threads allowed.

◆ MINIMUM_NUMBER_THREADS

const unsigned int MINIMUM_NUMBER_THREADS
static

Minimum number of threads allowed.


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