GNU CommonC++
Public Member Functions | Static Public Member Functions | Protected Member Functions | Friends | List of all members
ost::PosixThread Class Reference

#include <thread.h>

Inheritance diagram for ost::PosixThread:
ost::Thread

Public Member Functions

 PosixThread (int pri=0, size_t stack=0)
 
void signalThread (int signo)
 Delivers a Posix signal to the current thread. More...
 
- Public Member Functions inherited from ost::Thread
 Thread (bool isMain)
 This is actually a special constructor that is used to create a thread "object" for the current execution context when that context is not created via an instance of a derived Thread object itself. More...
 
 Thread (int pri=0, size_t stack=0)
 When a thread object is contructed, a new thread of execution context is created. More...
 
 Thread (const Thread &th)
 A thread of execution can also be specified by cloning an existing thread. More...
 
virtual ~Thread ()
 The thread destructor should clear up any resources that have been allocated by the thread. More...
 
int start (Semaphore *start=0)
 When a new thread is created, it does not begin immediate execution. More...
 
int detach (Semaphore *start=0)
 Start a new thread as "detached". More...
 
ThreadgetParent (void)
 Gets the pointer to the Thread class which created the current thread object. More...
 
void suspend (void)
 Suspends execution of the selected thread. More...
 
void resume (void)
 Resumes execution of the selected thread. More...
 
Cancel getCancel (void)
 Used to retrieve the cancellation mode in effect for the selected thread. More...
 
bool isRunning (void) const
 Verifies if the thread is still running or has already been terminated but not yet deleted. More...
 
bool isDetached (void) const
 Check if this thread is detached. More...
 
void join (void)
 Blocking call which unlocks when thread terminates. More...
 
bool isThread (void) const
 Tests to see if the current execution context is the same as the specified thread object. More...
 
cctid_t getId (void) const
 Get system thread numeric identifier. More...
 
const char * getName (void) const
 Get the name string for this thread, to use in debug messages. More...
 

Static Public Member Functions

static void sigInstall (int signo)
 Install a signal handler for use by threads and the OnSignal() event notification handler. More...
 
- Static Public Member Functions inherited from ost::Thread
static Threadget (void)
 
static void setStack (size_t size=0)
 Set base stack limit before manual stack sizes have effect. More...
 
static void sleep (timeout_t msec)
 A thread-safe sleep call. More...
 
static void yield (void)
 Yields the current thread's CPU time slice to allow another thread to begin immediate execution. More...
 
static Throw getException (void)
 Get exception mode of the current thread. More...
 
static void setException (Throw mode)
 Set exception mode of the current thread. More...
 
static Cancel enterCancel (void)
 This is used to help build wrapper functions in libraries around system calls that should behave as cancellation points but don't. More...
 
static void exitCancel (Cancel cancel)
 This is used to restore a cancel block. More...
 

Protected Member Functions

void signalParent (signo_t signo)
 In the Posix version of Common C++, this can be used to send a signal into the parent thread of the current object. More...
 
void signalMain (signo_t signo)
 In the Posix version of Common C++, this can be used to send a signal into the main application thread. More...
 
virtual void onTimer (void)
 A derivable method to call when a SIGALRM is being delivered to a specific thread. More...
 
virtual void onHangup (void)
 A derived method to handle hangup events being delivered to a specific thread. More...
 
virtual void onException (void)
 A derived method to call when a SIGABRT is being delivered to a specific thread. More...
 
virtual void onDisconnect (void)
 A derived method to call when a SIGPIPE is being delivered to a specific thread. More...
 
virtual void onPolling (void)
 A derived method to handle asynchronous I/O requests delivered to the specified thread. More...
 
virtual void onSignal (int)
 A derivable method to call for delivering a signal event to a specified thread. More...
 
void setTimer (timeout_t timer, bool periodic=false)
 Used to specify a timeout event that can be delivered to the current thread via SIGALRM. More...
 
timeout_t getTimer (void) const
 Gets the time remaining for the current threads timer before it expires. More...
 
void endTimer (void)
 Terminates the timer before the timeout period has expired. More...
 
void setSignal (int signo, bool active)
 Used to enable or disable a signal within the current thread. More...
 
pthread_attr_t * getPthreadAttrPtr (void)
 Access to pthread_attr structure this allows setting/modifying pthread attributes not covered in the platform independant Thread constructor, e.g. More...
 
pthread_t getPthreadId (void)
 Get pthread_t of underlying posix thread (useful for debugging/logging) More...
 
- Protected Member Functions inherited from ost::Thread
void setName (const char *text)
 Set the name of the current thread. More...
 
virtual void run (void)=0
 All threads execute by deriving the Run method of Thread. More...
 
virtual void final (void)
 A thread that is self terminating, either by invoking exit() or leaving it's run(), will have this method called. More...
 
virtual void initial (void)
 The initial method is called by a newly created thread when it starts execution. More...
 
virtual void * getExtended (void)
 Since getParent() and getThread() only refer to an object of the Thread "base" type, this virtual method can be replaced in a derived class with something that returns data specific to the derived class that can still be accessed through the pointer returned by getParent() and getThread(). More...
 
virtual void notify (Thread *)
 When a thread terminates, it now sends a notification message to the parent thread which created it. More...
 
void exit (void)
 Used to properly exit from a Thread derived run() or initial() method. More...
 
void sync (void)
 Used to wait for a join or cancel, in place of explicit exit. More...
 
bool testCancel (void)
 test a cancellation point for deferred thread cancellation. More...
 
void setCancel (Cancel mode)
 Sets thread cancellation mode. More...
 
void setSuspend (Suspend mode)
 Sets the thread's ability to be suspended from execution. More...
 
void terminate (void)
 Used by another thread to terminate the current thread. More...
 
void clrParent (void)
 clear parent thread relationship. More...
 

Friends

class ThreadImpl
 
class Thread
 

Additional Inherited Members

- Public Types inherited from ost::Thread
enum  Throw { throwNothing, throwObject, throwException }
 How to raise error. More...
 
enum  Cancel {
  cancelInitial =0, cancelDeferred =1, cancelImmediate, cancelDisabled,
  cancelManual, cancelDefault =cancelDeferred
}
 How work cancellation. More...
 
enum  Suspend { suspendEnable, suspendDisable }
 How work suspend. More...
 
typedef enum ost::Thread::Throw Throw
 How to raise error. More...
 
typedef enum ost::Thread::Cancel Cancel
 How work cancellation. More...
 
typedef enum ost::Thread::Suspend Suspend
 How work suspend. More...
 

Constructor & Destructor Documentation

◆ PosixThread()

ost::PosixThread::PosixThread ( int  pri = 0,
size_t  stack = 0 
)

Member Function Documentation

◆ endTimer()

void ost::PosixThread::endTimer ( void  )
protected

Terminates the timer before the timeout period has expired.

This prevents the timer from sending it's SIGALRM and makes the timer available to other threads.

◆ getPthreadAttrPtr()

pthread_attr_t* ost::PosixThread::getPthreadAttrPtr ( void  )
protected

Access to pthread_attr structure this allows setting/modifying pthread attributes not covered in the platform independant Thread constructor, e.g.

contention scope or scheduling policy

◆ getPthreadId()

pthread_t ost::PosixThread::getPthreadId ( void  )
protected

Get pthread_t of underlying posix thread (useful for debugging/logging)

◆ getTimer()

timeout_t ost::PosixThread::getTimer ( void  ) const
protected

Gets the time remaining for the current threads timer before it expires.

Returns
time remaining before timer expires in milliseconds.

◆ onDisconnect()

virtual void ost::PosixThread::onDisconnect ( void  )
protectedvirtual

A derived method to call when a SIGPIPE is being delivered to a specific thread.

◆ onException()

virtual void ost::PosixThread::onException ( void  )
protectedvirtual

A derived method to call when a SIGABRT is being delivered to a specific thread.

◆ onHangup()

virtual void ost::PosixThread::onHangup ( void  )
protectedvirtual

A derived method to handle hangup events being delivered to a specific thread.

◆ onPolling()

virtual void ost::PosixThread::onPolling ( void  )
protectedvirtual

A derived method to handle asynchronous I/O requests delivered to the specified thread.

◆ onSignal()

virtual void ost::PosixThread::onSignal ( int  )
protectedvirtual

A derivable method to call for delivering a signal event to a specified thread.

Parameters
-posix signal id.

◆ onTimer()

virtual void ost::PosixThread::onTimer ( void  )
protectedvirtual

A derivable method to call when a SIGALRM is being delivered to a specific thread.

◆ setSignal()

void ost::PosixThread::setSignal ( int  signo,
bool  active 
)
protected

Used to enable or disable a signal within the current thread.

Parameters
signoposix signal id.
activeset to true to enable.

◆ setTimer()

void ost::PosixThread::setTimer ( timeout_t  timer,
bool  periodic = false 
)
protected

Used to specify a timeout event that can be delivered to the current thread via SIGALRM.

When the timer expires, the onTimer() method is called for the thread. At present, only one thread timer can be active at any given time. On some operating systems (including Linux) a timer can be active on each thread.

Parameters
timertimeout in milliseconds.
periodicshould the timer be periodic.
Note
currently, periodic timers are only available on systems with a working setitimer call.

◆ sigInstall()

static void ost::PosixThread::sigInstall ( int  signo)
static

Install a signal handler for use by threads and the OnSignal() event notification handler.

Parameters
signoposix signal id.

◆ signalMain()

void ost::PosixThread::signalMain ( signo_t  signo)
inlineprotected

In the Posix version of Common C++, this can be used to send a signal into the main application thread.

Parameters
signoa posix signal id.

◆ signalParent()

void ost::PosixThread::signalParent ( signo_t  signo)
inlineprotected

In the Posix version of Common C++, this can be used to send a signal into the parent thread of the current object.

Parameters
signoa posix signal id.

◆ signalThread()

void ost::PosixThread::signalThread ( int  signo)
inline

Delivers a Posix signal to the current thread.

Parameters
signoa posix signal id.

Friends And Related Function Documentation

◆ Thread

friend class Thread
friend

◆ ThreadImpl

friend class ThreadImpl
friend

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