MADARA  3.2.3
madara::threads::Threader Class Reference

Starts threads with first class support of MADARA contexts. More...

#include <Threader.h>

Public Member Functions

 Threader ()
 Default constructor. More...
 
 Threader (knowledge::KnowledgeBase data_plane)
 Constructor. More...
 
 Threader (const Threader &)=delete
 
 Threader (Threader &&)=default
 
 ~Threader ()
 Destructor. More...
 
void change_hertz (const std::string name, double hertz)
 Modify hertz rate of a thread. More...
 
knowledge::KnowledgeBase get_control_plane (void)
 Gets the control plane used by threads. More...
 
knowledge::KnowledgeBase get_data_plane (void)
 Gets the data plane used by threads. More...
 
Threaderoperator= (const Threader &)=delete
 
Threaderoperator= (Threader &&)=default
 
void pause (const std::string name)
 Requests a specific thread to pause. More...
 
void pause (void)
 Requests all threads to pause. More...
 
void resume (const std::string name)
 Requests a specific thread to resume (unpause) More...
 
void resume (void)
 Requests all threads to resume (unpause) More...
 
void run (const std::string name, BaseThread *thread, bool paused=false)
 Starts a new thread and executes the provided user thread once. More...
 
void run (double hertz, const std::string name, BaseThread *thread, bool paused=false)
 Starts a new thread and executes the provided user thread at a hertz. More...
 
void run (const std::string name, jobject thread, bool paused=false)
 Starts a new thread and executes the provided user thread once. More...
 
void run (double hertz, const std::string name, jobject thread, bool paused=false)
 Starts a new thread and executes the provided user thread once. More...
 
void set_data_plane (knowledge::KnowledgeBase data_plane)
 Sets the data plane for new threads. More...
 
void terminate (const std::string name)
 Requests a specific thread to terminate. More...
 
void terminate (void)
 Requests all threads to terminate. More...
 
bool wait (const std::string name, const knowledge::WaitSettings &ws=knowledge::WaitSettings())
 Wait for a specific thread to complete. More...
 
bool wait (const knowledge::WaitSettings &ws=knowledge::WaitSettings())
 Wait for all threads to complete. More...
 

Private Attributes

knowledge::KnowledgeBase control_
 The control plane used by threads for termination and pause information. More...
 
knowledge::KnowledgeBase data_
 The data plane used by threads. More...
 
NamedWorkerThreads threads_
 the threads that are still active More...
 

Detailed Description

Starts threads with first class support of MADARA contexts.

Definition at line 35 of file Threader.h.

Constructor & Destructor Documentation

madara::threads::Threader::Threader ( )

Default constructor.

Definition at line 11 of file Threader.cpp.

madara::threads::Threader::Threader ( knowledge::KnowledgeBase  data_plane)

Constructor.

Parameters
data_planeThe data plane for threads to use

Definition at line 16 of file Threader.cpp.

madara::threads::Threader::~Threader ( )

Destructor.

Definition at line 22 of file Threader.cpp.

madara::threads::Threader::Threader ( const Threader )
delete
madara::threads::Threader::Threader ( Threader &&  )
default

Member Function Documentation

void madara::threads::Threader::change_hertz ( const std::string  name,
double  hertz 
)
inline

Modify hertz rate of a thread.

This is only useful for periodic threads that are operating at infinite or set hertz rates. If the thread had been started as a run once thread, it cannot be changed to a hertz rate as the thread will be dead. In the latter case, restart the thread at the new hertz rate.

Parameters
nameunique thread name for the thread
hertznew hertz rate for the periodic thread

Definition at line 17 of file Threader.inl.

madara::knowledge::KnowledgeBase madara::threads::Threader::get_control_plane ( void  )
inline

Gets the control plane used by threads.

Returns
the knowledge base used by threader for control of threads

Definition at line 33 of file Threader.inl.

madara::knowledge::KnowledgeBase madara::threads::Threader::get_data_plane ( void  )
inline

Gets the data plane used by threads.

Returns
the knowledge base used by threads for data

Definition at line 23 of file Threader.inl.

Threader& madara::threads::Threader::operator= ( const Threader )
delete
Threader& madara::threads::Threader::operator= ( Threader &&  )
default
void madara::threads::Threader::pause ( const std::string  name)

Requests a specific thread to pause.

Parameters
nameunique thread name for the thread.

Definition at line 29 of file Threader.cpp.

void madara::threads::Threader::pause ( void  )

Requests all threads to pause.

Definition at line 40 of file Threader.cpp.

void madara::threads::Threader::resume ( const std::string  name)

Requests a specific thread to resume (unpause)

Parameters
nameunique thread name for the thread.

Definition at line 50 of file Threader.cpp.

void madara::threads::Threader::resume ( void  )

Requests all threads to resume (unpause)

Definition at line 61 of file Threader.cpp.

void madara::threads::Threader::run ( const std::string  name,
BaseThread thread,
bool  paused = false 
)

Starts a new thread and executes the provided user thread once.

Execution ordering is init -> execute -> cleanup.


 
The thread will be managed by the threader. Please do not pass the address of a thread on the stack and do not delete this memory yourself or your program will crash.

Parameters
nameunique thread name for the thread. If possible, try to use one word or words separated by underscores (_)
threaduser-created thread implementation
pausedcreate thread in a paused state.
Exceptions
exceptions::ThreadExceptionbad name (null)

Definition at line 71 of file Threader.cpp.

void madara::threads::Threader::run ( double  hertz,
const std::string  name,
BaseThread thread,
bool  paused = false 
)

Starts a new thread and executes the provided user thread at a hertz.

Execution ordering is init -> *execute -> cleanup. init and cleanup are only called once.


 
The thread will be managed by the threader. Please do not pass the address of a thread on the stack and do not delete this memory yourself or your program will crash.

Parameters
hertzthe intended hertz (frequency) that the thread's execute should be ran. Hertz is in operations per second. 0.0 means infinite hertz rate. -1 means a one shot thread.
nameunique thread name for the thread. If possible, try to use one word or words separated by underscores (_)
threaduser-created thread implementation
pausedcreate thread in a paused state.
Exceptions
exceptions::ThreadExceptionbad name (null)

Definition at line 140 of file Threader.cpp.

void madara::threads::Threader::run ( const std::string  name,
jobject  thread,
bool  paused = false 
)

Starts a new thread and executes the provided user thread once.

Execution ordering is init -> execute -> cleanup.


 
The thread will be managed by the threader. Please do not pass the address of a thread on the stack and do not delete this memory yourself or your program will crash.

Parameters
nameunique thread name for the thread. If possible, try to use one word or words separated by underscores (_)
threaduser-created thread implementation
pausedcreate thread in a paused state.

Definition at line 107 of file Threader.cpp.

void madara::threads::Threader::run ( double  hertz,
const std::string  name,
jobject  thread,
bool  paused = false 
)

Starts a new thread and executes the provided user thread once.

Execution ordering is init -> *execute -> cleanup. init and cleanup are only called once.


 
The thread will be managed by the threader. Please do not pass the address of a thread on the stack and do not delete this memory yourself or your program will crash.

Parameters
hertzthe intended hertz (frequency) that the thread's execute should be ran. Hertz is in operations per second. 0.0 means infinite hertz rate. -1 means a one shot thread.
nameunique thread name for the thread. If possible, try to use one word or words separated by underscores (_)
threaduser-created thread implementation
pausedcreate thread in a paused state.

Definition at line 123 of file Threader.cpp.

void madara::threads::Threader::set_data_plane ( knowledge::KnowledgeBase  data_plane)

Sets the data plane for new threads.

Parameters
data_planeThe data plane for threads to use

Definition at line 173 of file Threader.cpp.

void madara::threads::Threader::terminate ( const std::string  name)

Requests a specific thread to terminate.

Parameters
nameunique thread name for the thread.

Definition at line 180 of file Threader.cpp.

void madara::threads::Threader::terminate ( void  )

Requests all threads to terminate.

Definition at line 191 of file Threader.cpp.

bool madara::threads::Threader::wait ( const std::string  name,
const knowledge::WaitSettings ws = knowledge::WaitSettings () 
)

Wait for a specific thread to complete.

Parameters
nameunique thread name for the thread
wswait settings for specifying period and timeout
Returns
true if thread was terminated, false if timeout

Definition at line 201 of file Threader.cpp.

bool madara::threads::Threader::wait ( const knowledge::WaitSettings ws = knowledge::WaitSettings ())

Wait for all threads to complete.

Parameters
wswait settings for specifying period and timeout
Returns
true if thread was terminated, false if timeout

Definition at line 226 of file Threader.cpp.

Member Data Documentation

knowledge::KnowledgeBase madara::threads::Threader::control_
private

The control plane used by threads for termination and pause information.

This has to be on the heap, because each thread gets its own stack!

Definition at line 234 of file Threader.h.

knowledge::KnowledgeBase madara::threads::Threader::data_
private

The data plane used by threads.

Definition at line 227 of file Threader.h.

NamedWorkerThreads madara::threads::Threader::threads_
private

the threads that are still active

Definition at line 239 of file Threader.h.


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