CARMA C++
sza::util::Thread Class Reference

Define a class to encapsulate thread handling. More...

#include <carma/szautil/Thread.h>

Public Member Functions

void broadcastDone ()
 Let other threads know we are done. More...
 
void broadcastReady ()
 Let other threads know we are ready. More...
 
void cancel ()
 Calls pthread_cancel() for this thread. More...
 
unsigned cancelOrder ()
 
bool isPingable ()
 Return true if a ping function has been installed. More...
 
bool isRunning ()
 Return true once this thread is running. More...
 
bool matchName (std::string compname)
 Return true if the passed argument matches the name of this thread. More...
 
std::string name ()
 
void ping (void *arg)
 Function by which the control thread can ping this thread. More...
 
void raise (int sigNo)
 Raise a signal to this thread. More...
 
void setRunState (bool state)
 Function by which we can safely alter the running state of this thread. More...
 
void start (void *arg)
 Function by which a caller can start up this thread. More...
 
unsigned startOrder ()
 
std::string strName ()
 Print the name of this thread. More...
 
 Thread (void *(*startFn)(void *arg), void(*cleanFn)(void *arg), void(*pingFn)(void *arg), std::string name)
 Constructor method. More...
 
 Thread (void *(*startFn)(void *arg), void(*cleanFn)(void *arg), void(*pingFn)(void *arg), std::string name, unsigned startOrder, unsigned cancelOrder)
 Same as above, but allows the user to explicitly control the order in which this thread is started and cancelled. More...
 
void waitUntilReady ()
 
 ~Thread ()
 Destructor method. More...
 

Static Public Member Functions

static void() unlockMutex (void *arg)
 A wrapper around pthread_mutex_unlock() suitable for passing to pthread_cleanup_push() More...
 

Public Attributes

bool wasError_
 A value to be returned if an error occurs on startup. More...
 

Detailed Description

Define a class to encapsulate thread handling.

Definition at line 57 of file Thread.h.

Constructor & Destructor Documentation

sza::util::Thread::Thread ( void *(*)(void *arg)  startFn,
void(*)(void *arg)  cleanFn,
void(*)(void *arg)  pingFn,
std::string  name 
)

Constructor method.

Parameters
startFnA user-supplied startup function for this thread. Obviously, this cannot be NULL.
cleanFnA user-supplied startup function for this thread. Can be NULL, in which case the default cleanup handler is a no-op.
pingFnA user-supplied method of pinging this thread. Can be NULL, in which case isPingable() returns false and ping() is a no-op.
nameA name to associate with this thread.
sza::util::Thread::Thread ( void *(*)(void *arg)  startFn,
void(*)(void *arg)  cleanFn,
void(*)(void *arg)  pingFn,
std::string  name,
unsigned  startOrder,
unsigned  cancelOrder 
)

Same as above, but allows the user to explicitly control the order in which this thread is started and cancelled.

sza::util::Thread::~Thread ( )

Destructor method.

Member Function Documentation

void sza::util::Thread::broadcastDone ( )

Let other threads know we are done.

Exceptions
Exception
void sza::util::Thread::broadcastReady ( )

Let other threads know we are ready.

Exceptions
Exception
void sza::util::Thread::cancel ( )

Calls pthread_cancel() for this thread.

Exceptions
Exception
bool sza::util::Thread::isPingable ( )

Return true if a ping function has been installed.

bool sza::util::Thread::isRunning ( )

Return true once this thread is running.

bool sza::util::Thread::matchName ( std::string  compname)

Return true if the passed argument matches the name of this thread.

void sza::util::Thread::ping ( void *  arg)

Function by which the control thread can ping this thread.

Exceptions
Exception
void sza::util::Thread::raise ( int  sigNo)

Raise a signal to this thread.

void sza::util::Thread::setRunState ( bool  state)

Function by which we can safely alter the running state of this thread.

Exceptions
Exception
void sza::util::Thread::start ( void *  arg)

Function by which a caller can start up this thread.

***NB: this method blocks until the startup function (passed as void* arg) calls broadcastReady() below, to allow synchronization. You MUST make sure your thread startup function calls broadcastReady() or the thread calling run() will never unblock.

Exceptions
Exception
std::string sza::util::Thread::strName ( )

Print the name of this thread.

static void() sza::util::Thread::unlockMutex ( void *  arg)
static

A wrapper around pthread_mutex_unlock() suitable for passing to pthread_cleanup_push()

Member Data Documentation

bool sza::util::Thread::wasError_

A value to be returned if an error occurs on startup.

Definition at line 178 of file Thread.h.


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