#include <ReusableObjectHolder.h>
Public Types | |
using | deleter_type = Deleter |
Public Member Functions | |
void | add (std::unique_ptr< T, Deleter > iItem) |
template<typename FM > | |
std::shared_ptr< T > | makeOrGet (FM &&iMakeFunc) |
Takes an object from the queue if one is available, or creates one using iMakeFunc. More... | |
template<typename FM , typename FC > | |
std::shared_ptr< T > | makeOrGetAndClear (FM &&iMakeFunc, FC &&iClearFunc) |
ReusableObjectHolder () | |
ReusableObjectHolder (ReusableObjectHolder &&iOther) | |
std::shared_ptr< T > | tryToGet () |
~ReusableObjectHolder () noexcept | |
Private Member Functions | |
void | addBack (std::unique_ptr< T, Deleter > iItem) |
std::unique_ptr< T > | makeUnique (T *ptr) |
std::unique_ptr< T, Deleter > | makeUnique (std::unique_ptr< T, Deleter > ptr) |
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. More... | |
Private Attributes | |
oneapi::tbb::concurrent_queue< std::unique_ptr< T, Deleter > > | m_availableQueue |
std::atomic< size_t > | m_outstandingObjects |
Description: Thread safe way to do create and reuse a group of the same object type.
Usage: This class can be used to safely reuse a series of objects created on demand. The reuse of the objects is safe even across different threads since one can safely call all member functions of this class on the same instance of this class from multiple threads.
This class manages the cache of reusable objects and therefore an instance of this class must live as long as you want the cache to live.
The primary way of using the class is to call makeOrGet:
If the returned object should be be automatically set or reset, call makeOrGetAndClear:
which is equivalent to
NOTE: If you hold onto the std::shared_ptr<> until another call to the ReusableObjectHolder, make sure to release the shared_ptr before the call. That way the object you were just using can go back into the cache and be reused for the call you are going to make. An example
The above example is very contrived, since the better way to do the above is
When a custom deleter is used, the deleter type must be the same to all objects. The deleter is allowed to have state that depends on the object. The deleter object is passed along the std::unique_ptr, and is internally kept along the object. The deleter object must be copyable.
Definition at line 82 of file ReusableObjectHolder.h.
using edm::ReusableObjectHolder< T, Deleter >::deleter_type = Deleter |
Definition at line 84 of file ReusableObjectHolder.h.
|
inline |
Definition at line 86 of file ReusableObjectHolder.h.
|
inline |
Definition at line 87 of file ReusableObjectHolder.h.
|
inlinenoexcept |
Definition at line 91 of file ReusableObjectHolder.h.
|
inline |
Adds the item to the cache. Use this function if you know ahead of time how many cached items you will need.
Definition at line 102 of file ReusableObjectHolder.h.
Referenced by counter.Counter::register().
|
inlineprivate |
Definition at line 158 of file ReusableObjectHolder.h.
Referenced by edm::ReusableObjectHolder< edm::ESProductHost >::wrapCustomDeleter().
|
inline |
Takes an object from the queue if one is available, or creates one using iMakeFunc.
Definition at line 122 of file ReusableObjectHolder.h.
Referenced by edm::ReusableObjectHolder< edm::ESProductHost >::makeOrGetAndClear(), EcalSeverityLevelESProducer::produce(), RPCInverseCPPFLinkMapESProducer::produce(), RPCInverseTwinMuxLinkMapESProducer::produce(), RPCInverseOMTFLinkMapESProducer::produce(), EcalNextToDeadChannelESProducer::produce(), RPCInverseLBLinkMapESProducer::produce(), EcalLaserCorrectionService::produce(), EcalLaserCorrectionServiceMC::produce(), HcalDbProducer::produce(), HcalTPGCoderULUT::produce(), CastorDbProducer::produce(), edmtest::ESTestProducerBUsingHost::produce(), and DTGeometryESProducer::produce().
|
inline |
Takes an object from the queue if one is available, or creates one using iMakeFunc. Then, passes the object to iClearFunc, and returns it.
Definition at line 134 of file ReusableObjectHolder.h.
|
inlineprivate |
Definition at line 150 of file ReusableObjectHolder.h.
Referenced by edm::ReusableObjectHolder< edm::ESProductHost >::makeOrGet().
|
inlineprivate |
Definition at line 156 of file ReusableObjectHolder.h.
|
inline |
Tries to get an already created object, if none are available, returns an empty shared_ptr. Use this function in conjunction with add()
Definition at line 111 of file ReusableObjectHolder.h.
|
inlineprivate |
Wraps an object in a shared_ptr<T> with a custom deleter, that hands the wrapped object.
Definition at line 143 of file ReusableObjectHolder.h.
Referenced by edm::ReusableObjectHolder< edm::ESProductHost >::makeOrGet(), and edm::ReusableObjectHolder< edm::ESProductHost >::tryToGet().
|
private |
Definition at line 163 of file ReusableObjectHolder.h.
Referenced by edm::ReusableObjectHolder< edm::ESProductHost >::add(), edm::ReusableObjectHolder< edm::ESProductHost >::addBack(), edm::ReusableObjectHolder< edm::ESProductHost >::makeOrGet(), edm::ReusableObjectHolder< edm::ESProductHost >::tryToGet(), and edm::ReusableObjectHolder< edm::ESProductHost >::~ReusableObjectHolder().
|
private |