MDSTk Libraries  1.1.0
Medical Data Segmentation Toolkit
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes
mds::sys::CUserThread Class Reference

Thread encapsulation. More...

#include <mdsUserThread.h>

Inheritance diagram for mds::sys::CUserThread:
Inheritance graph
[legend]

List of all members.

Public Types

enum  { CLASS_OBJECT }
 Templates that require members of the CObject class can use this enum to check the existence. More...
enum  { HEAP_OBJECT = 0x70616568 }
 Signature used to recognize objects on the heap. More...
typedef inttRoutine )(CThread *pThread)
 User thread routine.
typedef tRoutinetRoutinePtr
 Pointer to a user thread routine.

Public Member Functions

 CUserThread (void *pData=NULL, bool bRun=true)
 Default constructor.
virtual int entry ()=0
 Entry point of the thread.
void * getData ()
 Returns pointer to the user data.
int getExitCode ()
 Returns exit code returned by an user thread routine.
int getReferencesCount () const
 Returns the number of references.
bool isActive ()
 Returns true if the thread is running.
bool isExitSignalled ()
 Returns true if the exit event is already signalled.
bool isOnHeap () const
 Returns true if the object is allocated on the heap.
bool join (unsigned uTimeout)
 Waits for the thread termination.
 MDS_SHAREDPTR (CUserThread)
 Smart pointer type.
 MDS_SHAREDPTR (CThread)
 Smart pointer type.
void resume ()
 Resumes the suspended thread.
void setData (void *pData)
 Sets pointer to the user data.
void setExitEvent ()
 Signals the exit event that controls the thread termination.
void setPriority (EThreadPriority ePriority)
 Sets the thread priority.
void suspend ()
 Suspends the thread.
void terminate (bool bWait=true, unsigned uTime=THREAD_EXIT_TIME)
 Terminates the thread.
virtual ~CUserThread ()
 Virtual destructor.

Static Public Member Functions

static void * operator new (std::size_t Size)
 Allocates a new object on the heap.

Protected Member Functions

void addReference () const
 Increase the reference counter.
bool delReference () const
 Decrease the reference counter.

Static Protected Member Functions

static int threadRoutine (mds::sys::CThread *pThread)
 Real thread routine.

Protected Attributes

bool m_bSuspended
 Thread suspended flag.
CCriticalSection m_CritSec
 Critical section for mutual access.
CEvent m_ExitEvent
 Event the thread should check periodically and exit when it's set.
int m_iExitCode
 Thread exit code.
int m_iHeapObject
 Flag initialized if the object is on the heap.
int m_iReferences
 The number of references to the object.
CEvent m_NotSuspendedEvent
 Event signalled if the thread is not paused.
void * m_pData
 Pointer to user data.
tRoutinePtr m_pRoutine
 Pointer to a user thread routine.
CEvent m_TerminatedEvent
 Event signalled when the thread has terminated.

Detailed Description

Thread encapsulation.

Internal thread routine calls a virtual method that may be overloaded.


Member Typedef Documentation

typedef int( mds::sys::CThread::tRoutine)(CThread *pThread) [inherited]

User thread routine.

  • Please, call the method isExitSignalled() periodically to check if the routine should be terminated, or use the MDS_THREAD_MAIN_LOOP macro to implement this behaviour.

Pointer to a user thread routine.


Member Enumeration Documentation

anonymous enum [inherited]

Templates that require members of the CObject class can use this enum to check the existence.

Enumerator:
CLASS_OBJECT 
anonymous enum [inherited]

Signature used to recognize objects on the heap.

Enumerator:
HEAP_OBJECT 

Constructor & Destructor Documentation

mds::sys::CUserThread::CUserThread ( void *  pData = NULL,
bool  bRun = true 
)

Default constructor.

Virtual destructor.


Member Function Documentation

void mds::base::CObject::addReference ( ) const [protected, inherited]

Increase the reference counter.

bool mds::base::CObject::delReference ( ) const [protected, inherited]

Decrease the reference counter.

  • Returns true if the decremented number of references is lower or equal to zero and object must be deleted.
virtual int mds::sys::CUserThread::entry ( ) [pure virtual]

Entry point of the thread.

This function is pure virtual and must be implemented by any derived class. The thread execution is going to start here.

  • Please, call the method isExitSignalled() periodically to check if the function should be terminated, or use the MDS_THREAD_MAIN_LOOP macro to implement this behaviour.
  • Returned value can be checked further.
void* mds::sys::CThread::getData ( ) [inherited]

Returns pointer to the user data.

Returns exit code returned by an user thread routine.

  • -1 if the thread is still running.

Returns the number of references.

bool mds::sys::CThread::isActive ( ) [inherited]

Returns true if the thread is running.

bool mds::sys::CThread::isExitSignalled ( ) [inherited]

Returns true if the exit event is already signalled.

bool mds::base::CObject::isOnHeap ( ) const [inherited]

Returns true if the object is allocated on the heap.

bool mds::sys::CThread::join ( unsigned  uTimeout) [inherited]

Waits for the thread termination.

Smart pointer type.

Smart pointer type.

static void* mds::base::CObject::operator new ( std::size_t  Size) [static, inherited]

Allocates a new object on the heap.

void mds::sys::CThread::resume ( ) [inherited]

Resumes the suspended thread.

void mds::sys::CThread::setData ( void *  pData) [inherited]

Sets pointer to the user data.

void mds::sys::CThread::setExitEvent ( ) [inherited]

Signals the exit event that controls the thread termination.

void mds::sys::CThread::setPriority ( EThreadPriority  ePriority) [inherited]

Sets the thread priority.

void mds::sys::CThread::suspend ( ) [inherited]

Suspends the thread.

void mds::sys::CThread::terminate ( bool  bWait = true,
unsigned  uTime = THREAD_EXIT_TIME 
) [inherited]

Terminates the thread.

int mds::sys::CUserThread::threadRoutine ( mds::sys::CThread pThread) [static, protected]

Real thread routine.


Member Data Documentation

bool mds::sys::CThread::m_bSuspended [protected, inherited]

Thread suspended flag.

Critical section for mutual access.

CEvent mds::sys::CThread::m_ExitEvent [protected, inherited]

Event the thread should check periodically and exit when it's set.

int mds::sys::CThread::m_iExitCode [protected, inherited]

Thread exit code.

int mds::base::CObject::m_iHeapObject [mutable, protected, inherited]

Flag initialized if the object is on the heap.

int mds::base::CObject::m_iReferences [mutable, protected, inherited]

The number of references to the object.

  • Zero if there is no reference.

Event signalled if the thread is not paused.

void* mds::sys::CThread::m_pData [protected, inherited]

Pointer to user data.

Pointer to a user thread routine.

Event signalled when the thread has terminated.


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