CPN
Computational Process Networks
PthreadFunctional.h
Go to the documentation of this file.
1 //=============================================================================
2 // PthreadFunctional (higher order function) class
3 //-----------------------------------------------------------------------------
4 // POSIX Pthread class library
5 // Copyright (C) 1997-1999 The University of Texas
6 //
7 // This library is free software; you can redistribute it and/or modify it
8 // under the terms of the GNU Library General Public License as published
9 // by the Free Software Foundation; either version 2 of the License, or
10 // (at your option) any later version.
11 //
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // Library General Public License for more details.
16 //
17 // The GNU Public License is available in the file LICENSE, or you
18 // can write to the Free Software Foundation, Inc., 59 Temple Place -
19 // Suite 330, Boston, MA 02111-1307, USA, or you can find it on the
20 // World Wide Web at http://www.fsf.org.
21 //=============================================================================
22 
23 #ifndef PthreadFunctional_h
24 #define PthreadFunctional_h
25 #pragma once
26 
27 #include <cpn/common.h>
29 #ifdef _POSIX_THREADS
30 
32 
33 //-----------------------------------------------------------------------------
34 // The (virtual) base class
35 class PthreadFunctional : public Pthread {
36  public:
37  PthreadFunctional(void) : Pthread() { }
38  PthreadFunctional(const PthreadAttr& attr) : Pthread(attr) { }
39  private:
40  virtual void* EntryPoint(void) = 0;
41 };
42 //-----------------------------------------------------------------------------
43 
44 
45 //-----------------------------------------------------------------------------
46 // templatized class (not intended to be used)
47 template <class T>
49  public:
50  PthreadFunctionalTemplate( T& obj, void* (T::*meth)(void) )
51  : theObject(obj), theMethod(meth) { }
52  PthreadFunctionalTemplate( T& obj, void* (T::*meth)(void), const PthreadAttr& attr)
53  : PthreadFunctional(attr), theObject(obj), theMethod(meth) { }
54  private:
56  void* (T::*theMethod)(void);
57  void* EntryPoint(void) { return (theObject.*theMethod)(); }
58 };
59 //-----------------------------------------------------------------------------
60 
61 
62 //-----------------------------------------------------------------------------
63 // the proper way to create a PthreadFunctional (remember to delete!)
64 template <class T>
65 PthreadFunctional* CreatePthreadFunctional(T* obj, void* (T::*meth)(void))
66 { return new PthreadFunctionalTemplate<T>(*obj, meth); }
67 //-----------------------------------------------------------------------------
68 template <class T>
69 PthreadFunctional* CreatePthreadFunctional(T* obj, void* (T::*meth)(void), const PthreadAttr& attr)
70 { return new PthreadFunctionalTemplate<T>(*obj, meth, attr); }
71 //-----------------------------------------------------------------------------
72 
73 
74 #endif
75 #endif
PthreadFunctional(const PthreadAttr &attr)
void *(T::* theMethod)(void)
PthreadFunctionalTemplate(T &obj, void *(T::*meth)(void))
PthreadFunctionalTemplate(T &obj, void *(T::*meth)(void), const PthreadAttr &attr)
PthreadFunctional * CreatePthreadFunctional(T *obj, void *(T::*meth)(void))
virtual void * EntryPoint(void)=0