MADARA
3.1.8
|
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 () | |
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... | |
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 | 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... | |
Starts threads with first class support of MADARA contexts.
Definition at line 35 of file Threader.h.
madara::threads::Threader::Threader | ( | ) |
Default constructor.
Definition at line 10 of file Threader.cpp.
madara::threads::Threader::Threader | ( | knowledge::KnowledgeBase & | data_plane | ) |
Constructor.
data_plane | The 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.
|
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.
name | unique thread name for the thread |
hertz | new hertz rate for the periodic thread |
Definition at line 17 of file Threader.inl.
|
inline |
Gets the control plane used by threads.
Definition at line 33 of file Threader.inl.
|
inline |
Gets the data plane used by threads.
Definition at line 23 of file Threader.inl.
void madara::threads::Threader::pause | ( | const std::string | name | ) |
Requests a specific thread to pause.
name | unique thread name for the thread. |
Definition at line 31 of file Threader.cpp.
void madara::threads::Threader::pause | ( | void | ) |
Requests all threads to pause.
Definition at line 42 of file Threader.cpp.
void madara::threads::Threader::resume | ( | const std::string | name | ) |
Requests a specific thread to resume (unpause)
name | unique thread name for the thread. |
Definition at line 52 of file Threader.cpp.
void madara::threads::Threader::resume | ( | void | ) |
Requests all threads to resume (unpause)
Definition at line 63 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.
name | unique thread name for the thread. If possible, try to use one word or words separated by underscores (_) |
thread | user-created thread implementation |
paused | create thread in a paused state. |
Definition at line 73 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.
hertz | the 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. |
name | unique thread name for the thread. If possible, try to use one word or words separated by underscores (_) |
thread | user-created thread implementation |
paused | create thread in a paused state. |
Definition at line 126 of file Threader.cpp.
void madara::threads::Threader::set_data_plane | ( | knowledge::KnowledgeBase & | data_plane | ) |
Sets the data plane for new threads.
data_plane | The data plane for threads to use |
Definition at line 143 of file Threader.cpp.
void madara::threads::Threader::terminate | ( | const std::string | name | ) |
Requests a specific thread to terminate.
name | unique thread name for the thread. |
Definition at line 150 of file Threader.cpp.
void madara::threads::Threader::terminate | ( | void | ) |
Requests all threads to terminate.
Definition at line 161 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.
name | unique thread name for the thread |
ws | wait settings for specifying period and timeout |
Definition at line 171 of file Threader.cpp.
bool madara::threads::Threader::wait | ( | const knowledge::WaitSettings & | ws = knowledge::WaitSettings () | ) |
Wait for all threads to complete.
ws | wait settings for specifying period and timeout |
Definition at line 198 of file Threader.cpp.
|
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 227 of file Threader.h.
|
private |
The data plane used by threads.
Definition at line 220 of file Threader.h.
|
private |
the threads that are still active
Definition at line 232 of file Threader.h.