Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #pragma once
00038
00039 #include "rptypes.h"
00040 #define CLASS_THREAD(c , x ) \
00041 rp::hal::Thread::create_member<c, &c::x>(this )
00042
00043 namespace rp{ namespace hal{
00044
00045 class Thread
00046 {
00047 public:
00048 enum priority_val_t
00049 {
00050 PRIORITY_REALTIME = 0,
00051 PRIORITY_HIGH = 1,
00052 PRIORITY_NORMAL = 2,
00053 PRIORITY_LOW = 3,
00054 PRIORITY_IDLE = 4,
00055 };
00056
00057 template <class T, u_result (T::*PROC)(void)>
00058 static Thread create_member(T * pthis)
00059 {
00060 return create(_thread_thunk<T,PROC>, pthis);
00061 }
00062
00063 template <class T, u_result (T::*PROC)(void) >
00064 static _word_size_t THREAD_PROC _thread_thunk(void * data)
00065 {
00066 return (static_cast<T *>(data)->*PROC)();
00067 }
00068 static Thread create(thread_proc_t proc, void * data = NULL );
00069
00070 public:
00071 ~Thread() { }
00072 Thread(): _data(NULL),_func(NULL),_handle(0) {}
00073 _word_size_t getHandle(){ return _handle;}
00074 u_result terminate();
00075 void *getData() { return _data;}
00076 u_result join(unsigned long timeout = -1);
00077 u_result setPriority( priority_val_t p);
00078 priority_val_t getPriority();
00079
00080 bool operator== ( const Thread & right) { return this->_handle == right._handle; }
00081 protected:
00082 Thread( thread_proc_t proc, void * data ): _data(data),_func(proc), _handle(0) {}
00083 void * _data;
00084 thread_proc_t _func;
00085 _word_size_t _handle;
00086 };
00087
00088 }}
00089