You.i Engine
YiThreadManager.h
Go to the documentation of this file.
1 // © You i Labs Inc. 2000-2017. All rights reserved.
2 #ifndef _YI_THREAD_MANAGER_H_
3 #define _YI_THREAD_MANAGER_H_
4 
5 #include "framework/YiPredef.h"
6 #include "thread/YiMutex.h"
8 
9 #include <memory>
10 
44 {
45 public:
46  CYIThreadManager() : m_UniqueId(1)
47  {}
48 
50  {}
51 
52 
59  uint32_t CreateManager(uint32_t count);
60 
73  void DeleteManager(uint32_t managerId);
74 
92  bool GetThread(uint32_t managerId, uint32_t timeout = 0);
93 
103  bool ReleaseThread(uint32_t managerId);
104 
105  // Informative Data:
106  // On a manager:
107  bool IsManagerExist(uint32_t managerId) const;
108  bool IsManagerActive(uint32_t managerId) const;
109  int32_t GetAvailableThreadCount(uint32_t managerId) const;
110  // Overall:
111  int32_t GetCreatedManagerCount() const;
112  int32_t GetActiveManagerCount() const;
113 
114 private:
115  class ManagerInfo
116  {
117  public:
118  ManagerInfo(uint32_t _id, uint32_t _max) :
119  m_uId(_id),
120  m_uCnt(_max),
121  m_uSize(_max),
122  m_bIsDeleted(false)
123  {}
124 
125  bool IsThreadAvailable() // Same meaning with the mThreadAvailable condition
126  {
127  return (m_uCnt != 0);
128  }
129  uint32_t m_uId;
130  uint32_t m_uCnt;
131  uint32_t m_uSize;
132  bool m_bIsDeleted;
133  mutable CYIWaitCondition m_ThreadAvailable;
134  };
135 
136  uint32_t m_UniqueId;
137 
138  std::list<std::shared_ptr<ManagerInfo>> m_Managers;
139  mutable CYIMutex m_ManagersMutex; // Protect when modifying the list
140  // mutable so that it can be used in const functions
141  // and the object is still a const 'logically'
142 };
143 
146 #endif // _YI_THREAD_MANAGER_H_
int32_t GetActiveManagerCount() const
Definition: YiMutex.h:110
~CYIThreadManager()
Definition: YiThreadManager.h:49
bool IsManagerActive(uint32_t managerId) const
CYIThreadManager()
Definition: YiThreadManager.h:46
bool IsManagerExist(uint32_t managerId) const
Definition: YiThreadManager.h:43
int32_t GetAvailableThreadCount(uint32_t managerId) const
void DeleteManager(uint32_t managerId)
A class used to block a thread until a condition is met, as signaled by a different thread...
Definition: YiWaitCondition.h:64
bool GetThread(uint32_t managerId, uint32_t timeout=0)
bool ReleaseThread(uint32_t managerId)
uint32_t CreateManager(uint32_t count)
int32_t GetCreatedManagerCount() const