voxelTerrain
 All Classes Functions Variables Typedefs Enumerations Pages
dispatcher.hpp
1 #ifndef BLUB_CORE_DISPATCHER_HPP
2 #define BLUB_CORE_DISPATCHER_HPP
3 
4 #include "blub/async/predecl.hpp"
5 #include "blub/core/list.hpp"
6 #include "blub/core/noncopyable.hpp"
7 #include "blub/core/scopedPtr.hpp"
8 #include "blub/core/string.hpp"
9 
10 #include <functional>
11 
12 
13 namespace boost
14 {
15  class thread;
16  namespace asio
17  {
18  class io_service;
19  }
20 }
21 
22 
23 namespace blub
24 {
25 namespace async
26 {
27 
28 
29 class dispatcher : public noncopyable // TODO free me from threads!
30 {
31 public:
32  typedef std::function<void ()> t_toCallFunction;
33 
34  dispatcher(const uint16& numThreads = 0, const bool& endThreadsAfterAllDone = true, const string& threadName = "");
35  virtual ~dispatcher();
36 
37  void join();
38  void start();
39  void run();
40  void reset();
41  void stop();
42 
43  void dispatch(const t_toCallFunction &handler);
44  void post(const t_toCallFunction &handler);
45 
49  void waitForQueueDone(void);
50 
51  int32 getThreadCount(void);
52 
53  boost::asio::io_service* _getIoService(void);
54 
55 protected:
56  void nameThread(const int32 &indThread);
57 
58 private:
59  void runThread(const int32& indThread);
60 
61 protected:
62  const string m_threadName;
63 
64 private:
65  scopedPointer<boost::asio::io_service> m_service;
66  void* m_work;
67  uint16 m_numThreads;
68  bool m_endThreadsAfterAllDone;
70  t_threads m_threads;
71 
72 };
73 
74 
75 }
76 }
77 
78 
79 #endif // BLUB_CORE_DISPATCHER_HPP
Definition: dispatcher.hpp:13
Definition: dispatcher.hpp:29
Definition: noncopyable.hpp:10
Definition: deadlineTimer.hpp:10
void waitForQueueDone(void)
waitForQueueDone will work only if one thread
Definition: dispatcher.cpp:91