This class is a wrapper in order to manage threads according to the object oriented style. More...
#include <Thread.h>
Public Member Functions | |
Thread () | |
Constructor. | |
virtual | ~Thread () |
Destructor. | |
void | setDetachState (int32_t state) |
Modify the detach state of the thread. | |
virtual void | start (bool blockingMode, const std::string &threadName) |
Create and run a thread. | |
virtual void | stop () |
Stop the thread. | |
int32_t | join (void **status) |
Wait for the thread to terminate. | |
bool | getIsRunning () const |
Check if the thread is running. | |
pthread_t | getID () const |
Get the process ID. | |
int32_t | getPriority () const |
Get the priority of the thread. | |
void | setPriority (int32_t priority) |
Set the priority of the thread. | |
Static Public Member Functions | |
static void | AdjustProcessPriority () |
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. | |
static std::string | getThreadName (pthread_t threadId) |
Get the name of the thread by its id. | |
static void | registerThreadIdName (pthread_t threadId, const std::string &threadName) |
Associate a thread id with a name. | |
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. | |
pthread_t | tid_ |
Id of this thread. | |
Static Private Member Functions | |
static void * | startThread (void *arg) |
The method which will be called on creation of the thread. Static, in order to fit the expected type. | |
Private Attributes | |
pthread_attr_t | attr_ |
Attributes of this thread. | |
int32_t | priority_ |
Priority of this thread. | |
std::string | name_ |
This class is a wrapper in order to manage threads according to the object oriented style.
Definition at line 32 of file Thread.h.
fesa::Thread::Thread | ( | ) |
Constructor.
FesaException |
Definition at line 110 of file Thread.cpp.
References attr_, FesaErrorInitializingThreadAttributes, fesa::NICE_SCHED_POLICY, and priority_.
fesa::Thread::~Thread | ( | ) | [virtual] |
Destructor.
Definition at line 123 of file Thread.cpp.
void fesa::Thread::AdjustProcessPriority | ( | ) | [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.
FesaException |
Definition at line 241 of file Thread.cpp.
References fesa::AbstractEquipment::getDeviceDataFileName(), fesa::AbstractEquipment::getInstance(), fesa::AbstractEquipment::getProcessConfiguration(), fesa::ProcessConfiguration::isDefined(), fesa::NICE_SCHED_POLICY, fesa::PropertyTag::NO_RT_SCHEDULING, and fesa::RT_SCHED_POLICY.
pthread_t fesa::Thread::getID | ( | ) | const [inline] |
Get the process ID.
Definition at line 177 of file Thread.h.
References tid_.
Referenced by fesa::AbstractEventSource::AbstractEventSource(), fesa::AbstractEventSource::getEvtSrcID(), fesa::RTScheduler::printState(), and fesa::AbstractEventSource::printState().
bool fesa::Thread::getIsRunning | ( | ) | const [inline] |
Check if the thread is running.
Definition at line 172 of file Thread.h.
References isRunning_.
int32_t fesa::Thread::getPriority | ( | ) | const [inline] |
Get the priority of the thread.
Definition at line 167 of file Thread.h.
References priority_.
Referenced by fesa::OnSubscriptionEventSource::createSubscriptionThread(), fesa::AbstractEventSource::getEvtSrcPriority(), fesa::NotificationThread::NotificationThread(), fesa::RTScheduler::printConfig(), and fesa::RTScheduler::printState().
std::string fesa::Thread::getThreadName | ( | pthread_t | threadId | ) | [static] |
Get the name of the thread by its id.
threadId | The id of a thread |
Definition at line 288 of file Thread.cpp.
int32_t fesa::Thread::join | ( | void ** | status | ) |
Wait for the thread to terminate.
[out] | status | Status |
Definition at line 223 of file Thread.cpp.
References tid_.
void fesa::Thread::registerThreadIdName | ( | pthread_t | threadId, | |
const std::string & | threadName | |||
) | [static] |
Associate a thread id with a name.
threadId | The id of the thread | |
threadName | The name of the thread |
Definition at line 304 of file Thread.cpp.
Referenced by fesa::AbstractEventSource::AbstractEventSource(), fesa::FesaDeviceServer::get(), fesa::FesaDeviceServer::set(), and startThread().
virtual void fesa::Thread::run | ( | ) | [protected, pure virtual] |
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
Implemented in fesa::PersistencyManager, fesa::FesaDeviceServer, fesa::NotificationThread, fesa::AbstractEventSource, fesa::OnSubscriptionEventSource::SubscriptionThread, fesa::RTScheduler, and fesa::NotificationConsumer.
Referenced by startThread().
void fesa::Thread::setDetachState | ( | int32_t | state | ) | [inline] |
Modify the detach state of the thread.
state | New thread state. See pthread_attr_setdetachstate() for info on what values are possible |
Definition at line 162 of file Thread.h.
References attr_.
Referenced by fesa::NotificationConsumer::NotificationConsumer(), and fesa::RTScheduler::RTScheduler().
void fesa::Thread::setPriority | ( | int32_t | priority | ) |
Set the priority of the thread.
priority | Priority of the thread |
FesaException |
Definition at line 230 of file Thread.cpp.
References FesaErrorSettingPrioDuringRuntime, isRunning_, and priority_.
Referenced by fesa::AbstractEventSource::AbstractEventSource(), fesa::OnSubscriptionEventSource::createSubscriptionThread(), fesa::NotificationConsumer::NotificationConsumer(), fesa::NotificationThread::NotificationThread(), fesa::RTScheduler::RTScheduler(), fesa::FesaDeviceServer::start(), and fesa::PersistencyManager::start().
void fesa::Thread::start | ( | bool | blockingMode, | |
const std::string & | threadName | |||
) | [virtual] |
Create and run a thread.
blockingMode | If true, create a new thread and block the calling thread until the new thread finishes. If false, create a new thread and return | |
threadName | The name of the thread that is being started |
FesaException |
Definition at line 129 of file Thread.cpp.
References attr_, FesaErrorCreatingThread, FesaErrorDestroyingThreadAttributes, FesaErrorSettingInheritScheduling, FesaErrorSettingSchedulingPolicy, FesaErrorSettingThreadAttributes, FesaErrorUndefinedPriority, hasFinished_, isRunning_, name_, priority_, startThread(), and tid_.
Referenced by fesa::OnSubscriptionEventSource::createSubscriptionThread(), fesa::NotificationThread::NotificationThread(), and fesa::AbstractServerController::start().
void * fesa::Thread::startThread | ( | void * | arg | ) | [static, private] |
The method which will be called on creation of the thread. Static, in order to fit the expected type.
Definition at line 89 of file Thread.cpp.
References FesaErrorSettingThreadAttributes, name_, priority_, registerThreadIdName(), run(), and tid_.
Referenced by start().
void fesa::Thread::stop | ( | ) | [virtual] |
Stop the thread.
Definition at line 206 of file Thread.cpp.
References hasFinished_, isRunning_, fesa::MAX_ATTEMPTS_STOP_THREAD, and tid_.
Referenced by fesa::RTScheduler::cancel(), and fesa::OnSubscriptionEventSource::deleteSubscriptionThread().
pthread_attr_t fesa::Thread::attr_ [private] |
Attributes of this thread.
Definition at line 151 of file Thread.h.
Referenced by setDetachState(), start(), and Thread().
bool fesa::Thread::hasFinished_ [protected] |
true if the thread has finished.
Definition at line 135 of file Thread.h.
Referenced by fesa::RTScheduler::cancel(), fesa::RTScheduler::run(), fesa::AbstractEventSource::run(), fesa::NotificationThread::run(), fesa::PersistencyManager::run(), start(), and stop().
bool fesa::Thread::isRunning_ [protected] |
true if the thread is running
Definition at line 130 of file Thread.h.
Referenced by fesa::RTScheduler::cancel(), getIsRunning(), fesa::NotificationConsumer::run(), fesa::RTScheduler::run(), fesa::AbstractEventSource::run(), fesa::NotificationThread::run(), fesa::PersistencyManager::run(), setPriority(), start(), and stop().
std::string fesa::Thread::name_ [private] |
Reimplemented in fesa::RTScheduler.
Definition at line 157 of file Thread.h.
Referenced by start(), and startThread().
int32_t fesa::Thread::priority_ [private] |
Priority of this thread.
Definition at line 156 of file Thread.h.
Referenced by getPriority(), setPriority(), start(), startThread(), and Thread().
pthread_t fesa::Thread::tid_ [protected] |