gatelib  2.1
g_mthread_ThreadTypes.h
1 #pragma once
2 
3 #include "g_mthread_ThreadAbstract.h"
4 #include "g_signal.h"
5 
6 namespace g
7 {
8 namespace mthread
9 {
10 G_EXC_DEFINE_MSG(ThreadNotHavingSubscribersException,g::mthread::MultithreadException,"Invalid call of start with no subscribers added");
11 }//namespace mthread
12 }//namespace g
13 
15 G_SIGNAL(g::mthread::ThreadWithParamEvent(void* aPar))
16 
17 #include G_SIGNAL_INCLUDE(g.mthread.ThreadSimpleEvent)
18 #include G_SIGNAL_INCLUDE(g.mthread.ThreadWithParamEvent)
19 
20 namespace g
21 {
22 namespace mthread
23 {
24 
25 #if G_AUTOPTION_ON_MSVC
26 # pragma warning ( disable : 4512 )
27 #endif
28 
30 {
31  G_COPY_CONSTRUCTOR_PROHIBITED(ThreadSimple);
32 public:
33  template <class T>ThreadSimple ( T* aP , void ( T::*method ) ( ) )
34  {
35  subscribe ( aP , method );
36  }
37 
38  ThreadSimple ( void (*simple) () )
39  {
40  subscribe(simple);
41  }
42 
43  //no params event
44  void start ( const char* aName = NULL )
45  {
46  ThreadAbstract::start(NULL,aName);
47  }
48 private:
49  inline void start( void* , const char* ) { ThreadAbstract::start(); }
50 
51  void mEntryPoint ( void* )
52  {
53  send();
54 
55  doClearSubscribers();
56  }
57 };
58 
60 {
61  G_COPY_CONSTRUCTOR_PROHIBITED ( ThreadWithParam );
62 public:
63  template <class T>ThreadWithParam ( T* aP , void ( T::*method ) ( void* ) )
64  {
65  subscribe ( aP , method );
66  }
67 
68  ThreadWithParam ( void (*simple) (void*) )
69  {
70  subscribe(simple);
71  }
72 
73  inline void start( void* p ) { ThreadAbstract::start(p); }
74 
75 private:
76  void mEntryPoint ( void* aPar )
77  {
78  send(aPar);
79 
80  doClearSubscribers();
81  }
82 };
83 
84 template <class E,class Q=g::signal::QueueTxRxSimple> struct params_thread : E::template thread_base<g::mthread::ThreadAbstract,Q>{};
85 
86 #if G_AUTOPTION_ON_MSVC
87 # pragma warning ( default : 4512 )
88 #endif
89 
90 
91 }//namespace mthread
92 }//namespace g
Definition: g.mthread.ThreadSimpleEvent.h:41
Definition: g.mthread.ThreadWithParamEvent.h:41
#define G_EXC_DEFINE_MSG(aexctypename, abaseexctypename, amsg)
Definition: g_exception_macros.h:43
Definition: g_mthread_ThreadTypes.h:59
Definition: g.mthread.ThreadSimpleEvent.h:5
Definition: g.mthread.ThreadSimpleEvent.h:16
#define G_SIGNAL(sig_if)
Instanciate a signal with a certain interface.
Definition: g_signal.h:40
Definition: g_mthread_ThreadTypes.h:29
Definition: g_mthread_ThreadAbstract.h:18
Definition: g_mthread_ThreadTypes.h:84