OpenPolygon  1.0.0
OpenPolygon is a Rendering Engine
threadmanager.h
1 /*
2  Copyright (C) 2014 - 2016 Mutzii
3 
4  This program is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program. If not, see <http://www.gnu.org/licenses/>.
16 
17 */
18 #ifndef THREADMANAGER_H
19 #define THREADMANAGER_H
20 
21 #include "index.h"
22 
23 namespace Engine
24 {
25  typedef void (*THREAD_FUNC)();
26 
28  {
29  public:
31  virtual ~CustomThreadClass(){}
32  };
33 
39  {
40  public:
41 
42  FunctorWorker();
43  ~FunctorWorker(){}
44 
45  //override me ..
46  virtual void operator()();
47  };
48 
53  class Thread
54  {
55  public:
56 
57  Thread();
58  virtual ~ Thread(){}
59 
64  void start();
65 
71  void join();
72 
77  virtual void process(void)=0;
78 
84  void removeThreadPtr(void);
85 
86  private:
87 
88  void _process(void);
89 
90  boost::thread * mBoostThread;
91  };
92 
93  using ThreadList = std::list< Thread *>;
94 
96  {
97  private:
98  ThreadManager();
99  void operator=( ThreadManager & ){}
100 
101  static ThreadManager * ptrInstance;
102 
103  public:
104 
105  static ThreadManager * getSingletonPtr(void);
106 
107  boost::thread createWorkerFunc( THREAD_FUNC func_pointer );
108  boost::thread createFunctorWorker( FunctorWorker worker );
109 
110  void _register ( Thread * thread );
111  void _unregister( Thread * thread );
112  bool hasThread ( Thread * thread );
113 
114  private:
115 
116  ThreadList mThreadList;
117 
118  };
119 
120 //Examples - ein kleiner Trick um den Inhalt von dem Thread Process immer zu ändern
121 // void GameLoop()
122 // {
123 // //Create a Local Worker Thread
124 // struct Worker : public Thread
125 // {
126 // virtual void process()
127 // {
128 // // Make anything....
129 // }
130 // };
131 
132 // Worker worker;
133 // worker->start();
134 // }
135 
136 }
137 
138 #endif // THREADMANAGER_H
Definition: element.h:23
Definition: threadmanager.h:27
virtual void process(void)=0
process
void start()
start
Definition: ThreadManager.cpp:84
The Thread class.
Definition: threadmanager.h:53
Definition: threadmanager.h:95
The FunctorWorker class.
Definition: threadmanager.h:38
void join()
join
Definition: ThreadManager.cpp:101
void removeThreadPtr(void)
removeThreadPtr
Definition: ThreadManager.cpp:106