My Project
 All Classes Files Functions Variables Enumerations Enumerator Friends Macros Pages
gcp::util::Thread Class Reference

#include <Thread.h>

Public Member Functions

void start (void *arg)
 
void cancel ()
 
void ping (void *arg)
 
void broadcastReady ()
 
void broadcastDone ()
 
void setRunState (bool state)
 
bool matchName (std::string compname)
 
std::string strName ()
 
 Thread (THREAD_START(*startFn), THREAD_CLEAN(*cleanFn), THREAD_PING(*pingFn), std::string name, unsigned startOrder=0, unsigned cancelOrder=0)
 
 Thread (THREAD_START(*startFn), THREAD_CLEAN(*cleanFn), THREAD_PING(*pingFn), std::string name, unsigned startOrder, unsigned cancelOrder, int priority, int schedPolicy=SCHED_RR)
 
 ~Thread ()
 
bool isRunning ()
 
bool isPingable ()
 
void raise (int sigNo)
 
unsigned startOrder ()
 
unsigned cancelOrder ()
 
void waitUntilReady ()
 
std::string name ()
 

Static Public Member Functions

static THREAD_CLEAN (unlockMutex)
 

Public Attributes

bool wasError_
 

Detailed Description

Define a class to encapsulate thread handling.

Constructor & Destructor Documentation

gcp::util::Thread::Thread ( THREAD_START *  startFn,
THREAD_CLEAN cleanFn,
THREAD_PING *  pingFn,
std::string  name,
unsigned  startOrder = 0,
unsigned  cancelOrder = 0 
)

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.
startOrderThe order in which to start this thread
stopOrderThe order in which to stop this thread
schedPolicyThe Scheduling policy for this thread
Thread::~Thread ( )

Destructor method

....................................................................... Thread destructor

Member Function Documentation

void Thread::broadcastDone ( )

Let other threads know we are done

Exceptions
Exception....................................................................... Broadcast to any waiting threads that we are done
void Thread::broadcastReady ( )

Let other threads know we are ready

Exceptions
Exception....................................................................... Broadcast to any waiting threads that we are ready
void Thread::cancel ( )

Calls pthread_cancel() for this thread

Exceptions
Exception....................................................................... Thread cancellation function. It is expected that the exiting thread will call a function established by pthread_cleanup_push() which will signal ready when it is done.
bool Thread::isPingable ( )

Return true if a ping function has been installed.

....................................................................... Return true if a ping function has been installed for this thread.

bool Thread::isRunning ( )

Return true once this thread is running.

....................................................................... Return true if this thread is running

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

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

....................................................................... Return true if the passed name matches

void Thread::ping ( void *  arg)

Function by which the control thread can ping this thread

Exceptions
Exception....................................................................... Thread ping function
void Thread::raise ( int  sigNo)

Raise a signal to this thread.

....................................................................... Raise a signal to this thread.

void Thread::setRunState ( bool  state)

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

Exceptions
Exception....................................................................... A public interface to setRunStatePrivate()
void 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....................................................................... Thread run function
string Thread::strName ( )

Print the name of this thread

....................................................................... Return the name string of this thread

static gcp::util::Thread::THREAD_CLEAN ( unlockMutex  )
static

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

Member Data Documentation

bool gcp::util::Thread::wasError_

A value to be returned if an error occurs on startup


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