CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
mkfit::Pool< TT > Class Template Reference

#include <Pool.h>

Public Member Functions

auto makeOrGet ()
 
 Pool ()=default
 
void populate (int threads=Config::numThreadsFinder)
 
size_t size () const
 
 ~Pool ()
 

Private Member Functions

void addBack (TT *x)
 
TT * create ()
 
void destroy (TT *x)
 

Private Attributes

tbb::concurrent_queue< TT * > m_stack
 

Detailed Description

template<typename TT>
class mkfit::Pool< TT >

Pool for helper objects. All functions are thread safe.

Definition at line 13 of file Pool.h.

Constructor & Destructor Documentation

◆ Pool()

template<typename TT>
mkfit::Pool< TT >::Pool ( )
default

◆ ~Pool()

template<typename TT>
mkfit::Pool< TT >::~Pool ( )
inline

Definition at line 17 of file Pool.h.

17  {
18  TT *x = nullptr;
19  while (m_stack.try_pop(x)) {
20  destroy(x);
21  }
22  }
void destroy(TT *x)
Definition: Pool.h:44
tbb::concurrent_queue< TT * > m_stack
Definition: Pool.h:51

Member Function Documentation

◆ addBack()

template<typename TT>
void mkfit::Pool< TT >::addBack ( TT *  x)
inlineprivate

Definition at line 49 of file Pool.h.

Referenced by mkfit::Pool< mkfit::MkFitter >::makeOrGet().

49 { m_stack.push(x); }
tbb::concurrent_queue< TT * > m_stack
Definition: Pool.h:51

◆ create()

template<typename TT>
TT* mkfit::Pool< TT >::create ( )
inlineprivate

Definition at line 42 of file Pool.h.

Referenced by mkfit::Pool< mkfit::MkFitter >::makeOrGet(), and mkfit::Pool< mkfit::MkFitter >::populate().

42 { return new (Matriplex::aligned_alloc64(sizeof(TT))) TT; };
void * aligned_alloc64(std::size_t size)
Definition: Memory.h:13

◆ destroy()

template<typename TT>
void mkfit::Pool< TT >::destroy ( TT *  x)
inlineprivate

Definition at line 44 of file Pool.h.

Referenced by mkfit::Pool< mkfit::MkFitter >::~Pool().

44  {
45  x->~TT();
46  std::free(x);
47  };

◆ makeOrGet()

template<typename TT>
auto mkfit::Pool< TT >::makeOrGet ( )
inline

Definition at line 32 of file Pool.h.

32  {
33  TT *x = nullptr;
34  if (not m_stack.try_pop(x)) {
35  x = create();
36  }
37  auto deleter = [this](TT *ptr) { this->addBack(ptr); };
38  return std::unique_ptr<TT, decltype(deleter)>(x, std::move(deleter));
39  }
tbb::concurrent_queue< TT * > m_stack
Definition: Pool.h:51
TT * create()
Definition: Pool.h:42
def move(src, dest)
Definition: eostools.py:511
void addBack(TT *x)
Definition: Pool.h:49

◆ populate()

template<typename TT>
void mkfit::Pool< TT >::populate ( int  threads = Config::numThreadsFinder)
inline

Definition at line 26 of file Pool.h.

26  {
27  for (int i = 0; i < threads; ++i) {
28  m_stack.push(create());
29  }
30  }
tbb::concurrent_queue< TT * > m_stack
Definition: Pool.h:51
TT * create()
Definition: Pool.h:42

◆ size()

template<typename TT>
size_t mkfit::Pool< TT >::size ( void  ) const
inline

Definition at line 24 of file Pool.h.

Referenced by ntupleDataFormat._Collection::__iter__(), and ntupleDataFormat._Collection::__len__().

24 { return m_stack.unsafe_size(); }
tbb::concurrent_queue< TT * > m_stack
Definition: Pool.h:51

Member Data Documentation

◆ m_stack

template<typename TT>
tbb::concurrent_queue<TT *> mkfit::Pool< TT >::m_stack
private