ANNA Suite  2020b
Multipurpose development suite for Telco applications
ThreadManager.hpp
Go to the documentation of this file.
1 // ANNA - Anna is Not Nothingness Anymore //
2 // //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo //
4 // //
5 // See project site at http://redmine.teslayout.com/projects/anna-suite //
6 // See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
7 
8 
9 #ifndef anna_core_mt_ThreadManager_hpp
10 #define anna_core_mt_ThreadManager_hpp
11 
12 #include <string>
13 
15 #include <anna/core/mt/Thread.hpp>
16 
17 #include <anna/core/core.hpp>
18 
19 namespace anna {
20 
21 class Semaphore;
22 
27 class ThreadManager : SafeRecycler <Thread> {
28 public:
33  struct Mode {
34  enum _v {
40  };
41 
43  };
44 
46 
54  ThreadManager(const char* name, const Mode::_v mode, const int maxSize, const int flags = Thread::Flag::None);
55 
62  ThreadManager(const char* name, const int flags = Thread::Flag::None);
63 
67  virtual ~ThreadManager();
68 
73  const std::string& getName() const { return a_name; }
74 
81  Thread* createThread() noexcept(false);
82 
88  void join() noexcept(false);
89 
94  thread_iterator thread_begin() { return begin(); }
95 
100  thread_iterator thread_end() { return end(); }
101 
107  static Thread* thread(thread_iterator ii) { return SafeRecycler <Thread>::data(ii); }
108 
113  std::string asString() const ;
114 
115 private:
116  const std::string a_name;
117  const Mode::_v a_mode;
118  const int a_maxSize;
119  Semaphore* a_semaphore;
120  const int a_threadFlags;
121  bool a_destroying;
122 
123  // Se invoca cuando el thread detecta que va a terminar y que tiene una factoria asociada.
124  void releaseThread(Thread* thread) noexcept(false);
125 
126  friend class Thread;
127 };
128 
129 } //namespace anna
130 
131 #endif
132 
Definition: ThreadManager.hpp:35
Definition: Thread.hpp:31
Definition: ThreadManager.hpp:33
Thread * createThread() noexcept(false)
Definition: ThreadManager.hpp:27
const std::string & getName() const
Definition: ThreadManager.hpp:73
Definition: ThreadManager.hpp:37
ThreadManager(const char *name, const Mode::_v mode, const int maxSize, const int flags=Thread::Flag::None)
std::string asString() const
iterator thread_iterator
Definition: ThreadManager.hpp:45
void join() noexcept(false)
thread_iterator thread_end()
Definition: ThreadManager.hpp:100
Definition: SafeRecycler.hpp:36
iterator end()
Definition: Recycler.hpp:221
thread_iterator thread_begin()
Definition: ThreadManager.hpp:94
Definition: ThreadManager.hpp:38
Definition: ThreadManager.hpp:36
Definition: app.hpp:12
_v
Definition: ThreadManager.hpp:34
virtual ~ThreadManager()
Definition: Semaphore.hpp:30
iterator begin()
Definition: Recycler.hpp:209
Recycler< Thread, Allocator< Thread > >::iterator iterator
Definition: SafeRecycler.hpp:38
static Thread * thread(thread_iterator ii)
Definition: ThreadManager.hpp:107
Definition: Thread.hpp:38