1 #ifndef FWCore_Utilities_ReusableObjectHolder_h 2 #define FWCore_Utilities_ReusableObjectHolder_h 76 #include "tbb/concurrent_queue.h" 79 template <
class T,
class Deleter = std::default_delete<T>>
87 assert(0 == iOther.m_outstandingObjects);
91 std::unique_ptr<T, Deleter>
item;
100 void add(std::unique_ptr<T, Deleter> iItem) {
101 if (
nullptr != iItem) {
110 std::unique_ptr<T, Deleter>
item;
112 if (
nullptr == item) {
113 return std::shared_ptr<T>{};
117 auto deleter = item.get_deleter();
119 return std::shared_ptr<T>{item.release(), [pHolder,
deleter](
T* iItem) {
120 pHolder->addBack(std::unique_ptr<T, Deleter>{iItem,
deleter});
125 template <
typename F>
127 std::shared_ptr<T> returnValue;
128 while (!(returnValue =
tryToGet())) {
137 template <
typename FM,
typename FC>
139 std::shared_ptr<T> returnValue;
140 while (!(returnValue =
tryToGet())) {
143 iClearFunc(returnValue.get());
149 static_assert(std::is_same_v<Deleter, std::default_delete<T>>,
150 "Generating functions returning raw pointers are supported only with std::default_delete<T>");
151 return std::unique_ptr<T>{ptr};
154 std::unique_ptr<T, Deleter>
makeUnique(std::unique_ptr<T, Deleter> ptr) {
return ptr; }
156 void addBack(std::unique_ptr<T, Deleter> iItem) {
std::default_delete< edm::ESProductHost > deleter_type
tbb::concurrent_queue< std::unique_ptr< T, Deleter > > m_availableQueue
std::unique_ptr< T > makeUnique(T *ptr)
void add(std::unique_ptr< T, Deleter > iItem)
void addBack(std::unique_ptr< T, Deleter > iItem)
std::atomic< size_t > m_outstandingObjects
std::shared_ptr< T > makeOrGetAndClear(FM iMakeFunc, FC iClearFunc)
std::unique_ptr< T, Deleter > makeUnique(std::unique_ptr< T, Deleter > ptr)
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 > tryToGet()
ReusableObjectHolder(ReusableObjectHolder &&iOther)
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)