2 Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
8 * @file AthenaKernel/RecyclableDataObject.icc
9 * @author scott snyder <snyder@bnl.gov>
11 * @brief Helper for recycling objects from event to event.
20 * @param queue Queue on which this object will be entered when it is released.
21 * @param args... Additional arguments to pass to the @c DOBJ constructor.
24 template <typename... ARGS>
25 RecyclableDataObject<DOBJ>::RecyclableDataObject (std::shared_ptr<queue_t> queue, ARGS&&... args)
26 : DOBJ (std::forward<ARGS>(args)...),
29 // Bump reference count by one so that these objects won't be deleted by StoreGate.
35 * @brief DataObject release method.
37 * This overrides the @c release() method of @c DataObject.
38 * Once the reference count falls back to 1 (meaning that the object is no longer
39 * referenced from StoreGate), we recycle the object back to the queue.
42 unsigned long RecyclableDataObject<DOBJ>::release()
44 unsigned long cnt = DOBJ::release();
57 RecyclableDataQueue<DOBJ>::RecyclableDataQueue()
58 : m_queue (std::make_shared<queue_t>())
64 * @brief Get an object, either a new one or one recycled from a previous event.
65 * @param args... Arguments to pass to the @c DOBJ constructor if we make a new one.
68 template <typename... ARGS>
69 DOBJ* RecyclableDataQueue<DOBJ>::get (ARGS&&... args)
72 if (m_queue->try_pop (obj)) {
75 return new RecyclableDataObject<DOBJ> (m_queue, std::forward<ARGS>(args)...);
82 * Free all objects in the queue.
85 RecyclableDataQueue<DOBJ>::~RecyclableDataQueue()
88 while (m_queue->try_pop (obj)) {