#include <ReusableObjectHolder.h>
Public Member Functions | |
void | add (std::unique_ptr< T > iItem) |
template<typename F > | |
std::shared_ptr< T > | makeOrGet (F iFunc) |
If there isn't an object already available, creates a new one using iFunc. 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 () | |
Private Member Functions | |
void | addBack (T *iItem) |
Private Attributes | |
tbb::concurrent_queue< T * > | 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 it to call makeOrGetAndClear An example use would be
If you always want to set the values you can use makeOrGet
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
Definition at line 76 of file ReusableObjectHolder.h.
|
inline |
Definition at line 78 of file ReusableObjectHolder.h.
|
inline |
Definition at line 79 of file ReusableObjectHolder.h.
|
inline |
Definition at line 83 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 94 of file ReusableObjectHolder.h.
Referenced by edm::ReusableObjectHolder< edm::ESProductHost >::makeOrGet(), edm::ReusableObjectHolder< edm::ESProductHost >::makeOrGetAndClear(), and counter.Counter::register().
|
inlineprivate |
Definition at line 139 of file ReusableObjectHolder.h.
|
inline |
If there isn't an object already available, creates a new one using iFunc.
Definition at line 117 of file ReusableObjectHolder.h.
Referenced by CastorDbProducer::produce(), EcalSeverityLevelESProducer::produce(), EcalLaserCorrectionService::produce(), RPCInverseTwinMuxLinkMapESProducer::produce(), RPCInverseCPPFLinkMapESProducer::produce(), RPCInverseLBLinkMapESProducer::produce(), RPCInverseOMTFLinkMapESProducer::produce(), EcalNextToDeadChannelESProducer::produce(), HcalDbProducer::produce(), DTGeometryESModule::produce(), HcalTPGCoderULUT::produce(), CSCGeometryESModule::produce(), DTGeometryESProducer::produce(), FFTJetLookupTableESProducer< CT >::produce(), and FFTJetCorrectionESProducer< CT >::produce().
|
inline |
If there is an object already available, passes the object to iClearFunc and then returns the object. If there is not an object already available, creates a new one using iMakeFunc
Definition at line 129 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 103 of file ReusableObjectHolder.h.
Referenced by edm::ReusableObjectHolder< edm::ESProductHost >::makeOrGet(), and edm::ReusableObjectHolder< edm::ESProductHost >::makeOrGetAndClear().
|
private |
Definition at line 144 of file ReusableObjectHolder.h.
Referenced by edm::ReusableObjectHolder< edm::ESProductHost >::add(), edm::ReusableObjectHolder< edm::ESProductHost >::addBack(), edm::ReusableObjectHolder< edm::ESProductHost >::tryToGet(), and edm::ReusableObjectHolder< edm::ESProductHost >::~ReusableObjectHolder().
|
private |