sttcl  v0.9c
STTCL C++ template state machine framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SttclThread.h
Go to the documentation of this file.
1 
25 #ifndef STTCLTHREAD_H_
26 #define STTCLTHREAD_H_
27 
28 #ifndef STTCL_DEFAULT_THREADIMPL
29 #if defined(STTCL_POSIX_THREADS) or defined(STTCL_POSIX_IMPL)
30 #include "../PosixThreads/SttclPosixThread.h"
31 #define STTCL_DEFAULT_THREADIMPL sttcl::internal::posix_impl::SttclPosixThread
32 #elif defined(STTCL_BOOST_THREADS) or defined(STTCL_BOOST_IMPL)
33 #include "../BoostThreads/SttclBoostThread.h"
34 #define STTCL_DEFAULT_THREADIMPL sttcl::internal::boost_impl::SttclBoostThread
35 #elif defined(STTCL_CX11_THREADS) or defined(STTCL_CX11_IMPL)
36 #include "../C++11Threads/SttclCx11Thread.h"
37 #define STTCL_DEFAULT_THREADIMPL sttcl::internal::cx11_impl::SttclCx11Thread
38 #endif
39 
40 #ifndef STTCL_DEFAULT_THREADIMPL
41 #error "You need to define a default thread implementation for sttcl"
42 #endif
43 #endif
44 
45 namespace sttcl
46 {
47 
48 namespace internal
49 {
50 
57 template<class Impl = STTCL_DEFAULT_THREADIMPL>
59 : public Impl
60 {
61 public:
65  typedef void* (*ThreadMethodPtr)(void*);
66 
71  SttclThread(ThreadMethodPtr argThreadMethod) : Impl(argThreadMethod)
72  {
73  }
78 
83  bool run(void* args)
84  {
85  return static_cast<Impl*>(this)->run(args);
86  }
87 
91  void join()
92  {
93  static_cast<Impl*>(this)->join();
94  }
95 
99  void detach()
100  {
101  static_cast<Impl*>(this)->detach();
102  }
103 
109  static bool isSelf(const Impl& otherThread)
110  {
111  return Impl::isSelf(otherThread);
112  }
113 
114 private:
115  SttclThread();
116  SttclThread(const SttclThread<Impl>& rhs);
117  SttclThread<Impl>& operator=(const SttclThread<Impl>& rhs);
118 };
119 }
120 }
121 
122 #endif /* STTCLTHREAD_H_ */