00001 #ifndef __LDK_THREADING_H__
00002 #define __LDK_THREADING_H__
00003
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00028
00033
00034
00035
00036 #include "LDK/Types.h"
00037 #include "LDK/Mutex.h"
00038
00039
00045 namespace LDK
00046 {
00050 typedef size_t ThreadID;
00052
00058 LDK_API ThreadID currentThreadID();
00059
00066 LDK_API void yield();
00067
00078 LDK_API void sleep(uint32 time);
00079
00080
00092 class LDK_API Thread
00093 {
00094 protected:
00095 typedef void* ThreadHandle;
00096 ThreadHandle mHandle;
00097 Mutex mMutex;
00098 volatile bool mRunning;
00099 #ifdef unix
00100 static void* runThread(void* self);
00101 #else
00102 static void runThread(void* self);
00103 #endif
00104
00106 inline Thread(const Thread& rhs) : mRunning() {}
00107
00109 inline void operator=(const Thread& rhs) {}
00110
00111 public:
00112
00114 Thread();
00115
00118 virtual ~Thread();
00119
00122 virtual void run() = 0;
00123
00126 inline bool isRunning() { return mRunning; }
00127
00130 void start();
00131
00135 void kill();
00136 };
00137
00138 }
00139
00141
00142 #endif //__LDK_THREADING_H__