Leviathan  0.8.0.0
Leviathan game engine
Leviathan::ThreadSafeObjectPool< ElementType, KeyType, AutoCleanupObjects > Class Template Reference

Thread safe version of ObjectPool. More...

#include <ObjectPoolThreadSafe.h>

+ Inheritance diagram for Leviathan::ThreadSafeObjectPool< ElementType, KeyType, AutoCleanupObjects >:

Public Member Functions

 ThreadSafeObjectPool ()
 
 ~ThreadSafeObjectPool ()
 
template<typename... Args>
ElementType * ConstructNew (Lock &guard, KeyType forentity, Args &&... args)
 Constructs a new component of the held type for entity. More...
 
template<typename... Args>
ElementType * ConstructNew (KeyType forentity, Args &&... args)
 
bool HasElementsInRemoved () const
 Returns true if there are objects in Removed. More...
 
bool HasElementsInAdded () const
 Returns true if there are objects in Added. More...
 
bool HasElementsInQueued () const
 Returns true if there are objects in Queued. More...
 
template<typename... Args>
void ReleaseQueued (Args &&... args)
 Calls Release with the specified arguments on elements that are queued for destruction. More...
 
template<typename... Args>
void Release (KeyType entity, Args &&... args)
 Calls Release on an object and then removes it from the pool. More...
 
void ClearQueued ()
 Removes elements that are queued for destruction without calling release. More...
 
const auto & GetRemoved (Lock &locked) const
 Returns a reference to the vector of removed elements. More...
 
auto & GetAdded (Lock &locked)
 Returns a reference to the vector of added elements. More...
 
void ClearAdded ()
 Clears the added list. More...
 
void ClearAdded (Lock &guard)
 
void ClearRemoved ()
 Clears the removed list. More...
 
template<typename Any >
void RemoveBasedOnKeyTupleList (const std::vector< std::tuple< Any, KeyType >> &values, bool addtoremoved=false)
 Destroys without releasing elements based on ids in vector. More...
 
void RemoveFromAdded (Lock &guard, KeyType id)
 Removes a specific id from the added list. More...
 
ElementType * Find (Lock &guard, KeyType id) const
 
ElementType * Find (KeyType id) const
 
void Destroy (Lock &guard, KeyType id, bool addtoremoved=true)
 Destroys a component based on id. More...
 
void Destroy (KeyType id, bool addtoremoved=true)
 
void QueueDestroy (Lock &guard, KeyType id)
 Queues destruction of an element. More...
 
void QueueDestroy (KeyType id)
 
void Call (std::function< bool(ElementType &, KeyType, Lock &)> function)
 Calls an function on all the objects in the pool. More...
 
void Clear ()
 Clears the index and replaces the pool with a new one. More...
 
std::unordered_map< KeyType, ElementType * > & GetIndex ()
 Returns a direct access to Index. More...
 
- Public Member Functions inherited from Leviathan::ThreadSafeGeneric< MutexType >
DLLEXPORT ThreadSafeGeneric ()
 
DLLEXPORT ~ThreadSafeGeneric ()
 
FORCE_INLINE void VerifyLock (RecursiveLock &guard) const
 
FORCE_INLINE void VerifyLock (Lock &lockit) const
 

Protected Member Functions

bool RemoveFromIndex (Lock &guard, KeyType id)
 Removes an component from the index but doesn't destruct it. More...
 
bool RemoveFromIndex (KeyType id)
 

Protected Attributes

std::unordered_map< KeyType, ElementType * > Index
 Used for looking up element belonging to id. More...
 
std::vector< std::tuple< ElementType *, KeyType > > Removed
 
std::vector< std::tuple< ElementType *, KeyType > > Queued
 
std::vector< std::tuple< ElementType *, KeyType > > Added
 Used for detecting created elements. More...
 
boost::pool Elements
 Pool for objects. More...
 
- Protected Attributes inherited from Leviathan::ThreadSafeGeneric< MutexType >
MutexType ObjectsLock
 

Detailed Description

template<class ElementType, typename KeyType, bool AutoCleanupObjects = true>
class Leviathan::ThreadSafeObjectPool< ElementType, KeyType, AutoCleanupObjects >

Thread safe version of ObjectPool.

Definition at line 22 of file ObjectPoolThreadSafe.h.

Constructor & Destructor Documentation

◆ ThreadSafeObjectPool()

template<class ElementType , typename KeyType , bool AutoCleanupObjects = true>
Leviathan::ThreadSafeObjectPool< ElementType, KeyType, AutoCleanupObjects >::ThreadSafeObjectPool ( )
inline

Definition at line 25 of file ObjectPoolThreadSafe.h.

25  : Elements(sizeof(ElementType), 100, 200){
26 
27  }
boost::pool Elements
Pool for objects.

◆ ~ThreadSafeObjectPool()

template<class ElementType , typename KeyType , bool AutoCleanupObjects = true>
Leviathan::ThreadSafeObjectPool< ElementType, KeyType, AutoCleanupObjects >::~ThreadSafeObjectPool ( )
inline

Definition at line 29 of file ObjectPoolThreadSafe.h.

29  {
30 
31  if (!AutoCleanupObjects)
32  return;
33 
34  Clear();
35  }
void Clear()
Clears the index and replaces the pool with a new one.

Member Function Documentation

◆ Call()

template<class ElementType , typename KeyType , bool AutoCleanupObjects = true>
void Leviathan::ThreadSafeObjectPool< ElementType, KeyType, AutoCleanupObjects >::Call ( std::function< bool(ElementType &, KeyType, Lock &)>  function)
inline

Calls an function on all the objects in the pool.

Note
The order of the objects is not guaranteed and can change between runs
Parameters
functionThe function that is called with all of the components of this type the first parameter is the component, the second is the id of the entity owning the component and the last one is a lock to this ComponentHolder, the return value specifies if the component should be destroyed (true being yes and false being no)

Definition at line 319 of file ObjectPoolThreadSafe.h.

319  {
320 
321  GUARD_LOCK();
322 
323  for(auto iter = Index.begin(); iter != Index.end(); ){
324 
325  if(function(*iter->second, iter->first, guard)){
326 
327  iter->second->~ElementType();
328  Elements.free(iter->second);
329  iter = Index.erase(iter);
330 
331  } else {
332 
333  ++iter;
334  }
335  }
336  }
boost::pool Elements
Pool for objects.
std::unordered_map< KeyType, ElementType * > Index
Used for looking up element belonging to id.
#define GUARD_LOCK()
Definition: ThreadSafe.h:91

◆ Clear()

template<class ElementType , typename KeyType , bool AutoCleanupObjects = true>
void Leviathan::ThreadSafeObjectPool< ElementType, KeyType, AutoCleanupObjects >::Clear ( )
inline

Clears the index and replaces the pool with a new one.

Warning
All objects after this call are invalid

Definition at line 340 of file ObjectPoolThreadSafe.h.

340  {
341 
342  GUARD_LOCK();
343 
344  for(auto iter = Index.begin(); iter != Index.end(); ++iter){
345 
346  iter->second->~ElementType();
347  Elements.free(iter->second);
348  }
349 
350  Index.clear();
351  Removed.clear();
352  Queued.clear();
353  Added.clear();
354  }
boost::pool Elements
Pool for objects.
std::vector< std::tuple< ElementType *, KeyType > > Removed
std::vector< std::tuple< ElementType *, KeyType > > Added
Used for detecting created elements.
std::vector< std::tuple< ElementType *, KeyType > > Queued
std::unordered_map< KeyType, ElementType * > Index
Used for looking up element belonging to id.
#define GUARD_LOCK()
Definition: ThreadSafe.h:91

◆ ClearAdded() [1/2]

template<class ElementType , typename KeyType , bool AutoCleanupObjects = true>
void Leviathan::ThreadSafeObjectPool< ElementType, KeyType, AutoCleanupObjects >::ClearAdded ( )
inline

Clears the added list.

Definition at line 180 of file ObjectPoolThreadSafe.h.

180  {
181 
182  GUARD_LOCK();
183  ClearAdded(guard);
184  }
void ClearAdded()
Clears the added list.
#define GUARD_LOCK()
Definition: ThreadSafe.h:91

◆ ClearAdded() [2/2]

template<class ElementType , typename KeyType , bool AutoCleanupObjects = true>
void Leviathan::ThreadSafeObjectPool< ElementType, KeyType, AutoCleanupObjects >::ClearAdded ( Lock guard)
inline

Definition at line 186 of file ObjectPoolThreadSafe.h.

186  {
187 
188  Added.clear();
189  }
std::vector< std::tuple< ElementType *, KeyType > > Added
Used for detecting created elements.

◆ ClearQueued()

template<class ElementType , typename KeyType , bool AutoCleanupObjects = true>
void Leviathan::ThreadSafeObjectPool< ElementType, KeyType, AutoCleanupObjects >::ClearQueued ( )
inline

Removes elements that are queued for destruction without calling release.

Definition at line 143 of file ObjectPoolThreadSafe.h.

143  {
144 
145  GUARD_LOCK();
146 
147  for(auto iter = Queued.begin(); iter != Queued.end(); ++iter){
148 
149  auto object = std::get<0>(*iter);
150  const auto id = std::get<1>(*iter);
151 
152  object->~ElementType();
153  Elements.free(object);
154  Removed.push_back(std::make_tuple(object, id));
155  RemoveFromIndex(guard, id);
156  }
157 
158  Queued.clear();
159  }
bool RemoveFromIndex(Lock &guard, KeyType id)
Removes an component from the index but doesn&#39;t destruct it.
boost::pool Elements
Pool for objects.
std::vector< std::tuple< ElementType *, KeyType > > Removed
std::vector< std::tuple< ElementType *, KeyType > > Queued
#define GUARD_LOCK()
Definition: ThreadSafe.h:91

◆ ClearRemoved()

template<class ElementType , typename KeyType , bool AutoCleanupObjects = true>
void Leviathan::ThreadSafeObjectPool< ElementType, KeyType, AutoCleanupObjects >::ClearRemoved ( )
inline

Clears the removed list.

Definition at line 192 of file ObjectPoolThreadSafe.h.

192  {
193 
194  GUARD_LOCK();
195  Removed.clear();
196  }
std::vector< std::tuple< ElementType *, KeyType > > Removed
#define GUARD_LOCK()
Definition: ThreadSafe.h:91

◆ ConstructNew() [1/2]

template<class ElementType , typename KeyType , bool AutoCleanupObjects = true>
template<typename... Args>
ElementType* Leviathan::ThreadSafeObjectPool< ElementType, KeyType, AutoCleanupObjects >::ConstructNew ( Lock guard,
KeyType  forentity,
Args &&...  args 
)
inline

Constructs a new component of the held type for entity.

Exceptions
Exceptionwhen component has not been created

Definition at line 40 of file ObjectPoolThreadSafe.h.

40  {
41 
42  if(Find(guard, forentity))
43  throw Exception("Entity with ID already has object in pool of this type");
44 
45  // Get memory to hold the object //
46  void* memoryforobject = Elements.malloc();
47 
48  if(!memoryforobject)
49  throw Exception("Out of memory for element");
50 
51  // Construct the object //
52  ElementType* created;
53  try {
54  created = new(memoryforobject) ElementType(std::forward<Args>(args)...);
55  }
56  catch (...) {
57 
58  Elements.free(memoryforobject);
59  throw;
60  }
61 
62  // Add to index for finding later //
63  Index.insert(std::make_pair(forentity, created));
64 
65  Added.push_back(std::make_tuple(created, forentity));
66 
67  return created;
68  }
ElementType * Find(Lock &guard, KeyType id) const
boost::pool Elements
Pool for objects.
std::vector< std::tuple< ElementType *, KeyType > > Added
Used for detecting created elements.
std::unordered_map< KeyType, ElementType * > Index
Used for looking up element belonging to id.

◆ ConstructNew() [2/2]

template<class ElementType , typename KeyType , bool AutoCleanupObjects = true>
template<typename... Args>
ElementType* Leviathan::ThreadSafeObjectPool< ElementType, KeyType, AutoCleanupObjects >::ConstructNew ( KeyType  forentity,
Args &&...  args 
)
inline

Definition at line 71 of file ObjectPoolThreadSafe.h.

71  {
72 
73  GUARD_LOCK();
74  return ConstructNew(guard, forentity, args...);
75  }
ElementType * ConstructNew(Lock &guard, KeyType forentity, Args &&... args)
Constructs a new component of the held type for entity.
#define GUARD_LOCK()
Definition: ThreadSafe.h:91

◆ Destroy() [1/2]

template<class ElementType , typename KeyType , bool AutoCleanupObjects = true>
void Leviathan::ThreadSafeObjectPool< ElementType, KeyType, AutoCleanupObjects >::Destroy ( Lock guard,
KeyType  id,
bool  addtoremoved = true 
)
inline

Destroys a component based on id.

Definition at line 262 of file ObjectPoolThreadSafe.h.

262  {
263 
264  auto object = Find(guard, id);
265 
266  if(!object)
267  throw InvalidArgument("ID is not in index");
268 
269  object->~ElementType();
270  Elements.free(object);
271 
272  if(addtoremoved)
273  Removed.push_back(std::make_tuple(object, id));
274 
275  RemoveFromIndex(guard, id);
276  RemoveFromAdded(guard, id);
277  }
void RemoveFromAdded(Lock &guard, KeyType id)
Removes a specific id from the added list.
bool RemoveFromIndex(Lock &guard, KeyType id)
Removes an component from the index but doesn&#39;t destruct it.
ElementType * Find(Lock &guard, KeyType id) const
boost::pool Elements
Pool for objects.
std::vector< std::tuple< ElementType *, KeyType > > Removed

◆ Destroy() [2/2]

template<class ElementType , typename KeyType , bool AutoCleanupObjects = true>
void Leviathan::ThreadSafeObjectPool< ElementType, KeyType, AutoCleanupObjects >::Destroy ( KeyType  id,
bool  addtoremoved = true 
)
inline

Definition at line 279 of file ObjectPoolThreadSafe.h.

279  {
280 
281  GUARD_LOCK();
282  Destroy(guard, id, addtoremoved);
283  }
void Destroy(Lock &guard, KeyType id, bool addtoremoved=true)
Destroys a component based on id.
#define GUARD_LOCK()
Definition: ThreadSafe.h:91

◆ Find() [1/2]

template<class ElementType , typename KeyType , bool AutoCleanupObjects = true>
ElementType* Leviathan::ThreadSafeObjectPool< ElementType, KeyType, AutoCleanupObjects >::Find ( Lock guard,
KeyType  id 
) const
inline
Returns
The found component or NULL

Definition at line 245 of file ObjectPoolThreadSafe.h.

245  {
246 
247  auto iter = Index.find(id);
248 
249  if(iter == Index.end())
250  return nullptr;
251 
252  return iter->second;
253  }
std::unordered_map< KeyType, ElementType * > Index
Used for looking up element belonging to id.

◆ Find() [2/2]

template<class ElementType , typename KeyType , bool AutoCleanupObjects = true>
ElementType* Leviathan::ThreadSafeObjectPool< ElementType, KeyType, AutoCleanupObjects >::Find ( KeyType  id) const
inline

Definition at line 255 of file ObjectPoolThreadSafe.h.

255  {
256 
257  GUARD_LOCK();
258  return Find(guard, id);
259  }
ElementType * Find(Lock &guard, KeyType id) const
#define GUARD_LOCK()
Definition: ThreadSafe.h:91

◆ GetAdded()

template<class ElementType , typename KeyType , bool AutoCleanupObjects = true>
auto& Leviathan::ThreadSafeObjectPool< ElementType, KeyType, AutoCleanupObjects >::GetAdded ( Lock locked)
inline

Returns a reference to the vector of added elements.

Note
This object needs to be locked and kept locked while using the result of this call

Definition at line 174 of file ObjectPoolThreadSafe.h.

174  {
175 
176  return Added;
177  }
std::vector< std::tuple< ElementType *, KeyType > > Added
Used for detecting created elements.

◆ GetIndex()

template<class ElementType , typename KeyType , bool AutoCleanupObjects = true>
std::unordered_map<KeyType, ElementType*>& Leviathan::ThreadSafeObjectPool< ElementType, KeyType, AutoCleanupObjects >::GetIndex ( )
inline

Returns a direct access to Index.

Note
Do not change the returned index it is intended only for looping. Okay, you may change it but you have to be extremely careful

Definition at line 359 of file ObjectPoolThreadSafe.h.

359  {
360 
361  return Index;
362  }
std::unordered_map< KeyType, ElementType * > Index
Used for looking up element belonging to id.

◆ GetRemoved()

template<class ElementType , typename KeyType , bool AutoCleanupObjects = true>
const auto& Leviathan::ThreadSafeObjectPool< ElementType, KeyType, AutoCleanupObjects >::GetRemoved ( Lock locked) const
inline

Returns a reference to the vector of removed elements.

Note
This object needs to be locked and kept locked while using the result of this call

Definition at line 164 of file ObjectPoolThreadSafe.h.

164  {
165 
166  return Removed;
167  }
std::vector< std::tuple< ElementType *, KeyType > > Removed

◆ HasElementsInAdded()

template<class ElementType , typename KeyType , bool AutoCleanupObjects = true>
bool Leviathan::ThreadSafeObjectPool< ElementType, KeyType, AutoCleanupObjects >::HasElementsInAdded ( ) const
inline

Returns true if there are objects in Added.

Definition at line 85 of file ObjectPoolThreadSafe.h.

85  {
86 
87  GUARD_LOCK();
88  return !Added.empty();
89  }
std::vector< std::tuple< ElementType *, KeyType > > Added
Used for detecting created elements.
#define GUARD_LOCK()
Definition: ThreadSafe.h:91

◆ HasElementsInQueued()

template<class ElementType , typename KeyType , bool AutoCleanupObjects = true>
bool Leviathan::ThreadSafeObjectPool< ElementType, KeyType, AutoCleanupObjects >::HasElementsInQueued ( ) const
inline

Returns true if there are objects in Queued.

Definition at line 92 of file ObjectPoolThreadSafe.h.

92  {
93 
94  GUARD_LOCK();
95  return !Queued.empty();
96  }
std::vector< std::tuple< ElementType *, KeyType > > Queued
#define GUARD_LOCK()
Definition: ThreadSafe.h:91

◆ HasElementsInRemoved()

template<class ElementType , typename KeyType , bool AutoCleanupObjects = true>
bool Leviathan::ThreadSafeObjectPool< ElementType, KeyType, AutoCleanupObjects >::HasElementsInRemoved ( ) const
inline

Returns true if there are objects in Removed.

Definition at line 78 of file ObjectPoolThreadSafe.h.

78  {
79 
80  GUARD_LOCK();
81  return !Removed.empty();
82  }
std::vector< std::tuple< ElementType *, KeyType > > Removed
#define GUARD_LOCK()
Definition: ThreadSafe.h:91

◆ QueueDestroy() [1/2]

template<class ElementType , typename KeyType , bool AutoCleanupObjects = true>
void Leviathan::ThreadSafeObjectPool< ElementType, KeyType, AutoCleanupObjects >::QueueDestroy ( Lock guard,
KeyType  id 
)
inline

Queues destruction of an element.

Exceptions
InvalidArgumentwhen key is not found (is already deleted)
Note
This has to be used for objects that require calling Release

Definition at line 288 of file ObjectPoolThreadSafe.h.

288  {
289 
290  auto end = Index.end();
291  for(auto iter = Index.begin(); iter != end; ++iter){
292 
293  if(iter->first == id){
294 
295  Queued.push_back(std::make_tuple(iter->second, id));
296 
297  RemoveFromAdded(guard, id);
298 
299  return;
300  }
301  }
302 
303  throw InvalidArgument("ID is not in index");
304  }
void RemoveFromAdded(Lock &guard, KeyType id)
Removes a specific id from the added list.
std::vector< std::tuple< ElementType *, KeyType > > Queued
std::unordered_map< KeyType, ElementType * > Index
Used for looking up element belonging to id.

◆ QueueDestroy() [2/2]

template<class ElementType , typename KeyType , bool AutoCleanupObjects = true>
void Leviathan::ThreadSafeObjectPool< ElementType, KeyType, AutoCleanupObjects >::QueueDestroy ( KeyType  id)
inline

Definition at line 306 of file ObjectPoolThreadSafe.h.

306  {
307 
308  GUARD_LOCK();
309  QueueDestroy(guard, id);
310  }
void QueueDestroy(Lock &guard, KeyType id)
Queues destruction of an element.
#define GUARD_LOCK()
Definition: ThreadSafe.h:91

◆ Release()

template<class ElementType , typename KeyType , bool AutoCleanupObjects = true>
template<typename... Args>
void Leviathan::ThreadSafeObjectPool< ElementType, KeyType, AutoCleanupObjects >::Release ( KeyType  entity,
Args &&...  args 
)
inline

Calls Release on an object and then removes it from the pool.

Definition at line 123 of file ObjectPoolThreadSafe.h.

123  {
124 
125  GUARD_LOCK();
126 
127  auto* object = Find(guard, entity);
128 
129  if (!object)
130  throw NotFound("entity not in pool");
131 
132  object->Release(std::forward<Args>(args)...);
133 
134  object->~ElementType();
135  Elements.free(object);
136 
137  RemoveFromIndex(guard, entity);
138  RemoveFromAdded(guard, entity);
139  }
void RemoveFromAdded(Lock &guard, KeyType id)
Removes a specific id from the added list.
bool RemoveFromIndex(Lock &guard, KeyType id)
Removes an component from the index but doesn&#39;t destruct it.
ElementType * Find(Lock &guard, KeyType id) const
boost::pool Elements
Pool for objects.
#define GUARD_LOCK()
Definition: ThreadSafe.h:91

◆ ReleaseQueued()

template<class ElementType , typename KeyType , bool AutoCleanupObjects = true>
template<typename... Args>
void Leviathan::ThreadSafeObjectPool< ElementType, KeyType, AutoCleanupObjects >::ReleaseQueued ( Args &&...  args)
inline

Calls Release with the specified arguments on elements that are queued for destruction.

Definition at line 101 of file ObjectPoolThreadSafe.h.

101  {
102 
103  GUARD_LOCK();
104 
105  for(auto iter = Queued.begin(); iter != Queued.end(); ++iter){
106 
107  auto object = std::get<0>(*iter);
108  const auto id = std::get<1>(*iter);
109 
110  object->Release(std::forward<Args>(args)...);
111 
112  object->~ElementType();
113  Elements.free(object);
114  Removed.push_back(std::make_tuple(object, id));
115  RemoveFromIndex(guard, id);
116  }
117 
118  Queued.clear();
119  }
bool RemoveFromIndex(Lock &guard, KeyType id)
Removes an component from the index but doesn&#39;t destruct it.
boost::pool Elements
Pool for objects.
std::vector< std::tuple< ElementType *, KeyType > > Removed
std::vector< std::tuple< ElementType *, KeyType > > Queued
#define GUARD_LOCK()
Definition: ThreadSafe.h:91

◆ RemoveBasedOnKeyTupleList()

template<class ElementType , typename KeyType , bool AutoCleanupObjects = true>
template<typename Any >
void Leviathan::ThreadSafeObjectPool< ElementType, KeyType, AutoCleanupObjects >::RemoveBasedOnKeyTupleList ( const std::vector< std::tuple< Any, KeyType >> &  values,
bool  addtoremoved = false 
)
inline

Destroys without releasing elements based on ids in vector.

Parameters
addtoremovedIf true will add the elements to the Removed index for (possibly) using them to remove attached resources

Definition at line 202 of file ObjectPoolThreadSafe.h.

204  {
205 
206  GUARD_LOCK();
207 
208  for(auto iter = values.begin(); iter != values.end(); ++iter){
209 
210  auto todelete = Index.find(std::get<1>(*iter));
211 
212  if(todelete == Index.end())
213  continue;
214 
215 
216  if(addtoremoved){
217 
218  Removed.push_back(std::make_tuple(todelete->second, todelete->first));
219  }
220 
221  RemoveFromAdded(guard, todelete->first);
222 
223  Index.erase(todelete);
224  }
225  }
void RemoveFromAdded(Lock &guard, KeyType id)
Removes a specific id from the added list.
std::vector< std::tuple< ElementType *, KeyType > > Removed
std::unordered_map< KeyType, ElementType * > Index
Used for looking up element belonging to id.
#define GUARD_LOCK()
Definition: ThreadSafe.h:91

◆ RemoveFromAdded()

template<class ElementType , typename KeyType , bool AutoCleanupObjects = true>
void Leviathan::ThreadSafeObjectPool< ElementType, KeyType, AutoCleanupObjects >::RemoveFromAdded ( Lock guard,
KeyType  id 
)
inline

Removes a specific id from the added list.

Used to remove entries that have been deleted before clearing the added ones

Todo:
Check if this gives better performance than noticing missing elements during node construction

Definition at line 232 of file ObjectPoolThreadSafe.h.

232  {
233 
234  for(auto iter = Added.begin(); iter != Added.end(); ++iter){
235 
236  if(std::get<1>(*iter) == id){
237 
238  Added.erase(iter);
239  return;
240  }
241  }
242  }
std::vector< std::tuple< ElementType *, KeyType > > Added
Used for detecting created elements.

◆ RemoveFromIndex() [1/2]

template<class ElementType , typename KeyType , bool AutoCleanupObjects = true>
bool Leviathan::ThreadSafeObjectPool< ElementType, KeyType, AutoCleanupObjects >::RemoveFromIndex ( Lock guard,
KeyType  id 
)
inlineprotected

Removes an component from the index but doesn't destruct it.

Note
The component will only be deallocated once this object is destructed

Definition at line 367 of file ObjectPoolThreadSafe.h.

367  {
368 
369  auto end = Index.end();
370  for(auto iter = Index.begin(); iter != end; ++iter){
371 
372  if(iter->first == id){
373 
374  Index.erase(iter);
375  return true;
376  }
377  }
378 
379  return false;
380  }
std::unordered_map< KeyType, ElementType * > Index
Used for looking up element belonging to id.

◆ RemoveFromIndex() [2/2]

template<class ElementType , typename KeyType , bool AutoCleanupObjects = true>
bool Leviathan::ThreadSafeObjectPool< ElementType, KeyType, AutoCleanupObjects >::RemoveFromIndex ( KeyType  id)
inlineprotected

Definition at line 382 of file ObjectPoolThreadSafe.h.

382  {
383 
384  GUARD_LOCK();
385  return RemoveFromIndex(id);
386  }
bool RemoveFromIndex(Lock &guard, KeyType id)
Removes an component from the index but doesn&#39;t destruct it.
#define GUARD_LOCK()
Definition: ThreadSafe.h:91

Member Data Documentation

◆ Added

template<class ElementType , typename KeyType , bool AutoCleanupObjects = true>
std::vector<std::tuple<ElementType*, KeyType> > Leviathan::ThreadSafeObjectPool< ElementType, KeyType, AutoCleanupObjects >::Added
protected

Used for detecting created elements.

Definition at line 404 of file ObjectPoolThreadSafe.h.

◆ Elements

template<class ElementType , typename KeyType , bool AutoCleanupObjects = true>
boost::pool Leviathan::ThreadSafeObjectPool< ElementType, KeyType, AutoCleanupObjects >::Elements
protected

Pool for objects.

Definition at line 407 of file ObjectPoolThreadSafe.h.

◆ Index

template<class ElementType , typename KeyType , bool AutoCleanupObjects = true>
std::unordered_map<KeyType, ElementType*> Leviathan::ThreadSafeObjectPool< ElementType, KeyType, AutoCleanupObjects >::Index
protected

Used for looking up element belonging to id.

Definition at line 391 of file ObjectPoolThreadSafe.h.

◆ Queued

template<class ElementType , typename KeyType , bool AutoCleanupObjects = true>
std::vector<std::tuple<ElementType*, KeyType> > Leviathan::ThreadSafeObjectPool< ElementType, KeyType, AutoCleanupObjects >::Queued
protected

Used for marking elements to be deleted later at a suitable time GameWorld uses this to control when components are deleted

Definition at line 401 of file ObjectPoolThreadSafe.h.

◆ Removed

template<class ElementType , typename KeyType , bool AutoCleanupObjects = true>
std::vector<std::tuple<ElementType*, KeyType> > Leviathan::ThreadSafeObjectPool< ElementType, KeyType, AutoCleanupObjects >::Removed
protected

Used for detecting deleted elements later Can be used to unlink resources that have pointers to elements

Definition at line 396 of file ObjectPoolThreadSafe.h.


The documentation for this class was generated from the following file: