DABC (Data Acquisition Backbone Core)  2.9.9
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes
dabc::PosixThread Class Reference

class represents posix pthread functionality More...

#include <dabc/threads.h>

Inheritance diagram for dabc::PosixThread:
dabc::Thread dabc::SocketThread verbs::Thread

Public Types

typedef void *() StartRoutine(void *)
 

Public Member Functions

void Cancel ()
 Try to cancel thread execution. More...
 
bool GetAffinity (bool actual, char *buf, unsigned maxbuf)
 Provides thread affinity in form of "xxxooooo". More...
 
Thread_t Id () const
 
bool IsItself () const
 Returns true if called from thread context. More...
 
void Join ()
 Join thread - method waits until thread execution is completed. More...
 
void Kill (int sig=9)
 Kill thread with specified signal. More...
 
 PosixThread ()
 
bool SetAffinity (const char *aff)
 Sets affinity mask for the thread. More...
 
void SetPriority (int prio)
 Change thread priority. More...
 
void SetThreadName (const char *thrdname)
 Set thread name, which can be seen from htop. More...
 
void Start (Runnable *run)
 Start thread with provided runnable. More...
 
void Start (StartRoutine *func, void *args)
 Start thread with provided routine and call arguments. More...
 
virtual ~PosixThread ()
 

Static Public Member Functions

static bool GetDfltAffinity (char *buf, unsigned maxbuf)
 Returns default affinity mask in form "xxxooosss". More...
 
static Thread_t Self ()
 
static bool SetDfltAffinity (const char *aff=nullptr)
 Sets default affinity for next threads to be created and for main process. More...
 

Protected Member Functions

void UseCurrentAsSelf ()
 

Protected Attributes

cpu_set_t fCpuSet
 affinity property of the thread More...
 
pthread_t fThrd
 pthread handle More...
 

Static Protected Attributes

static cpu_set_t fDfltSet
 default affinity for new thread More...
 
static cpu_set_t fSpecialSet
 set of processors, which can be used for special threads More...
 

Detailed Description

class represents posix pthread functionality

Definition at line 340 of file threads.h.

Member Typedef Documentation

◆ StartRoutine

typedef void*() dabc::PosixThread::StartRoutine(void *)

Definition at line 351 of file threads.h.

Constructor & Destructor Documentation

◆ PosixThread()

dabc::PosixThread::PosixThread ( )

Definition at line 272 of file threads.cxx.

◆ ~PosixThread()

dabc::PosixThread::~PosixThread ( )
virtual

Definition at line 282 of file threads.cxx.

Member Function Documentation

◆ UseCurrentAsSelf()

void dabc::PosixThread::UseCurrentAsSelf ( )
inlineprotected

Definition at line 347 of file threads.h.

◆ SetAffinity()

bool dabc::PosixThread::SetAffinity ( const char *  aff)

Sets affinity mask for the thread.

Should be called before thread is started.

Parameters
[in]affcan be
  • unsigned value with processors mask
  • string like "xxxoooxxx" were x and o identified enabled and disabled processors, first element in string corresponds to first processor -string like "+M" where M is processor number in special processors set, before SetDfltAffinity("-N") should be called (M<N)

Definition at line 286 of file threads.cxx.

◆ GetAffinity()

bool dabc::PosixThread::GetAffinity ( bool  actual,
char *  buf,
unsigned  maxbuf 
)

Provides thread affinity in form of "xxxooooo".

See SetAffinity method for more information

Parameters
[in]actualif true, request will be done to the thread, otherwise configured value will be provided
[out]bufoutput buffer
[out]maxbufsize of output buffer
Returns
true if operation was executed without error.

Definition at line 451 of file threads.cxx.

◆ Start() [1/2]

void dabc::PosixThread::Start ( Runnable run)

Start thread with provided runnable.

Definition at line 358 of file threads.cxx.

◆ Start() [2/2]

void dabc::PosixThread::Start ( StartRoutine func,
void *  args 
)

Start thread with provided routine and call arguments.

Definition at line 382 of file threads.cxx.

◆ Join()

void dabc::PosixThread::Join ( )

Join thread - method waits until thread execution is completed.

Definition at line 389 of file threads.cxx.

◆ Kill()

void dabc::PosixThread::Kill ( int  sig = 9)

Kill thread with specified signal.

Definition at line 407 of file threads.cxx.

◆ Cancel()

void dabc::PosixThread::Cancel ( )

Try to cancel thread execution.

Definition at line 412 of file threads.cxx.

◆ SetPriority()

void dabc::PosixThread::SetPriority ( int  prio)

Change thread priority.

Definition at line 395 of file threads.cxx.

◆ SetThreadName()

void dabc::PosixThread::SetThreadName ( const char *  thrdname)

Set thread name, which can be seen from htop.

Definition at line 417 of file threads.cxx.

◆ Id()

Thread_t dabc::PosixThread::Id ( ) const
inline
Returns
handle of thread object.

Definition at line 398 of file threads.h.

◆ Self()

static Thread_t dabc::PosixThread::Self ( )
inlinestatic
Returns
handle of current thread.

Definition at line 401 of file threads.h.

◆ IsItself()

bool dabc::PosixThread::IsItself ( ) const
inline

Returns true if called from thread context.

Definition at line 404 of file threads.h.

◆ SetDfltAffinity()

bool dabc::PosixThread::SetDfltAffinity ( const char *  aff = nullptr)
static

Sets default affinity for next threads to be created and for main process.

Parameters
[in]affcould be:
  • unsigned value with processors mask
  • string like "xxxoooxxxss" with allowed symbols 'x', 'o' and 's'. 'x' - enabled, 'o' - disabled, 's' - special purpose first element in string corresponds to first processor
  • string like "-N" where N is processors number which should be reserved for special purposes, these processors could be later assigned with SetAffinity("+M") call (M<N)
Returns
true if successful

Definition at line 183 of file threads.cxx.

◆ GetDfltAffinity()

bool dabc::PosixThread::GetDfltAffinity ( char *  buf,
unsigned  maxbuf 
)
static

Returns default affinity mask in form "xxxooosss".

See SetDfltAffinity for more details

Definition at line 424 of file threads.cxx.

Field Documentation

◆ fThrd

pthread_t dabc::PosixThread::fThrd
protected

pthread handle

Definition at line 342 of file threads.h.

◆ fCpuSet

cpu_set_t dabc::PosixThread::fCpuSet
protected

affinity property of the thread

Definition at line 343 of file threads.h.

◆ fDfltSet

cpu_set_t dabc::PosixThread::fDfltSet
staticprotected

default affinity for new thread

Definition at line 344 of file threads.h.

◆ fSpecialSet

cpu_set_t dabc::PosixThread::fSpecialSet
staticprotected

set of processors, which can be used for special threads

Definition at line 345 of file threads.h.


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