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 #pragma once
00036
00037 #include "hal/types.h"
00038 #define CLASS_THREAD(c , x ) \
00039 rp::hal::Thread::create_member<c, &c::x>(this )
00040
00041 namespace rp{ namespace hal{
00042
00043 class Thread
00044 {
00045 public:
00046 enum priority_val_t
00047 {
00048 PRIORITY_REALTIME = 0,
00049 PRIORITY_HIGH = 1,
00050 PRIORITY_NORMAL = 2,
00051 PRIORITY_LOW = 3,
00052 PRIORITY_IDLE = 4,
00053 };
00054
00055 template <class T, u_result (T::*PROC)(void)>
00056 static Thread create_member(T * pthis)
00057 {
00058 return create(_thread_thunk<T,PROC>, pthis);
00059 }
00060
00061 template <class T, u_result (T::*PROC)(void) >
00062 static _word_size_t THREAD_PROC _thread_thunk(void * data)
00063 {
00064 return (static_cast<T *>(data)->*PROC)();
00065 }
00066 static Thread create(thread_proc_t proc, void * data = NULL );
00067
00068 public:
00069 ~Thread() { }
00070 Thread(): _data(NULL),_func(NULL),_handle(0) {}
00071 _word_size_t getHandle(){ return _handle;}
00072 u_result terminate();
00073 void *getData() { return _data;}
00074 u_result join(unsigned long timeout = -1);
00075 u_result setPriority( priority_val_t p);
00076 priority_val_t getPriority();
00077
00078 bool operator== ( const Thread & right) { return this->_handle == right._handle; }
00079 protected:
00080 Thread( thread_proc_t proc, void * data ): _data(data),_func(proc), _handle(0) {}
00081 void * _data;
00082 thread_proc_t _func;
00083 _word_size_t _handle;
00084 };
00085
00086 }}
00087