00001 #ifndef THREAD_H_
00002 #define THREAD_H_
00003
00004
00005 #include <pthread.h>
00006 #include <cvd/runnable.h>
00007
00008 namespace CVD {
00013 class Thread : public Runnable
00014 {
00015 public:
00017 Thread();
00018
00020 virtual ~Thread();
00021
00023 void start(Runnable* runnable=0);
00024
00026
00027 void stop();
00028
00030 bool shouldStop() const;
00031
00033 bool isRunning() const;
00034
00036
00037 void join();
00038
00040 pthread_t getID();
00041
00043 virtual void run(){};
00044
00045
00046
00048 static unsigned int count();
00049
00051 static Thread* getCurrent();
00052
00054 static void sleep(unsigned int milli);
00055
00057 static void yield();
00058
00059 private:
00060 static bool init();
00061 static bool ourInitializedFlag;
00062 static void* threadproc(void* param);
00063 static pthread_key_t ourKey;
00064 static unsigned int ourCount;
00065 Runnable* myRunnable;
00066 pthread_t myID;
00067 bool myRunningFlag;
00068 bool myStopFlag;
00069 };
00070
00071 }
00072 #endif