![]() |
Classes | |
class | protlib::ThreadParam |
class | protlib::ThreadError |
class | protlib::Thread |
class | protlib::ThreadStarter< T, TParam > |
Namespaces | |
namespace | protlib |
Defines | |
#define | install_cleanup(f, m) pthread_cleanup_push((void (*)(void *)) f, (void *) m) |
install cleanup handler | |
#define | install_cleanup_mutex(m) install_cleanup(pthread_mutex_unlock,m) |
install cleanup handler for mutex | |
#define | install_cleanup_mutex_lock(m) install_cleanup_mutex(m) pthread_mutex_lock(m) |
lock mutex and install cleanup handler | |
#define | install_cleanup_thread_lock(ttype, tp) install_cleanup(call_unlock<ttype>,tp) tp->lock() |
Lock thread and install cleanup handler. | |
#define | uninstall_cleanup(exec) pthread_cleanup_pop(exec) |
uninstall cleanup handler | |
Functions | |
template<class T > | |
void | protlib::call_unlock (void *pobj) |
unlock template | |
void | protlib::call_void_fun (void(*f)()) |
call void function | |
template<class T > | |
void * | protlib::thread_starter (void *thread_object) |
protlib::ThreadParam::ThreadParam (uint32 wait, const char *name, uint32 minc=1, uint32 maxc=(uint32)-1) | |
protlib::Thread::Thread (const ThreadParam &p, bool create_queue=true, bool exp_allow=true) | |
virtual | protlib::Thread::~Thread () |
void * | protlib::Thread::start_processing () |
void | protlib::Thread::stop_processing (bool do_lock=true) |
void | protlib::Thread::abort_processing (bool do_lock=true) |
bool | protlib::Thread::is_running (bool do_lock=true) |
int | protlib::Thread::wait_cond (int32 sec, int32 nsec=0) |
state_t | protlib::Thread::get_state (bool do_lock=true) |
static void | protlib::Thread::get_time_of_day (struct timespec &ts) |
get time of day as timespec | |
virtual const char * | protlib::ThreadError::getstr () const |
void | protlib::Thread::lock () |
void | protlib::Thread::unlock () |
void | protlib::Thread::signal_cond () |
void | protlib::Thread::broadcast_cond () |
void | protlib::Thread::wait_cond () |
int | protlib::Thread::wait_cond (const struct timespec &ts) |
void | protlib::Thread::inc_running_threads () |
void | protlib::Thread::dec_running_threads () |
uint32 | protlib::Thread::get_running_threads () const |
void | protlib::Thread::inc_started_threads () |
uint32 | protlib::Thread::get_started_threads () const |
protlib::ThreadStarter::ThreadStarter (uint32 count, const TParam ¶m) | |
protlib::ThreadStarter::~ThreadStarter () | |
void | protlib::ThreadStarter::start_processing () |
void | protlib::ThreadStarter::stop_processing () |
bool | protlib::ThreadStarter::sleepuntilstop () |
void | protlib::ThreadStarter::wait_until_stopped () |
void | protlib::ThreadStarter::abort_processing (bool kill=false) |
Variables | |
static uint32 | protlib::ThreadParam::default_sleep_time = 5 |
static const char *const | protlib::ThreadError::errstr [] |
#define install_cleanup | ( | f, | |||
m | ) | pthread_cleanup_push((void (*)(void *)) f, (void *) m) |
install cleanup handler
This macro installs a cleanup handler and does some type casting. Use uninstall_cleanup(execute) or an apropriate unlock routine to unlock the mutex and uninstall the handler.
f | pointer to a cleanup handler routine. This is casted to void (*routine)(void *) | |
m | cleanup handler argument, normally a pointer to the mutex. This is casted to void*. |
Definition at line 65 of file cleanuphandler.h.
#define install_cleanup_mutex | ( | m | ) | install_cleanup(pthread_mutex_unlock,m) |
install cleanup handler for mutex
Calls install_cleanup and uses pthread_mutex_unlock as cleanup handler.
m | pointer to the mutex. |
Definition at line 71 of file cleanuphandler.h.
#define install_cleanup_mutex_lock | ( | m | ) | install_cleanup_mutex(m) pthread_mutex_lock(m) |
lock mutex and install cleanup handler
m | mutex |
Definition at line 76 of file cleanuphandler.h.
#define install_cleanup_thread_lock | ( | ttype, | |||
tp | ) | install_cleanup(call_unlock<ttype>,tp) tp->lock() |
Lock thread and install cleanup handler.
ttype | class name of thread object | |
tp | pointer to thread object |
Definition at line 82 of file cleanuphandler.h.
#define uninstall_cleanup | ( | exec | ) | pthread_cleanup_pop(exec) |
uninstall cleanup handler
This uninstalls a cleanup handler and optionally executes it.
exec | 0 or 1 |
Definition at line 88 of file cleanuphandler.h.
void protlib::ThreadStarter< T, TParam >::abort_processing | ( | bool | kill = false |
) | [inline, inherited] |
Stop and kill the threads.
kill | kill the threads if they do not stop. |
Definition at line 492 of file threads.h.
References DLog, protlib::ThreadError::ERROR_NOT_STARTED, protlib::ThreadError::ERROR_STILL_RUNNING, ILog, protlib::ThreadStarter< T, TParam >::pthreads, protlib::ThreadStarter< T, TParam >::sleepuntilstop(), protlib::ThreadStarter< T, TParam >::thread_object, and protlib::ThreadStarter< T, TParam >::thread_param.
Referenced by ariba::transport::tcpip::stop(), and protlib::ThreadStarter< T, TParam >::~ThreadStarter().
void protlib::Thread::abort_processing | ( | bool | do_lock = true |
) | [inherited] |
This is called just before a running thread is killed.
do_lock | if true the thread mutex is used |
Definition at line 202 of file threads.cpp.
References protlib::Thread::lock(), protlib::Thread::signal_cond(), protlib::Thread::state, protlib::Thread::STATE_ABORT, protlib::Thread::STATE_RUN, protlib::Thread::STATE_STOP, and protlib::Thread::unlock().
void protlib::Thread::broadcast_cond | ( | ) | [inline, inherited] |
void protlib::call_unlock | ( | void * | pobj | ) | [inline] |
unlock template
This function calls the unlock method of an object.
pobj | pointer to the locked object. |
Definition at line 94 of file cleanuphandler.h.
void protlib::call_void_fun | ( | void(*)() | f | ) | [inline] |
call void function
This function calls a function of type void f(void).
Definition at line 102 of file cleanuphandler.h.
void protlib::Thread::dec_running_threads | ( | ) | [inline, private, inherited] |
Definition at line 247 of file threads.h.
References protlib::Thread::running_threads.
Referenced by protlib::Thread::start_processing().
uint32 protlib::Thread::get_running_threads | ( | ) | const [inline, private, inherited] |
Definition at line 252 of file threads.h.
References protlib::Thread::running_threads.
Referenced by protlib::Thread::is_running(), and protlib::Thread::~Thread().
uint32 protlib::Thread::get_started_threads | ( | ) | const [inline, private, inherited] |
Definition at line 260 of file threads.h.
References protlib::Thread::started_threads.
Referenced by protlib::Thread::start_processing().
Thread::state_t protlib::Thread::get_state | ( | bool | do_lock = true |
) | [inherited] |
Returns the thread's state.
do_lock | if true the thread mutex is used |
Definition at line 278 of file threads.cpp.
References protlib::Thread::lock(), protlib::Thread::state, and protlib::Thread::unlock().
Referenced by protlib::TPoverUDP::listener_thread(), protlib::TPoverUDP::main_loop(), protlib::TPoverTCP::main_loop(), protlib::TPoverTCP::master_listener_thread(), protlib::TimerModule::process_elapsed_timers(), and protlib::TimerModule::process_queue().
void protlib::Thread::get_time_of_day | ( | struct timespec & | ts | ) | [static, inherited] |
get time of day as timespec
Definition at line 291 of file threads.cpp.
Referenced by protlib::TPoverTCP::get_connection_to().
const char * protlib::ThreadError::getstr | ( | ) | const [virtual, inherited] |
Deprecated: Use what() instead.
Reimplemented from protlib::ProtLibException.
Definition at line 298 of file threads.cpp.
References protlib::ThreadError::err, and protlib::ThreadError::errstr.
Referenced by protlib::ThreadError::what().
void protlib::Thread::inc_running_threads | ( | ) | [inline, private, inherited] |
Definition at line 243 of file threads.h.
References protlib::Thread::running_threads.
Referenced by protlib::Thread::start_processing().
void protlib::Thread::inc_started_threads | ( | ) | [inline, private, inherited] |
Definition at line 256 of file threads.h.
References protlib::Thread::started_threads.
Referenced by protlib::Thread::start_processing().
bool protlib::Thread::is_running | ( | bool | do_lock = true |
) | [inherited] |
Checks whether there is still a running thread.
do_lock | if true the thread mutex is used |
Definition at line 221 of file threads.cpp.
References protlib::Thread::get_running_threads(), protlib::Thread::lock(), and protlib::Thread::unlock().
void protlib::Thread::lock | ( | ) | [inline, inherited] |
Definition at line 210 of file threads.h.
References ERRLog, protlib::Thread::mutex, protlib::ThreadParam::name, and protlib::Thread::tparam.
Referenced by protlib::Thread::abort_processing(), protlib::TPoverTCP::create_new_receiver_thread(), protlib::TPoverTCP::get_connection_to(), protlib::Thread::get_state(), protlib::Thread::is_running(), protlib::TPoverTCP::main_loop(), protlib::TPoverTCP::master_listener_thread(), protlib::TimerModule::process_queue(), protlib::TPoverTCP::send(), protlib::Thread::start_processing(), protlib::Thread::stop_processing(), protlib::TPoverTCP::terminate(), and protlib::TimerModule::timer_expired().
void protlib::Thread::signal_cond | ( | ) | [inline, inherited] |
Definition at line 221 of file threads.h.
References protlib::Thread::cond.
Referenced by protlib::Thread::abort_processing(), and protlib::Thread::stop_processing().
bool protlib::ThreadStarter< T, TParam >::sleepuntilstop | ( | ) | [inline, inherited] |
Wait for the thread to stop running (DEPRECATED).
Sleeps until all threads have stopped running but not longer than sleep_time seconds.
This method is deprecated because it suffers from a race condition: If none of the pthreads created in start_processing() has been run yet, then this method returns immediately. Use wait_until_stopped() instead.
Definition at line 453 of file threads.h.
References ariba::utility::Helper::sleep(), protlib::ThreadStarter< T, TParam >::thread_object, and protlib::ThreadStarter< T, TParam >::thread_param.
Referenced by protlib::ThreadStarter< T, TParam >::abort_processing(), and protlib::ThreadStarter< T, TParam >::~ThreadStarter().
void protlib::ThreadStarter< T, TParam >::start_processing | ( | ) | [inline, inherited] |
Start the threads.
Definition at line 341 of file threads.h.
References ERRLog, protlib::ThreadError::ERROR_INTERNAL, protlib::ThreadError::ERROR_THREAD_CREATION, ILog, protlib::ThreadStarter< T, TParam >::pthreads, protlib::ThreadStarter< T, TParam >::thread_object, and protlib::ThreadStarter< T, TParam >::thread_param.
Referenced by ariba::transport::tcpip::start().
void * protlib::Thread::start_processing | ( | ) | [inherited] |
Called for each thread when processing is started.
The thread must not be locked because this is done inside this method. Cancellation is enabled and set to synchronous mode. So you only need to install cleanup handlers when there is a cancellation point between calls to lock() and unlock().
Definition at line 120 of file threads.cpp.
References protlib::Thread::dec_running_threads(), ERRLog, protlib::Thread::get_started_threads(), protlib::ProtLibException::getstr(), protlib::Thread::inc_running_threads(), protlib::Thread::inc_started_threads(), protlib::Thread::lock(), protlib::Thread::main_loop(), protlib::ThreadParam::name, protlib::Thread::state, protlib::Thread::STATE_ABORT, protlib::Thread::STATE_INIT, protlib::Thread::STATE_RUN, protlib::Thread::STATE_STOP, protlib::Thread::tparam, and protlib::Thread::unlock().
void protlib::ThreadStarter< T, TParam >::stop_processing | ( | ) | [inline, inherited] |
Ask all threads to stop (politely).
Definition at line 394 of file threads.h.
References DLog, protlib::ThreadError::ERROR_NOT_STARTED, protlib::ThreadError::ERROR_STOPPING, ILog, protlib::ThreadStarter< T, TParam >::thread_object, and protlib::ThreadStarter< T, TParam >::thread_param.
Referenced by ariba::transport::tcpip::stop(), and protlib::ThreadStarter< T, TParam >::~ThreadStarter().
void protlib::Thread::stop_processing | ( | bool | do_lock = true |
) | [inherited] |
Called when the thread is asked to stop processing.
The thread object may do some cleanup or work on until it has completed a task.
do_lock | if true the thread mutex is used |
Definition at line 183 of file threads.cpp.
References protlib::Thread::lock(), protlib::Thread::signal_cond(), protlib::Thread::state, protlib::Thread::STATE_RUN, protlib::Thread::STATE_STOP, and protlib::Thread::unlock().
protlib::Thread::Thread | ( | const ThreadParam & | p, | |
bool | create_queue = true , |
|||
bool | exp_allow = true | |||
) | [inherited] |
Constructor.
p | thread parameters | |
create_queue | if true, create one internal queue | |
exp_allow | if true, allow reception of expedited messages on the queue |
Definition at line 75 of file threads.cpp.
References protlib::Thread::cond, protlib::Thread::mutex, PTHREAD_MUTEX_ERRORCHECK, PTHREAD_MUTEX_NORMAL, and pthread_mutexattr_settype.
void* protlib::thread_starter | ( | void * | thread_object | ) | [inline] |
protlib::ThreadParam::ThreadParam | ( | uint32 | wait, | |
const char * | n, | |||
uint32 | minc = 1 , |
|||
uint32 | maxc = (uint32)-1 | |||
) | [inherited] |
Initializes a ThreadParam object with a default wait time and a a thread (group) name string.
wait | wait time between stopping and aborting the thread inside ThreadStarter::abort_processing | |
n | name of the threads. | |
minc | minimal number of threads | |
maxc | maximal number of threads |
Definition at line 59 of file threads.cpp.
protlib::ThreadStarter< T, TParam >::ThreadStarter | ( | uint32 | count, | |
const TParam & | param | |||
) | [inline, inherited] |
Constructor.
count | the number of threads to start | |
param | thread parameters |
Definition at line 307 of file threads.h.
References protlib::ThreadStarter< T, TParam >::pthreads.
void protlib::Thread::unlock | ( | ) | [inline, inherited] |
Definition at line 216 of file threads.h.
References protlib::Thread::mutex.
Referenced by protlib::Thread::abort_processing(), protlib::TPoverTCP::create_new_receiver_thread(), protlib::TPoverTCP::get_connection_to(), protlib::Thread::get_state(), protlib::Thread::is_running(), protlib::TPoverTCP::main_loop(), protlib::TPoverTCP::master_listener_thread(), protlib::TimerModule::process_queue(), protlib::TPoverTCP::send(), protlib::Thread::start_processing(), protlib::Thread::stop_processing(), protlib::TPoverTCP::terminate(), and protlib::TimerModule::timer_expired().
int protlib::Thread::wait_cond | ( | const struct timespec & | ts | ) | [inline, inherited] |
ts | absolute time |
Definition at line 238 of file threads.h.
References protlib::Thread::cond, and protlib::Thread::mutex.
void protlib::Thread::wait_cond | ( | ) | [inline, inherited] |
Definition at line 229 of file threads.h.
References protlib::Thread::cond, and protlib::Thread::mutex.
Referenced by protlib::TPoverTCP::get_connection_to().
Wait for the condition.
sec | relative time (seconds) | |
nsec | relative time (nanoseconds) |
Definition at line 242 of file threads.cpp.
References protlib::Thread::cond, and protlib::Thread::mutex.
void protlib::ThreadStarter< T, TParam >::wait_until_stopped | ( | ) | [inline, inherited] |
Wait until all threads have stopped running.
Threads that haven't been running yet (state IDLE) are not considered as stopped!
Definition at line 470 of file threads.h.
References DLog, ariba::utility::Helper::sleep(), protlib::Thread::STATE_INIT, protlib::ThreadStarter< T, TParam >::thread_object, and protlib::ThreadStarter< T, TParam >::thread_param.
Referenced by ariba::transport::tcpip::stop().
protlib::Thread::~Thread | ( | ) | [virtual, inherited] |
Destructor.
Currently throws an exception if there are still running threads.
Definition at line 101 of file threads.cpp.
References protlib::Thread::cond, protlib::ThreadError::ERROR_STILL_RUNNING, protlib::Thread::fq, protlib::Thread::get_running_threads(), and protlib::Thread::mutex.
protlib::ThreadStarter< T, TParam >::~ThreadStarter | ( | ) | [inline, inherited] |
Destructor.
This cancels all running threads if there are still some.
Definition at line 327 of file threads.h.
References protlib::ThreadStarter< T, TParam >::abort_processing(), catch_all, protlib::ThreadStarter< T, TParam >::sleepuntilstop(), protlib::ThreadStarter< T, TParam >::stop_processing(), and protlib::ThreadStarter< T, TParam >::thread_object.
uint32 protlib::ThreadParam::default_sleep_time = 5 [static, inherited] |
const char *const protlib::ThreadError::errstr [static, protected, inherited] |
Initial value:
{ "Cannot create POSIX Threads.", "Thread is running.", "Thread is going to stop.", "Thread is aborting.", "Still running threads left.", "ThreadStarter is not initialized correctly." "Internal ThreadStarter or Thread error.", "Thread has not been started yet." }
Definition at line 122 of file threads.h.
Referenced by protlib::ThreadError::getstr().