00001 #ifndef THREAD_OBJ_H 00002 #define THREAD_OBJ_H 00003 #include <pthread.h> 00004 #include <string> 00005 #include "engine/mutex.h" 00006 #include "tools/log.h" 00007 00011 class ThreadObj 00012 { 00013 Mutex lock; 00014 00015 bool has_started; 00016 bool ask_stop; 00017 bool stopped; 00018 00019 bool thread_running; 00020 00021 protected: 00026 virtual void Main() = 0; 00027 00031 bool GetAskStop(); 00032 public: 00033 pthread_t id; 00034 std::string name; 00035 00040 ThreadObj(std::string name); 00041 00042 virtual ~ThreadObj(); 00043 00045 void Start(); 00046 00051 void Stop(); 00052 00057 void Kill(); 00058 00063 virtual void OnStart() {} 00064 00070 virtual void OnStop() {} 00071 static void *StartThread(void*); 00072 00076 bool GetStopped(); 00077 }; 00078 00082 ThreadObj* GetCurrentThread(); 00083 00084 #endif //THREAD_OBJ_H
1.5.8