MMSThread Class Reference

This class is the base class for all threads. More...

#include <mmsthread.h>

Inheritance diagram for MMSThread:

List of all members.


Public Member Functions

 MMSThread (string identity="MMSThread", int priority=0, bool autodetach=true)
 Constructor.
virtual ~MMSThread ()
 Destructor.
virtual void threadMain ()=0
 Virtual main method for the thread.
virtual bool start ()
 Create and start a new thread.
virtual bool isRunning ()
 Check if the thread is running.
void detach ()
 Mark the thread as detached.
bool cancel ()
 Cancel execution of a thread.
void join ()
 The caller of this method will wait of the termination of the thread.
void setStacksize (size_t stacksize=1000000)
 Set the size of the stack for the new thread.

Public Attributes

string identity
 identification string

Private Member Functions

void run ()
 the code of this method runs in the new thread and calls the virtual threadMain()

Static Private Member Functions

static void * runThread (void *thiz)
 static helper routine to call this->run()

Private Attributes

MMSMutex startlock
 helper mutex to perform a safe start
bool starting
 starting thread is in progress
bool running
 thread is running
bool detached
 if thread is detached, its resources are automatically released when it terminates
pthread_attr_t tattr
 thread attributes
sched_param param
 scheduling parameter
pthread_t id
 id of the thread, valid for the running state
int priority
 requested priority of the thread
bool autodetach
 should thread automatically detached?
size_t stacksize
 requested stack size

Detailed Description

This class is the base class for all threads.

This class includes the base functionality available for all threads within MMS/DISKO. This class cannot be constructed. Only classes which are derived from this class can be constructed.

Author:
Jens Schneider

Definition at line 47 of file mmsthread.h.


Constructor & Destructor Documentation

MMSThread::MMSThread ( string  identity = "MMSThread",
int  priority = 0,
bool  autodetach = true 
)

Constructor.

Parameters:
identity identification string
priority requested priority of the thread, default is 0
autodetach automatically detach the thread after starting, default is true

Definition at line 59 of file mmsthread.cpp.

MMSThread::~MMSThread (  )  [virtual]

Destructor.

Definition at line 79 of file mmsthread.cpp.


Member Function Documentation

void * MMSThread::runThread ( void *  thiz  )  [static, private]

static helper routine to call this->run()

Definition at line 83 of file mmsthread.cpp.

void MMSThread::run (  )  [private]

the code of this method runs in the new thread and calls the virtual threadMain()

Definition at line 89 of file mmsthread.cpp.

virtual void MMSThread::threadMain (  )  [pure virtual]

Virtual main method for the thread.

This virtual method is empty and have to be setup with code by a derived class. The MMSThread class is only the base class and cannot be constructed.

Implemented in MMSEventThread, MMSImportScheduler, MMSSwitcherThread, MMSFlashThread, MMSFBWindowManagerThread, MMSGIFLoader, MMSImageWidgetThread, MMSInputWidgetThread, MMSLabelWidgetThread, MMSWindowAction, MMSInputLISThread, MMSInputThread, MMSProcessMonitor, MMSPulser, MMSTCPServer, MMSTCPServerThread, MMSThreadServer, and MMSTimer.

bool MMSThread::start ( void   )  [virtual]

Create and start a new thread.

Returns:
true if thread is started
Note:
The method returns false, if the thread is already running or cannot be started.

If the method returns true, it is possible, that the new thread is already finished.

See also:
isRunning()

Reimplemented in MMSFlashThread, and MMSThreadServer.

Definition at line 115 of file mmsthread.cpp.

bool MMSThread::isRunning (  )  [virtual]

Check if the thread is running.

Returns:
true if running
Note:
This check is a combination between the "starting" and "running" states. This means that if the thread is currently starting this method also returns true.
See also:
start()

Reimplemented in MMSPulser.

Definition at line 160 of file mmsthread.cpp.

void MMSThread::detach (  ) 

Mark the thread as detached.

Note:
If a thread is detached, its resources are automatically released when it terminates.

Definition at line 167 of file mmsthread.cpp.

bool MMSThread::cancel (  ) 

Cancel execution of a thread.

Returns:
true if successfully canceled
Note:
The method returns false, if the thread is not running or cannot be canceled.

Definition at line 173 of file mmsthread.cpp.

void MMSThread::join (  ) 

The caller of this method will wait of the termination of the thread.

Note:
This works only, if the thread is NOT detached.
See also:
MMSThread(), detach()

Definition at line 202 of file mmsthread.cpp.

void MMSThread::setStacksize ( size_t  stacksize = 1000000  ) 

Set the size of the stack for the new thread.

The stack size determines the minimum size (in bytes) that will be allocated.

Parameters:
stacksize size of the stack in bytes
Note:
The default stack size is 1000000 bytes.

The stack size must be changed before the start() method will be called.

Definition at line 208 of file mmsthread.cpp.


Member Data Documentation

helper mutex to perform a safe start

Reimplemented in MMSPulser.

Definition at line 51 of file mmsthread.h.

bool MMSThread::starting [private]

starting thread is in progress

Definition at line 54 of file mmsthread.h.

bool MMSThread::running [private]

thread is running

Definition at line 57 of file mmsthread.h.

bool MMSThread::detached [private]

if thread is detached, its resources are automatically released when it terminates

Definition at line 60 of file mmsthread.h.

pthread_attr_t MMSThread::tattr [private]

thread attributes

Definition at line 64 of file mmsthread.h.

sched_param MMSThread::param [private]

scheduling parameter

Definition at line 67 of file mmsthread.h.

pthread_t MMSThread::id [private]

id of the thread, valid for the running state

Reimplemented in MMSWindowAction.

Definition at line 70 of file mmsthread.h.

int MMSThread::priority [private]

requested priority of the thread

Definition at line 74 of file mmsthread.h.

bool MMSThread::autodetach [private]

should thread automatically detached?

Definition at line 77 of file mmsthread.h.

size_t MMSThread::stacksize [private]

requested stack size

Definition at line 80 of file mmsthread.h.

identification string

Definition at line 91 of file mmsthread.h.


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