EpcTools
An event based multi-threaded C++ development framework.
Public Types | Public Member Functions | Static Public Member Functions | Static Protected Member Functions | Friends | List of all members
EThreadBasic Class Referenceabstract

An abstract class that represents contains the threadProc() that will be run in a separate thread. More...

#include <etbasic.h>

Inheritance diagram for EThreadBasic:
EThreadEvent< TQueue, TMessage > ESocket::Thread< TQueue, TMessage >

Public Types

enum  RunState { rsWaitingToRun, rsRunning, rsDoneRunning }
 EThreadBasic run states. More...
 

Public Member Functions

 EThreadBasic ()
 Class constructor. More...
 
virtual ~EThreadBasic ()
 Class destructor. More...
 
virtual Dword threadProc (pVoid arg)=0
 Function that will be called in a separate thread. More...
 
Void init (pVoid arg, size_t stackSize=0)
 Initialize and start the thread. More...
 
Void join ()
 Waits for the thread to terminate. More...
 
Bool isInitialized ()
 Returns the thread initialization state. More...
 
RunState getRunState ()
 Returns the current thread run state. More...
 
Bool isWaitingToRun ()
 Determines if the thread is waiting to run. More...
 
Bool isRunning ()
 Determines if the thread is running. More...
 
Bool isDoneRunning ()
 Determines if the thread has finished running. More...
 
Int cancelWait ()
 Sends a cancellation request to the thread. More...
 
Void signal (Int sig)
 

Static Public Member Functions

static Void sleep (Int milliseconds)
 Sleeps for the specified number of milliseconds. More...
 
static Void yield ()
 Relinquishes the CPU. More...
 

Static Protected Member Functions

static Void Initialize ()
 performs internal initialization *** DO NOT CALL *** More...
 
static Void UnInitialize ()
 performs internal de-initialization *** DO NOT CALL *** More...
 

Friends

class EThreadBase
 
class EpcTools
 

Detailed Description

An abstract class that represents contains the threadProc() that will be run in a separate thread.

EThreadBasic is the base class that represents a single CPU thread. The function that will be called in the new thread is EThreadBasic::threadProc(). Additionally, EThreadBasic is one of the base classes used by the event thread base class EThreadBase.

Member Enumeration Documentation

◆ RunState

EThreadBasic run states.

Enumerator
rsWaitingToRun 

the thread is waiting to run

rsRunning 

the thread is running

rsDoneRunning 

the threadProc has exited and the thread is no longer running

Constructor & Destructor Documentation

◆ EThreadBasic()

EThreadBasic::EThreadBasic ( )

Class constructor.

◆ ~EThreadBasic()

EThreadBasic::~EThreadBasic ( )
virtual

Class destructor.

Member Function Documentation

◆ cancelWait()

Int EThreadBasic::cancelWait ( )

Sends a cancellation request to the thread.

Returns
0 if successful otherwise a nonzero error number.

Sends a cancellation request to the thread. Whether and when the target thread reacts to the cancellation request depends on two attributes that are under the control of that thread: its cancelability state and type. See pthread_cancel() for more information.

◆ getRunState()

RunState EThreadBasic::getRunState ( )
inline

Returns the current thread run state.

Returns
the current EThreadBasic::RunState

Returns the current EThreadBasic::RunState for this thread.

◆ init()

Void EThreadBasic::init ( pVoid  arg,
size_t  stackSize = 0 
)

Initialize and start the thread.

Parameters
argthe threadProc() argument
stackSizethe stack size for the new thread, 0 - default stack size
Exceptions
EThreadError_AlreadyInitializedthe thread has already been initialized
EThreadError_UnableToInitializeunable to initialize the thread

Initializes and starts the thread with the specified argument and stack size. A stackSize of 0 corresponds to the default stack size.

◆ Initialize()

Void EThreadBasic::Initialize ( )
staticprotected

performs internal initialization *** DO NOT CALL ***

◆ isDoneRunning()

Bool EThreadBasic::isDoneRunning ( )
inline

Determines if the thread has finished running.

Returns
indicates if the thread is finished running or not

Returns True if the thread is in the rsDoneRunning state and False if it is not.

◆ isInitialized()

Bool EThreadBasic::isInitialized ( )

Returns the thread initialization state.

Returns
the initialization status

Returns True if the thread has been initialized and False if not.

◆ isRunning()

Bool EThreadBasic::isRunning ( )
inline

Determines if the thread is running.

Returns
indicates if the thread is running or not

Returns True if the thread is in the rsRunning state and False if it is not.

◆ isWaitingToRun()

Bool EThreadBasic::isWaitingToRun ( )
inline

Determines if the thread is waiting to run.

Returns
indicates if the thread is waiting to run or not

Returns True if the thread is in the rsWaitingToRun state and False if it is not.

◆ join()

Void EThreadBasic::join ( )

Waits for the thread to terminate.

Exceptions
EThreadError_AlreadyInitializedalready initialized
EThreadError_UnableToInitializeunable to initailize

Suspends the execution of the calling thread until the thread associated with this object terminates.

◆ signal()

Void EThreadBasic::signal ( Int  sig)
inline

◆ sleep()

Void EThreadBasic::sleep ( Int  milliseconds)
static

Sleeps for the specified number of milliseconds.

Causes the calling thread to sleep for the specified number of milliseconds.

◆ threadProc()

virtual Dword EThreadBasic::threadProc ( pVoid  arg)
pure virtual

Function that will be called in a separate thread.

Parameters
argpassed by init() to the new thread's threadProc() function

This pure virtual function must be overridden in the derived class. The code in the derived class will be executed in a separate thread.

◆ UnInitialize()

Void EThreadBasic::UnInitialize ( )
staticprotected

performs internal de-initialization *** DO NOT CALL ***

◆ yield()

Void EThreadBasic::yield ( )
static

Relinquishes the CPU.

Causes the calling thread to relinquish the CPU. The thread is moved to the end of the queue for its static priority and another thread gets to run.

Friends And Related Function Documentation

◆ EpcTools

friend class EpcTools
friend

◆ EThreadBase

friend class EThreadBase
friend

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