1 #ifndef FWCore_Utilities_ReusableObjectHolder_h 2 #define FWCore_Utilities_ReusableObjectHolder_h 78 #include <oneapi/tbb/concurrent_queue.h> 81 template <
class T,
class Deleter = std::default_delete<T>>
89 assert(0 == iOther.m_outstandingObjects);
93 std::unique_ptr<T, Deleter>
item;
102 void add(std::unique_ptr<T, Deleter> iItem) {
103 if (
nullptr != iItem) {
112 std::unique_ptr<T, Deleter>
item;
116 return std::shared_ptr<T>{};
121 template <
typename FM>
123 std::unique_ptr<T, Deleter>
item;
133 template <
typename FM,
typename FC>
135 std::shared_ptr<T> returnValue =
makeOrGet(std::forward<FM>(iMakeFunc));
136 iClearFunc(returnValue.get());
146 return std::shared_ptr<T>{
item.release(), [
this,
deleter](
T* iItem) {
152 static_assert(std::is_same_v<Deleter, std::default_delete<T>>,
153 "Generating functions returning raw pointers are supported only with std::default_delete<T>");
154 return std::unique_ptr<T>{ptr};
157 std::unique_ptr<T, Deleter>
makeUnique(std::unique_ptr<T, Deleter> ptr) {
return ptr; }
159 void addBack(std::unique_ptr<T, Deleter> iItem) {
std::default_delete< edm::ESProductHost > deleter_type
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::unique_ptr< T, Deleter > makeUnique(std::unique_ptr< T, Deleter > ptr)
oneapi::tbb::concurrent_queue< std::unique_ptr< T, Deleter > > m_availableQueue
std::shared_ptr< T > makeOrGetAndClear(FM &&iMakeFunc, FC &&iClearFunc)
std::shared_ptr< T > makeOrGet(FM &&iMakeFunc)
Takes an object from the queue if one is available, or creates one using iMakeFunc.
std::shared_ptr< T > tryToGet()
ReusableObjectHolder(ReusableObjectHolder &&iOther)
std::shared_ptr< T > wrapCustomDeleter(std::unique_ptr< T, Deleter > item)
Wraps an object in a shared_ptr<T> with a custom deleter, that hands the wrapped object.