Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

thread.h

Go to the documentation of this file.
00001 /*
00002 **  ClanLib SDK
00003 **  Copyright (c) 1997-2005 The ClanLib Team
00004 **
00005 **  This software is provided 'as-is', without any express or implied
00006 **  warranty.  In no event will the authors be held liable for any damages
00007 **  arising from the use of this software.
00008 **
00009 **  Permission is granted to anyone to use this software for any purpose,
00010 **  including commercial applications, and to alter it and redistribute it
00011 **  freely, subject to the following restrictions:
00012 **
00013 **  1. The origin of this software must not be misrepresented; you must not
00014 **     claim that you wrote the original software. If you use this software
00015 **     in a product, an acknowledgment in the product documentation would be
00016 **     appreciated but is not required.
00017 **  2. Altered source versions must be plainly marked as such, and must not be
00018 **     misrepresented as being the original software.
00019 **  3. This notice may not be removed or altered from any source distribution.
00020 **
00021 **  Note: Some of the libraries ClanLib link to may have additional
00022 **  requirements or restrictions.
00023 **
00024 **  File Author(s):
00025 **
00026 **    Magnus Norddahl
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

Generated on Sat Feb 19 22:51:16 2005 for npcore by  doxygen 1.4.1