1 #ifndef FWCore_Utilities_ReusableObjectHolder_h 2 #define FWCore_Utilities_ReusableObjectHolder_h 72 #include "tbb/concurrent_queue.h" 81 assert(0 == iOther.m_outstandingObjects);
94 void add(std::unique_ptr<T> iItem) {
107 return std::shared_ptr<T>{};
112 return std::shared_ptr<T>{item, [pHolder](
T* iItem) { pHolder->addBack(iItem); }};
116 template <
typename F>
118 std::shared_ptr<T> returnValue;
119 while (!(returnValue =
tryToGet())) {
120 add(std::unique_ptr<T>(iFunc()));
128 template <
typename FM,
typename FC>
130 std::shared_ptr<T> returnValue;
131 while (!(returnValue =
tryToGet())) {
132 add(std::unique_ptr<T>(iMakeFunc()));
134 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)
ReusableObjectHolder(ReusableObjectHolder &&iOther)
std::shared_ptr< T > tryToGet()
std::atomic< size_t > m_outstandingObjects
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)