2  * Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration.
 
    5  * @file CxxUtils/SimpleUpdater.icc
 
    6  * @author scott snyder <snyder@bnl.gov>
 
    8  * @brief Simple (non-deleting) Updater implementation.
 
   16  * @brief Move constructor.
 
   19 SimpleUpdater<T>::SimpleUpdater (SimpleUpdater&& other)
 
   20   : m_obj (static_cast<const T*> (other.m_obj)),
 
   21     m_objs (std::move (other.m_objs))
 
   27  * @brief Return a reference to the current object.
 
   31 const T& SimpleUpdater<T>::get() const
 
   38  * @brief Install a new object.
 
   39  * @param p The new object to install.
 
   40  * @param ctx Current execution context.
 
   42  * The existing object should not be deleted until it can no longer
 
   43  * be referenced by any thread.
 
   46 void SimpleUpdater<T>::update (std::unique_ptr<T> p, const Context_t&)
 
   48   m_objs.push_back (std::move (p));
 
   49   m_obj = m_objs.back().get();
 
   54  * @brief Queue an object for later deletion.
 
   55  * @param p The object to delete.
 
   57  * The object @c p will be queued for deletion once a grace period
 
   58  * has passed for all slots.  In contrast to using @c update,
 
   59  * this does not change the current object.
 
   62 void SimpleUpdater<T>::discard (std::unique_ptr<T> p)
 
   64   m_objs.push_back (std::move (p));
 
   69  * @brief Mark that an event slot is not referencing this object.
 
   71  * A no-op for @c SimpleUpdater.
 
   74 void SimpleUpdater<T>::quiescent (const Context_t&)
 
   80  * @brief Delete all objects we're managing except for the current one.
 
   82  * This is NOT concurrency-safe.  No other threads may be accessing
 
   83  * the objects managed here.
 
   86 void SimpleUpdater<T>::clean()
 
   89   auto it = std::remove_if (m_objs.begin(), m_objs.end(),
 
   90                             [&] (const std::unique_ptr<T>& p) { return p.get() != obj; });
 
   91   m_objs.erase (it, m_objs.end());
 
   96  * @brief Swap this object with another.
 
   97  * @param other The other object with which to swap.
 
   99  * This operation is NOT concurrency-safe.  No other threads may be accessing
 
  100  * either container during this operation.
 
  103 void SimpleUpdater<T>::swap (SimpleUpdater& other)
 
  105   const T* tmp = m_obj.load (std::memory_order_relaxed);
 
  106   m_obj.store (other.m_obj.load(std::memory_order_relaxed), std::memory_order_relaxed);
 
  107   other.m_obj.store (tmp, std::memory_order_relaxed);
 
  109   m_objs.swap (other.m_objs);
 
  114  * @brief Return the current event context.
 
  117 const typename SimpleUpdater<T>::Context_t SimpleUpdater<T>::defaultContext()
 
  123 } // namespace CxxUtils