Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef WIBBLE_SYS_THREAD_H
00022 #define WIBBLE_SYS_THREAD_H
00023
00024 #include <wibble/sys/macros.h>
00025 #include <wibble/exception.h>
00026 #include <unistd.h>
00027 #ifdef POSIX
00028 #include <pthread.h>
00029 #endif
00030
00031 #ifdef _WIN32
00032 #include <windows.h>
00033 #include <process.h>
00034 #endif
00035 #include <signal.h>
00036
00037 namespace wibble {
00038 namespace sys {
00039
00040 static inline void sleep( int secs ) {
00041 #ifdef _WIN32
00042 Sleep( secs * 1000 );
00043 #else
00044 ::sleep( secs );
00045 #endif
00046 }
00047
00048 static inline void usleep( int usecs ) {
00049 #ifdef _WIN32
00050 Sleep( usecs / 1000 );
00051 #else
00052 ::usleep( usecs );
00053 #endif
00054 }
00055
00093 class Thread
00094 {
00095 protected:
00096 #ifdef POSIX
00097 pthread_t thread;
00098 #endif
00099
00100 #ifdef _WIN32
00101 unsigned int thread;
00102 HANDLE hThread;
00103 #endif
00104
00109 virtual const char* threadTag() { return "generic"; }
00110
00115 virtual void* main() = 0;
00116
00118 #ifdef POSIX
00119 static void* Starter(void* parm);
00120 #endif
00121
00122 #ifdef _WIN32
00123 static unsigned __stdcall Starter(void* parm);
00124 #endif
00125
00126 void testcancel();
00127
00128 public:
00129 virtual ~Thread() {}
00130
00132 void start();
00133
00135 void startDetached();
00136
00138 void* join();
00139
00141 void detach();
00142
00144 void cancel();
00145
00147 void kill(int signal);
00148 };
00149
00150 }
00151 }
00152
00153
00154 #endif