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

void clear ()
 
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 { clear(); }
void clear()
Definition: Pool.h:19

Member Function Documentation

◆ addBack()

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

Definition at line 51 of file Pool.h.

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

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

◆ clear()

template<typename TT>
void mkfit::Pool< TT >::clear ( void  )
inline

Definition at line 19 of file Pool.h.

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

19  {
20  TT *x = nullptr;
21  while (m_stack.try_pop(x)) {
22  destroy(x);
23  }
24  }
void destroy(TT *x)
Definition: Pool.h:46
float x
tbb::concurrent_queue< TT * > m_stack
Definition: Pool.h:53

◆ create()

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

Definition at line 44 of file Pool.h.

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

44 { 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 46 of file Pool.h.

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

46  {
47  x->~TT();
48  std::free(x);
49  };
void free(void *ptr) noexcept
float x

◆ makeOrGet()

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

Definition at line 34 of file Pool.h.

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

◆ populate()

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

Definition at line 28 of file Pool.h.

28  {
29  for (int i = 0; i < threads; ++i) {
30  m_stack.push(create());
31  }
32  }
tbb::concurrent_queue< TT * > m_stack
Definition: Pool.h:53
TT * create()
Definition: Pool.h:44

◆ size()

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

Definition at line 26 of file Pool.h.

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

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

Member Data Documentation

◆ m_stack

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