cumbia-tango 1.x
C++ multi threaded library based on cumbia and the Tango control system
Public Member Functions | List of all members
CuTThreadTokenGen Class Reference

Thread token generator for Tango sources. More...

#include <cutthreadtokengen.h>

Inheritance diagram for CuTThreadTokenGen:
Inheritance graph
[legend]

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...
 

Detailed Description

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.

Recommended readings
  • CuThreadTokenGenI
  • Cumbia::setThreadTokenGenerator
  • Cumbia::threadToken

Constructor & Destructor Documentation

◆ CuTThreadTokenGen()

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.

Parameters
pool_sizthe desired upper limit on the thread count.
tok_prefixa string prefix to prepend to the thread number in the token returned by generate
See also
CuTThreadTokenGen::generate
Cumbia::setThreadTokenGenerator
Cumbia::threadToken
Cumbia::registerActivity

References tok_prefix().

◆ ~CuTThreadTokenGen()

CuTThreadTokenGen::~CuTThreadTokenGen ( )

Member Function Documentation

◆ devicesForToken()

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.

Parameters
tokenthe thread token
Returns
list of devices whose sources live in the same thread with the given token

References which_from_token().

◆ generate()

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.

User defined mapping
If a user defined map has been defined by calling CuTThreadTokenGen::map, it is used to group threads accordingly. In that case, the defined thread pool size is ignored.
Automatic token generation
If the user defined map is empty and the thread pool size is greater than zero, automatic device grouping into threads takes place, so that:
  • sources with the same device belong to the same thread
  • the total number of threads is at most threadPoolSize.
If the in parameter is null, then an empty string is returned.

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.

Parameters
in
Returns

◆ map()

void CuTThreadTokenGen::map ( const std::string &  device,
int  which 
)

User defined associations between device names and thread number.

Parameters
devicethe device name
whichthe thread, as integer, to associate to the given device
Note
If the user defined map is not empty, its elements only are used by the generate function. In that case, no automatic generation will take place and if a device is not in the user map the token will be left untouched.
See also
generate

◆ setThreadPoolSize()

void CuTThreadTokenGen::setThreadPoolSize ( int  siz)

CuTThreadTokenGen::setThreadPoolSize change the thread pool size.

Parameters
sizthe upper limit on the number of threads created and managed by CuThreadService
Note
Changes to the thread pool size after activities have been registered do not affect the threads already running. For example, their number will not be reduced and their grouping will not be changed.

◆ threadPoolSize()

int CuTThreadTokenGen::threadPoolSize ( ) const

CuTThreadTokenGen::threadPoolSize returns the upper limit on the number of threads created and managed by CuThreadService.

Returns
the thread pool size, initialised either in the constructor or with setThreadPoolSize

◆ tok_prefix()

std::string CuTThreadTokenGen::tok_prefix ( ) const

Returns the prefix used for the token name.

Returns
the string used as prefix to name the token

Referenced by CuTThreadTokenGen().

◆ which_from_token()

int CuTThreadTokenGen::which_from_token ( const std::string &  tok) const

Removes the prefix from tok and returns the.

Parameters
tok
Returns
the integer obtained from the given token after removing the prefix, or -1 if tok does not exactly match prefix + number

Referenced by devicesForToken().

◆ which_thread()

int CuTThreadTokenGen::which_thread ( const std::string &  device) const

CuTThreadTokenGen::which_thread returns which thread has been assigned to the given device.

Parameters
devicethe name of the Tango device
Returns
an integer representing which thread has been assigned to the given device

The user defined map is searched first, the automatically generated map afterwards. If the device has not been mapped, -1 is returned.


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