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 #ifndef header_thread
00030 #define header_thread
00031
00032 #include "runnable.h"
00033 #include "exception.h"
00034 #ifndef WIN32
00035 #ifndef __USE_UNIX98
00036 #define __USE_UNIX98
00037 #endif
00038 #include <pthread.h>
00039 #endif
00040
00041 class CL_Thread
00042 {
00044 public:
00045 CL_Thread();
00046
00047 ~CL_Thread();
00048
00050 public:
00051
00053 public:
00054 void start(CL_Runnable *runnable);
00055
00056 template<class C>
00057 void start(C *instance, void (C::*member)())
00058 {
00059 CL_Runnable *r = new CL_RunnableMember_v0<C>(instance, member);
00060 try
00061 {
00062 start(r);
00063 }
00064 catch (CL_Exception e)
00065 {
00066 delete r;
00067 throw;
00068 }
00069 }
00070
00071 template<class C, class P1>
00072 void start(C *instance, void (C::*member)(P1 p1), P1 p1)
00073 {
00074 CL_Runnable *r = new CL_RunnableMember_v1<C, P1>(instance, member, p1);
00075 try
00076 {
00077 start(r);
00078 }
00079 catch (CL_Exception e)
00080 {
00081 delete r;
00082 throw;
00083 }
00084 }
00085
00086 template<class C, class P1, class P2>
00087 void start(C *instance, void (C::*member)(P1 p1, P2 p2), P1 p1, P2 p2)
00088 {
00089 CL_Runnable *r = new CL_RunnableMember_v2<C, P1, P2>(instance, member, p1, p2);
00090 try
00091 {
00092 start(r);
00093 }
00094 catch (CL_Exception e)
00095 {
00096 delete r;
00097 throw;
00098 }
00099 }
00100
00101 template<class C, class P1, class P2, class P3>
00102 void start(C *instance, void (C::*member)(P1 p1, P2 p2, P3 p3), P1 p1, P2 p2, P3 p3)
00103 {
00104 CL_Runnable *r = new CL_RunnableMember_v3<C, P1, P2, P3>(instance, member, p1, p2, p3);
00105 try
00106 {
00107 start(r);
00108 }
00109 catch (CL_Exception e)
00110 {
00111 delete r;
00112 throw;
00113 }
00114 }
00115
00116 template<class C, class P1, class P2, class P3, class P4>
00117 void start(C *instance, void (C::*member)(P1 p1, P2 p2, P3 p3, P4 p4), P1 p1, P2 p2, P3 p3, P4 p4)
00118 {
00119 CL_Runnable *r = new CL_RunnableMember_v4<C, P1, P2, P3, P4>(instance, member, p1, p2, p3, p4);
00120 try
00121 {
00122 start(r);
00123 }
00124 catch (CL_Exception e)
00125 {
00126 delete r;
00127 throw;
00128 }
00129 }
00130
00131 template<class C, class P1, class P2, class P3, class P4, class P5>
00132 void start(C *instance, void (C::*member)(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5), P1 p1, P2 p2, P3 p3, P4 p4, P5 p5)
00133 {
00134 CL_Runnable *r = new CL_RunnableMember_v5<C, P1, P2, P3, P4, P5>(instance, member, p1, p2, p3, p4, p5);
00135 try
00136 {
00137 start(r);
00138 }
00139 catch (CL_Exception e)
00140 {
00141 delete r;
00142 throw;
00143 }
00144 }
00145
00146 void join();
00147
00149 private:
00150 #ifdef WIN32
00151 static DWORD WINAPI thread_main(void *data);
00152
00153 HANDLE handle;
00154 #else
00155 static void *thread_main(void *data);
00156
00157 pthread_t handle;
00158 #endif
00159 };
00160
00161 #endif