00001 #ifndef THREAD_H 00002 #define THREAD_H 00003 #include <windows.h> 00004 00005 namespace wkgl { 00011 typedef void (*RUNNABLE)( void *param ); 00012 00013 #define SFLAG unsigned short 00014 00019 #define THREAD_STOPPED 0 00020 00024 #define THREAD_RUNNING 1 00025 00030 #define THREAD_SUSPENDED 2 00031 00051 class Thread 00052 { 00053 protected: 00054 RUNNABLE r; 00055 SFLAG state; 00056 DWORD thread_id; 00057 HANDLE thandle; 00058 char* name; 00059 void* param; 00060 00064 static HANDLE notify_event; 00065 00069 static UINT nwaiting; 00070 00073 Thread(); 00074 public: 00078 Thread( RUNNABLE r ); 00079 00083 Thread( RUNNABLE r, char *name ); 00084 00087 ~Thread(void); 00088 00092 virtual BOOL start(); 00093 00097 virtual BOOL start( void *param ); 00098 00102 virtual BOOL stop(); 00103 00107 virtual BOOL suspend(); 00108 00112 virtual BOOL resume(); 00113 00114 //virtual int getPriority(); 00115 //virtual void setPriority( int priority ); 00116 00120 virtual SFLAG getState(); 00121 00125 virtual char* getName(); 00126 00130 virtual BOOL waitForCompletion( DWORD mill ); 00131 00135 virtual BOOL waitForCompletion(); 00136 00140 static void sleep( ULONG mill ); 00141 00145 static Thread* getCurrentThread(); 00146 00150 static void wait( DWORD mill ); 00151 00155 static void wait(); 00156 00160 static void notify(); 00161 00165 static void notifyAll(); 00166 00170 static void yield(); 00171 00175 friend DWORD WINAPI ThreadProc( LPVOID lpParam ); 00176 }; 00177 } 00178 #endif
1.2.18