BasicThread Class Reference
[Basic classes]

Basic functions to handle threads. More...

#include <basicthread.h>

Inheritance diagram for BasicThread:

Inheritance graph
[legend]
Collaboration diagram for BasicThread:

Collaboration graph
[legend]
List of all members.

Public Member Functions

DECLSPEC BasicThread (TiXmlElement *el, BasicObject *p)
DECLSPEC BasicThread (const char *name, BasicObject *p, const char *fndebug)
DECLSPEC BasicThread (const char *name, BasicObject *p, std::ostream *strm=&std::cout)
virtual const char * getClassName ()
DECLSPEC bool start (bool paused=false)
DECLSPEC void kill ()
DECLSPEC void restart (Uint32 wait=20)
bool running ()
DECLSPEC bool lock (Uint32 wait=0)
DECLSPEC bool unlock ()
DECLSPEC bool setPause (bool pause)
DECLSPEC void stop (Uint32 wait=20)
virtual unsigned int getTimePerCycle ()
virtual DECLSPEC unsigned int getAvgTimePerCycle ()
unsigned int numCycles ()

Protected Member Functions

virtual int onRun ()
virtual void onCycle ()

Protected Attributes

Uint32 ulThreadId
SDL_mutex * mutex

Detailed Description

Basic functions to handle threads.

Required header file:

 #include <basicthread.h> 

BasicThread is used to handle threads. Only use it in a derived class and inherit onRun() and / or onCycle().


Constructor & Destructor Documentation

BasicThread::BasicThread ( TiXmlElement el,
BasicObject p 
)

Constructor. Does not start the thread!

Parameters:
fndebug the filename of the log file to use for debugging can be NULL, if logs are not required

BasicThread::BasicThread ( const char *  name,
BasicObject p,
const char *  fndebug 
)

Constructor, used without XML-data.

Parameters:
fndebug the filename of the logfile to use or NULL if you do not want to log messages.

BasicThread::BasicThread ( const char *  name,
BasicObject p,
std::ostream *  strm = &std::cout 
)

Constructor, used without XML-data, for logging to a stream.

Parameters:
strm the stream where the logs are written to, standard output by default.


Member Function Documentation

virtual const char* BasicThread::getClassName (  )  [inline, virtual]

This function should be overriden in every sub-class of BasicObject!

Returns:
the name of the class.

Reimplemented from BasicObject.

Reimplemented in NetThread.

bool BasicThread::start ( bool  paused = false  ) 

Activates the thread, which then calls onRun()

Parameters:
paused if this is true then onCycle() will not be called until the thread resumes (
See also:
setPause)

void BasicThread::kill (  ) 

Stopps the thread immediately

Warning:
try not to use this, if you are not informed about the consequences, prefer stop(10), if unavoidible or, best finish the inherited onRun()

void BasicThread::restart ( Uint32  wait = 20  ) 

Stopps the thread, and starts it again, try to avoid this as kill()

bool BasicThread::running (  )  [inline]

Returns:
true, if the thread is active otherwise false

bool BasicThread::lock ( Uint32  wait = 0  ) 

lock is used for locking the mutex, this function is only valid while the thread is running (otherwise it returns false)

Parameters:
wait time to wait (in msecs) if locking is not possible immediatelly
Returns:
false, if locking was not successful or the thread is not running, true otherwise
Todo:
verify functionality

bool BasicThread::unlock (  ) 

unlock is used for unlocking the mutex, this function is only valid while the thread is running (otherwise it returns false)

Returns:
false, if unlocking was not successful or the thread is not running, true otherwise
Todo:
verify functionality

bool BasicThread::setPause ( bool  pause  ) 

Pauses or continues the thread, so that onCycle will no more or again be called

Parameters:
pause if true thread will be paused, if false it will be continued
Returns:
true, if the thread is paused, false if it is stopping or not running

void BasicThread::stop ( Uint32  wait = 20  ) 

Tries to finish the loop by setting the stopping-status to true, finally kills it, if still running.

Parameters:
wait time to wait (in msecs) until killing, if it's still running
Warning:
use it with care

virtual unsigned int BasicThread::getTimePerCycle (  )  [inline, virtual]

Returns:
the duration in msecs of the last cycle or INFINITE, if no time availible

unsigned int BasicThread::getAvgTimePerCycle (  )  [virtual]

Returns:
the average time of one cycle since last thread-start or INFINITE, if no values availible

unsigned int BasicThread::numCycles (  )  [inline]

Returns:
the number of cycles that were done, since last thread-start, and zero, if it has not been started yet

int BasicThread::onRun (  )  [protected, virtual]

inherit onRun to have a function, called once (done in the new thread), when the thread is started

Reimplemented in NetThread, and WebThread.

virtual void BasicThread::onCycle (  )  [inline, protected, virtual]

inherit onCycle to get a function, called once per loop-cycle after starting the thread when using onCycle, the cycle-functions return a usable result note that this only happens, if onRun is not inherited or if it is called by a inherited function

Reimplemented in NetThread.


Member Data Documentation

Uint32 BasicThread::ulThreadId [protected]

Returns:
the thread's identifyer

SDL_mutex* BasicThread::mutex [protected]

just a mutex (used by lock and unlock) for any use

See also:
lock, unlock


The documentation for this class was generated from the following files:
Generated on Wed May 9 17:36:12 2007 for netrinjo by  doxygen 1.5.1