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>{};
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) {