Thread.h

00001 // $Id: Thread.h 21 2010-09-05 04:18:17Z cschwarz1 $
00002 
00003 #ifndef BASE_THREAD_H
00004 #define BASE_THREAD_H
00005 
00006 #ifdef _WIN32
00007     #define WIN32_LEAN_AND_MEAN
00008     #include <windows.h>
00009 #else
00010     #include <pthread.h>
00011 #endif
00012 #include "IOException.h"
00013 #include "ThreadList.h"
00014 
00015 namespace base {
00017 
00031     class PPBASE_EXPORT Thread {
00032     public:
00034         Thread(ThreadList *list = NULL);
00035 
00037         virtual ~Thread();
00038 
00053         void cancel(bool immediate = false);
00054 
00056 
00059         bool cleanup();
00060 
00062 
00065         static unsigned long getCpuMilliSeconds();
00066 
00068 
00071         unsigned long getCpuMilliSecondsBase() const;
00072 
00074 
00077         ThreadList *getList();
00078 
00080 
00083         int getPid() const;
00084 
00086 
00089         bool isCancelled() const;
00090 
00092 
00095         bool isRunning() const;
00096 
00098         void launch();
00099 
00101         void reconfig();
00102 
00104 
00108         virtual void run() = 0;
00109 
00111 
00116         void setCpuMilliSecondsBase();
00117 
00119 
00125         void setPriority(int priority);
00126 
00128 
00131         void setPriorityBoost(bool enabled);
00132 
00134         static void sleep(unsigned msecs);
00135 
00141         void start(bool detached = false);
00142 
00144 
00148         bool wait(unsigned timeout = 0);
00149 
00150     protected:
00151         bool           _cancelled;   
00152         ThreadList    *_list;        
00153         unsigned long  _msbase;      
00154         int            _pid;         
00155         bool           _reconfig;    
00156         bool           _running;     
00157     #ifdef _WIN32
00158         LCID           _locale;      
00159         HANDLE         _thread;      
00160     #else
00161         pthread_t      _thread;      
00162     #endif
00163 
00165         DISALLOW_COPY_CONSTRUCTOR_AND_ASSIGNMENT(Thread);
00166     };
00167 }
00168 
00169 #endif