00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef FXTHREAD_H
00022 #define FXTHREAD_H
00023
00024 #ifndef FXRUNNABLE_H
00025 #include "FXRunnable.h"
00026 #endif
00027
00028 namespace FX {
00029
00030
00058 class FXAPI FXThread : public FXRunnable {
00059 private:
00060 volatile FXThreadID tid;
00061 volatile FXbool busy;
00062 private:
00063 static FXAutoThreadStorageKey selfKey;
00064 private:
00065 FXThread(const FXThread&);
00066 FXThread &operator=(const FXThread&);
00067 #if defined(WIN32)
00068 static unsigned int CALLBACK function(void*);
00069 #else
00070 static void* function(void*);
00071 #endif
00072 protected:
00073 static void self(FXThread* t);
00074 public:
00075
00077 enum Priority {
00078 PriorityError=-1,
00079 PriorityDefault,
00080 PriorityMinimum,
00081 PriorityLower,
00082 PriorityMedium,
00083 PriorityHigher,
00084 PriorityMaximum
00085 };
00086
00088 enum Policy {
00089 PolicyError=-1,
00090 PolicyDefault,
00091 PolicyFifo,
00092 PolicyRoundRobin
00093 };
00094
00095 public:
00096
00098 FXThread();
00099
00105 FXThreadID id() const;
00106
00110 FXbool running() const;
00111
00119 FXbool start(unsigned long stacksize=0);
00120
00125 FXbool join();
00126
00133 FXbool join(FXint& code);
00134
00143 FXbool cancel();
00144
00150 FXbool detach();
00151
00157 static void exit(FXint code=0);
00158
00162 static void yield();
00163
00167 static FXTime time();
00168
00172 static void sleep(FXTime nsec);
00173
00177 static void wakeat(FXTime nsec);
00178
00184 static FXThread* self();
00185
00189 static FXThreadID current();
00190
00194 static FXint processors();
00195
00199 static FXThreadStorageKey createStorageKey();
00200
00204 static void deleteStorageKey(FXThreadStorageKey key);
00205
00209 static void* getStorage(FXThreadStorageKey key);
00210
00214 static void setStorage(FXThreadStorageKey key,void* ptr);
00215
00219 FXbool priority(Priority prio);
00220
00224 Priority priority() const;
00225
00229 FXbool policy(Policy plcy);
00230
00234 Policy policy() const;
00235
00240 FXbool affinity(FXulong mask);
00241
00245 FXulong affinity() const;
00246
00250 FXbool suspend();
00251
00255 FXbool resume();
00256
00262 virtual ~FXThread();
00263 };
00264
00265 }
00266
00267 #endif
00268