#include <basicthread.h>
Inheritance diagram for BasicThread:


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 |
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().
| BasicThread::BasicThread | ( | TiXmlElement * | el, | |
| BasicObject * | p | |||
| ) |
Constructor. Does not start the thread!
| 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.
| 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.
| strm | the stream where the logs are written to, standard output by default. |
| virtual const char* BasicThread::getClassName | ( | ) | [inline, virtual] |
This function should be overriden in every sub-class of BasicObject!
Reimplemented from BasicObject.
Reimplemented in NetThread.
| bool BasicThread::start | ( | bool | paused = false |
) |
| void BasicThread::kill | ( | ) |
Stopps the thread immediately
| void BasicThread::restart | ( | Uint32 | wait = 20 |
) |
Stopps the thread, and starts it again, try to avoid this as kill()
| bool BasicThread::running | ( | ) | [inline] |
| 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)
| wait | time to wait (in msecs) if locking is not possible immediatelly |
| bool BasicThread::unlock | ( | ) |
unlock is used for unlocking the mutex, this function is only valid while the thread is running (otherwise it returns false)
| bool BasicThread::setPause | ( | bool | pause | ) |
Pauses or continues the thread, so that onCycle will no more or again be called
| pause | if true thread will be paused, if false it will be continued |
| void BasicThread::stop | ( | Uint32 | wait = 20 |
) |
Tries to finish the loop by setting the stopping-status to true, finally kills it, if still running.
| wait | time to wait (in msecs) until killing, if it's still running |
| virtual unsigned int BasicThread::getTimePerCycle | ( | ) | [inline, virtual] |
| unsigned int BasicThread::getAvgTimePerCycle | ( | ) | [virtual] |
| unsigned int BasicThread::numCycles | ( | ) | [inline] |
| int BasicThread::onRun | ( | ) | [protected, virtual] |
| 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.
Uint32 BasicThread::ulThreadId [protected] |
SDL_mutex* BasicThread::mutex [protected] |
1.5.1