thread.h

Go to the documentation of this file.
00001 /*
00002 **  ClanLib SDK
00003 **  Copyright (c) 1997-2009 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 may link to may have additional
00022 **  requirements or restrictions.
00023 **
00024 **  File Author(s):
00025 **
00026 **    Magnus Norddahl
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 

Generated on Thu Dec 3 02:39:32 2009 for ClanLib by  doxygen 1.4.6