1 #ifndef FWCore_Utilities_ReusableObjectHolder_h
2 #define FWCore_Utilities_ReusableObjectHolder_h
72 #include "tbb/concurrent_queue.h"
92 void add(std::unique_ptr<T> iItem){
105 return std::shared_ptr<T>{};
110 return std::shared_ptr<T>{item, [pHolder](
T* iItem) {pHolder->addBack(iItem);} };
114 template<
typename F>
116 std::shared_ptr<T> returnValue;
117 while ( ! ( returnValue =
tryToGet()) ) {
118 add( std::unique_ptr<T>(iFunc()) );
126 template<
typename FM,
typename FC>
128 std::shared_ptr<T> returnValue;
129 while ( ! ( returnValue =
tryToGet()) ) {
130 add( std::unique_ptr<T>(iMakeFunc()) );
132 iClearFunc(returnValue.get());
tbb::concurrent_queue< T * > m_availableQueue
std::shared_ptr< T > makeOrGet(F iFunc)
If there isn't an object already available, creates a new one using iFunc.
std::shared_ptr< T > makeOrGetAndClear(FM iMakeFunc, FC iClearFunc)
void add(std::unique_ptr< T > iItem)
std::shared_ptr< T > tryToGet()
std::atomic< size_t > m_outstandingObjects
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)