fesa-core  4.2.0
fesa::Thread Class Referenceabstract

This class is a wrapper in order to manage threads according to the object oriented style. More...

#include <Thread.h>

Inheritance diagram for fesa::Thread:
fesa::AbstractEventSource fesa::BufferSynchronizer fesa::MultiThreadedEventSourceProducer fesa::NotificationConsumer fesa::NotificationThread fesa::PeriodicalPersistencyTrigger fesa::PersistencyManager fesa::RTScheduler fesa::SettingsPersistencyTrigger

Public Member Functions

 Thread ()
 Constructor. More...
 
virtual ~Thread ()
 Destructor.
 
void setDetachState (int32_t state)
 Modify the detach state of the thread. More...
 
void start (bool blockingMode, const std::string &threadName, bool permanent=true)
 
virtual void stop ()
 Stop the thread.
 
int join (void **status)
 
bool isRunning () const
 Check if the thread is running. More...
 
pthread_t getID () const
 Get the process ID. More...
 
int32_t getPriority () const
 Get the priority of the thread. More...
 
cpu_set_t getAffinity () const
 Get the affinity of the thread.
 
void setPriority (int32_t priority)
 Set the priority of the thread. More...
 
void setAffinity (cpu_set_t affinity)
 Set the affinity of the thread. More...
 

Static Public Member Functions

static void AdjustProcessScheduling ()
 The process priority can only be adjusted in the main thread. It needs to be adjusted to the maximal thread priority since it sets the limit of the thread priorities of this process. More...
 
static std::string getThreadName (pthread_t threadId)
 Get the name of the thread by its id. More...
 
static std::string getCurrentThreadName ()
 
static void registerThreadIdName (pthread_t threadId, const std::string &threadName)
 Associate a thread id with a name. More...
 
static void registerThreadId (pthread_t threadId, Thread *thread)
 Associate a thread id with a name. More...
 
static Threadcurrent ()
 Returns the Thread object associated with the current thread.
 
static ThreadgetById (pthread_t id)
 Returns the Thread object associated with the given id. Throws FesaException if the id is unknown. More...
 
static const std::set< const
Thread * > 
getThreads ()
 

Protected Member Functions

virtual void run ()=0
 this method has to be overridden to provide the logic for the thread. It has to contain the code that will be executed in the thread
 

Protected Attributes

bool isRunning_
 true if the thread is running
 
bool hasFinished_
 true if the thread has finished.
 
bool joinHasFinished_
 true if another thread has joined this thread.
 
bool permanent_
 
pthread_t tid_
 Id of this thread.
 

Detailed Description

This class is a wrapper in order to manage threads according to the object oriented style.

Constructor & Destructor Documentation

fesa::Thread::Thread ( )

Constructor.

Exceptions
FesaException

Member Function Documentation

void fesa::Thread::AdjustProcessScheduling ( )
static

The process priority can only be adjusted in the main thread. It needs to be adjusted to the maximal thread priority since it sets the limit of the thread priorities of this process.

Exceptions
FesaException
Thread * fesa::Thread::getById ( pthread_t  id)
static

Returns the Thread object associated with the given id. Throws FesaException if the id is unknown.

Parameters
idthe thread id (pthread_t form, not gettid() form).
std::string fesa::Thread::getCurrentThreadName ( )
static
Returns
the current thread's name.
pthread_t fesa::Thread::getID ( ) const
inline

Get the process ID.

Returns
the process ID
int32_t fesa::Thread::getPriority ( ) const
inline

Get the priority of the thread.

Returns
Current priority
std::string fesa::Thread::getThreadName ( pthread_t  threadId)
static

Get the name of the thread by its id.

Parameters
threadIdThe id of a thread
Returns
The name of the thread
const std::set< const Thread * > fesa::Thread::getThreads ( )
static
Returns
a set containing pointer to all the running threads that have been registered.
bool fesa::Thread::isRunning ( ) const
inline

Check if the thread is running.

Returns
true if the the thread is running
int fesa::Thread::join ( void **  status)

IMPORTANT: calling this on a thread which is not permanent causes undefined behaviour. Blocks until this thread finishes. If the thread has already finished, returns immediately. A thread can only be joined once.

Parameters
[out]status(optional, can be NULL) the return value of the thread.
Returns
0 on success, a standard error code otherwise.
void fesa::Thread::registerThreadId ( pthread_t  threadId,
Thread thread 
)
static

Associate a thread id with a name.

Parameters
threadIdThe id of the thread
threadNameThe name of the thread
void fesa::Thread::registerThreadIdName ( pthread_t  threadId,
const std::string &  threadName 
)
static

Associate a thread id with a name.

Parameters
threadIdThe id of the thread
threadNameThe name of the thread
void fesa::Thread::setAffinity ( cpu_set_t  affinity)

Set the affinity of the thread.

Parameters
affinityThe affinity of the thread
Exceptions
FesaException
void fesa::Thread::setDetachState ( int32_t  state)
inline

Modify the detach state of the thread.

Parameters
stateNew thread state. See pthread_attr_setdetachstate() for info on what values are possible
void fesa::Thread::setPriority ( int32_t  priority)

Set the priority of the thread.

Parameters
priorityPriority of the thread
Exceptions
FesaException
void fesa::Thread::start ( bool  blockingMode,
const std::string &  threadName,
bool  permanent = true 
)

Starts this thread and gives it a name. If blockingMode is true, the thread is started in blocking mode and this method returns once the thread has finished. Otherwise, this method returns immediately. If permanent is true, the thread is joinable and will be stopped automatically when the process stops. Otherwise: -It is the responsibility of the caller to ensure that the thread finishes shortly. -The thread can't be joined (it is created in detached state). -If the process is shut down while the thread is still running, it will be stopped without notice. -blockingMode is ignored and the current thread is not blocked.

Parameters
blockingModeIf true, create a new thread and block the calling thread until the new thread finishes. If false, create a new thread and return
threadNameThe name of the thread that is being started
permanent
Exceptions
FesaException

Member Data Documentation

bool fesa::Thread::permanent_
protected

True if thread is permanent, false otherwise. If true, thread is joinable. Otherwise, thread is detached.


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