MADARA
3.4.1
|
Starts threads with first class support of MADARA contexts. More...
#include <Threader.h>
Public Member Functions | |
Threader () | |
Default constructor. More... | |
Threader (const Threader &)=delete | |
Threader (knowledge::KnowledgeBase &data_plane) | |
Constructor. More... | |
Threader (Threader &&)=default | |
~Threader () | |
Destructor. More... | |
void | change_hertz (const std::string &name, double hertz) |
Modify hertz rate of a thread. More... | |
void | debug_to_kb (const std::string &prefix=".threader") |
Requests all debugging for threads go into the data plane KB instead of the control plane. More... | |
void | disable_debug (const std::string &name) |
Requests a specific thread to disable debug mode. More... | |
void | disable_debug (void) |
Requests that all new threads disable debug mode. More... | |
void | enable_debug (const std::string &name) |
Requests a specific thread to enter debug mode. More... | |
void | enable_debug (void) |
Requests that all new threads to enter debug mode. 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... | |
Threader & | operator= (const Threader &)=delete |
Threader & | operator= (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 (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, BaseThread *thread, bool paused=false) |
Starts a new thread and executes the provided user thread at a hertz. 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 knowledge::WaitSettings &ws=knowledge::WaitSettings()) |
Wait for all threads to complete. More... | |
bool | wait (const std::string &name, const knowledge::WaitSettings &ws=knowledge::WaitSettings()) |
Wait for a specific thread to complete. More... | |
bool | wait_for_paused (const knowledge::WaitSettings &ws=knowledge::WaitSettings()) |
Wait for all threads to reach paused state. More... | |
bool | wait_for_paused (const std::string &name, const knowledge::WaitSettings &ws=knowledge::WaitSettings()) |
Wait for a specific thread to reach paused state. 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... | |
bool | debug_ = false |
indicates if threads should be started in debug mode More... | |
std::string | debug_to_kb_prefix_ |
if not empty, user has specified debug information should go to the data plane at this prefix 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 11 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 13 of file Threader.cpp.
madara::threads::Threader::~Threader | ( | ) |
Destructor.
Definition at line 18 of file Threader.cpp.
|
delete |
|
default |
|
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 15 of file Threader.inl.
|
inline |
Requests all debugging for threads go into the data plane KB instead of the control plane.
This will impact performance of your main knowledge base, so you should use it sparingly, if possible.
prefix | prefix to save debug info into data plane KB |
Definition at line 31 of file Threader.inl.
|
inline |
Requests a specific thread to disable debug mode.
Debug mode prints thread performance information such as durations and executions.
name | unique thread name for the thread. |
Definition at line 26 of file Threader.inl.
|
inline |
Requests that all new threads disable debug mode.
Debug mode prints thread performance information such as durations and executions. Disabled is the default mode.
Definition at line 42 of file Threader.inl.
|
inline |
Requests a specific thread to enter debug mode.
Debug mode prints thread performance information such as durations and executions.
name | unique thread name for the thread. |
Definition at line 21 of file Threader.inl.
|
inline |
Requests that all new threads to enter debug mode.
Debug mode prints thread performance information such as durations and executions. Disabled is the default mode.
Definition at line 37 of file Threader.inl.
|
inline |
Gets the control plane used by threads.
Definition at line 54 of file Threader.inl.
|
inline |
Gets the data plane used by threads.
Definition at line 48 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 24 of file Threader.cpp.
void madara::threads::Threader::pause | ( | void | ) |
Requests all threads to pause.
Definition at line 34 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 43 of file Threader.cpp.
void madara::threads::Threader::resume | ( | void | ) |
Requests all threads to resume (unpause)
Definition at line 53 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. |
exceptions::ThreadException | bad name (null) |
Definition at line 62 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.
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 100 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. |
exceptions::ThreadException | bad name (null) |
Definition at line 132 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.
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 116 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 168 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 174 of file Threader.cpp.
void madara::threads::Threader::terminate | ( | void | ) |
Requests all threads to terminate.
Definition at line 184 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 218 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 194 of file Threader.cpp.
bool madara::threads::Threader::wait_for_paused | ( | const knowledge::WaitSettings & | ws = knowledge::WaitSettings() | ) |
Wait for all threads to reach paused state.
ws | wait settings for specifying period and timeout |
Definition at line 275 of file Threader.cpp.
bool madara::threads::Threader::wait_for_paused | ( | const std::string & | name, |
const knowledge::WaitSettings & | ws = knowledge::WaitSettings() |
||
) |
Wait for a specific thread to reach paused state.
name | unique thread name for the thread |
ws | wait settings for specifying period and timeout |
Definition at line 255 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 286 of file Threader.h.
|
private |
The data plane used by threads.
Definition at line 279 of file Threader.h.
|
private |
indicates if threads should be started in debug mode
Definition at line 296 of file Threader.h.
|
private |
if not empty, user has specified debug information should go to the data plane at this prefix
Definition at line 302 of file Threader.h.
|
private |
the threads that are still active
Definition at line 291 of file Threader.h.