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
00031
00032
00033 #pragma once
00034
00035
00036 #include "../api_core.h"
00037 #include "sharedptr.h"
00038 #include "runnable.h"
00039 #include "exception.h"
00040
00041 class CL_Thread_Impl;
00042
00046 class CL_API_CORE CL_Thread
00047 {
00050
00051 public:
00053 CL_Thread();
00054
00055 ~CL_Thread();
00056
00057
00061
00062 public:
00063
00064
00068
00069 public:
00071 void start(CL_Runnable *runnable);
00072
00073 template<class C>
00074 void start(C *instance, void (C::*member)())
00075 {
00076 CL_Runnable *r = new CL_RunnableMember_v0<C>(instance, member);
00077 try
00078 {
00079 start(r);
00080 }
00081 catch (CL_Exception)
00082 {
00083 delete r;
00084 throw;
00085 }
00086 }
00087
00088 template<class C, class P1>
00089 void start(C *instance, void (C::*member)(P1 p1), P1 p1)
00090 {
00091 CL_Runnable *r = new CL_RunnableMember_v1<C, P1>(instance, member, p1);
00092 try
00093 {
00094 start(r);
00095 }
00096 catch (CL_Exception)
00097 {
00098 delete r;
00099 throw;
00100 }
00101 }
00102
00103 template<class C, class P1, class P2>
00104 void start(C *instance, void (C::*member)(P1 p1, P2 p2), P1 p1, P2 p2)
00105 {
00106 CL_Runnable *r = new CL_RunnableMember_v2<C, P1, P2>(instance, member, p1, p2);
00107 try
00108 {
00109 start(r);
00110 }
00111 catch (CL_Exception)
00112 {
00113 delete r;
00114 throw;
00115 }
00116 }
00117
00118 template<class C, class P1, class P2, class P3>
00119 void start(C *instance, void (C::*member)(P1 p1, P2 p2, P3 p3), P1 p1, P2 p2, P3 p3)
00120 {
00121 CL_Runnable *r = new CL_RunnableMember_v3<C, P1, P2, P3>(instance, member, p1, p2, p3);
00122 try
00123 {
00124 start(r);
00125 }
00126 catch (CL_Exception)
00127 {
00128 delete r;
00129 throw;
00130 }
00131 }
00132
00133 template<class C, class P1, class P2, class P3, class P4>
00134 void start(C *instance, void (C::*member)(P1 p1, P2 p2, P3 p3, P4 p4), P1 p1, P2 p2, P3 p3, P4 p4)
00135 {
00136 CL_Runnable *r = new CL_RunnableMember_v4<C, P1, P2, P3, P4>(instance, member, p1, p2, p3, p4);
00137 try
00138 {
00139 start(r);
00140 }
00141 catch (CL_Exception)
00142 {
00143 delete r;
00144 throw;
00145 }
00146 }
00147
00148 template<class C, class P1, class P2, class P3, class P4, class P5>
00149 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)
00150 {
00151 CL_Runnable *r = new CL_RunnableMember_v5<C, P1, P2, P3, P4, P5>(instance, member, p1, p2, p3, p4, p5);
00152 try
00153 {
00154 start(r);
00155 }
00156 catch (CL_Exception)
00157 {
00158 delete r;
00159 throw;
00160 }
00161 }
00162
00164 void join();
00165
00167
00168 static void set_thread_name(const char *name);
00169
00170
00174
00175 private:
00176 CL_SharedPtr<CL_Thread_Impl> impl;
00178 };
00179
00180