00001 #ifndef THREAD_H 00002 #define THREAD_H 00003 00004 #include <pthread.h> 00005 00006 // The thread does not autodelete by default. 00007 // If autodelete is 1 the thread autodeletes. 00008 // If it's synchronous the deletion occurs in join(). 00009 // If it's asynchronous the deletion occurs in entrypoint. 00010 00011 00012 class Thread 00013 { 00014 private: 00015 static void* entrypoint(void *parameters); 00016 protected: 00017 virtual void run() = 0; 00018 public: 00019 Thread(int synchronous = 0, int realtime = 0, int autodelete = 0); 00020 virtual ~Thread(); 00021 void start(); 00022 int end(pthread_t tid); // end another thread 00023 int end(); // end this thread 00024 int cancel(); // end this thread 00025 int join(); // join this thread 00026 int suspend_thread(); // suspend this thread 00027 int continue_thread(); // continue this thread 00028 int exit_thread(); // exit this thread 00029 int enable_cancel(); 00030 int disable_cancel(); 00031 int get_cancel_enabled(); 00032 int running(); // Return if thread is running 00033 int set_synchronous(int value); 00034 int set_realtime(int value = 1); 00035 int set_autodelete(int value); 00036 int get_autodelete(); 00037 // Return realtime variable 00038 int get_realtime(); 00039 // Return 1 if querying the kernel returned a realtime policy 00040 static int calculate_realtime(); 00041 int get_synchronous(); 00042 int get_tid(); 00043 00044 private: 00045 int synchronous; // set to 1 to force join() to end 00046 int realtime; // set to 1 to schedule realtime 00047 int autodelete; // set to 1 to autodelete when run() finishes 00048 int thread_running; 00049 pthread_t tid; 00050 int tid_valid; 00051 int cancel_enabled; 00052 }; 00053 00054 #endif
1.5.5