cumbia-tango 1.x
C++ multi threaded library based on cumbia and the Tango control system
|
Thread token generator for Tango sources. More...
#include <cutthreadtokengen.h>
Public Member Functions | |
CuTThreadTokenGen (int pool_siz, const std::string &tok_prefix="tthread_") | |
CuTThreadTokenGen::CuTThreadTokenGen constructor. More... | |
~CuTThreadTokenGen () | |
std::string | generate (const std::string &dev) |
This function implements the CuThreadTokenI::generate method and is invoked by Cumbia::threadToken function to provide a token (in the form of std::string) to be used to group threads together. More... | |
void | map (const std::string &device, int which) |
User defined associations between device names and thread number. More... | |
int | which_thread (const std::string &device) const |
CuTThreadTokenGen::which_thread returns which thread has been assigned to the given device. More... | |
int | which_from_token (const std::string &tok) const |
Removes the prefix from tok and returns the. More... | |
std::list< std::string > | devicesForToken (const std::string &token) const |
Returns the list of devices whose sources belong to the thread with the given token. More... | |
std::string | tok_prefix () const |
Returns the prefix used for the token name. More... | |
int | threadPoolSize () const |
CuTThreadTokenGen::threadPoolSize returns the upper limit on the number of threads created and managed by CuThreadService. More... | |
void | setThreadPoolSize (int siz) |
CuTThreadTokenGen::setThreadPoolSize change the thread pool size. More... | |
Thread token generator for Tango sources.
A thread token determines how threads are grouped in Cumbia. When Cumbia::registerActivity is called, the thread token will assign an activity to the thread with the given token. Activities with the same token are executed in the same thread.
Tokens for grouping Tango sources can be either generated automatically, with an imposed limit to the set, or through a user defined map. When the limit is reached, the first method starts reusing threads, ensuring at the same time that sources referring to the same devices belong to the same thread. The automatic mode is employed if no user map has been defined. The CuTThreadTokenGen::generate method provides more details.
Use setThreadPoolSize to fix a limit on the number of desired threads.
After instantiating and configuring CuTThreadTokenGen, call Cumbia::setThreadTokenGenerator from your application to use the token generator.
CuTThreadTokenGen::CuTThreadTokenGen | ( | int | pool_siz, |
const std::string & | tok_prefix = "tthread_" |
||
) |
CuTThreadTokenGen::CuTThreadTokenGen constructor.
Build a Tango thread token generator. A thread token determines how threads are grouped in Cumbia. When Cumbia::registerActivity is called, the thread token will assign an activity to the thread with the given token.
pool_siz | the desired upper limit on the thread count. |
tok_prefix | a string prefix to prepend to the thread number in the token returned by generate |
References tok_prefix().
CuTThreadTokenGen::~CuTThreadTokenGen | ( | ) |
std::list< std::string > CuTThreadTokenGen::devicesForToken | ( | const std::string & | token | ) | const |
Returns the list of devices whose sources belong to the thread with the given token.
token | the thread token |
References which_from_token().
std::string CuTThreadTokenGen::generate | ( | const std::string & | dev | ) |
This function implements the CuThreadTokenI::generate method and is invoked by Cumbia::threadToken function to provide a token (in the form of std::string) to be used to group threads together.
If the device value in the input argument is not in the user map (i.e. the user only partially defines the device/thread association), then the generation will be hybrid.
in |
void CuTThreadTokenGen::map | ( | const std::string & | device, |
int | which | ||
) |
User defined associations between device names and thread number.
device | the device name |
which | the thread, as integer, to associate to the given device |
void CuTThreadTokenGen::setThreadPoolSize | ( | int | siz | ) |
CuTThreadTokenGen::setThreadPoolSize change the thread pool size.
siz | the upper limit on the number of threads created and managed by CuThreadService |
int CuTThreadTokenGen::threadPoolSize | ( | ) | const |
CuTThreadTokenGen::threadPoolSize returns the upper limit on the number of threads created and managed by CuThreadService.
std::string CuTThreadTokenGen::tok_prefix | ( | ) | const |
Returns the prefix used for the token name.
Referenced by CuTThreadTokenGen().
int CuTThreadTokenGen::which_from_token | ( | const std::string & | tok | ) | const |
Removes the prefix from tok and returns the.
tok |
Referenced by devicesForToken().
int CuTThreadTokenGen::which_thread | ( | const std::string & | device | ) | const |
CuTThreadTokenGen::which_thread returns which thread has been assigned to the given device.
device | the name of the Tango device |
The user defined map is searched first, the automatically generated map afterwards. If the device has not been mapped, -1 is returned.