ATLAS Offline Software
RCUObject.h
Go to the documentation of this file.
1 // This file's extension implies that it's C, but it's really -*- C++ -*-.
2 
3 /*
4  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
5 */
118 #ifndef ATHENAKERNEL_RCUOBJECT_H
119 #define ATHENAKERNEL_RCUOBJECT_H
120 
121 
122 #include "GaudiKernel/ThreadLocalContext.h"
123 #include "GaudiKernel/EventContext.h"
124 #include <atomic>
125 #include <deque>
126 #include <vector>
127 #include <memory>
128 #include <mutex>
129 
130 
131 namespace Athena {
132 
133 
134 class IRCUSvc;
135 template <class T> class RCURead;
136 template <class T> class RCUReadQuiesce;
137 template <class T> class RCUUpdate;
138 
139 
140 struct RCUObjectGraceSets;
141 
142 
147 {
148 public:
152 
153 
161 
162 
169  IRCUObject (size_t nslots);
170 
171 
178 
179 
180  // Make these explicit to prevent warnings from coverity.
181  // (copy/assign are implicitly deleted due to the mutex member.)
182  IRCUObject (const IRCUObject&) = delete;
183  IRCUObject& operator= (const IRCUObject&) = delete;
185 
186 
192  virtual ~IRCUObject();
193 
194 
200  void quiescent();
201 
202 
209  void quiescent (const EventContext& ctx);
210 
211 
212 protected:
214  typedef std::unique_lock<mutex_t> lock_t;
215 
216 
226  bool endGrace (lock_t& lock,
227  const EventContext& ctx);
228 
229 
236  void setGrace (lock_t& /*lock*/);
237 
238 
243 
244 
251  virtual void clearAll (lock_t& /*lock*/) = 0;
252 
253 
262  virtual bool clearOld (lock_t& /*lock*/, size_t nold) = 0;
263 
264 
274  void makeOld (lock_t& lock, size_t garbageSize);
275 
276 
277 private:
281  void quiescentOol (const EventContext& ctx);
282 
283 
286 
289 
292  std::unique_ptr<RCUObjectGraceSets> m_graceSets;
293 
296  size_t m_nold;
297 
300  std::atomic<bool> m_dirty;
301 };
302 
303 
309 template <class T>
311  : public IRCUObject
312 {
313 public:
317 
318 
326  template <typename... Args>
328 
329 
335  template <typename... Args>
336  RCUObject (size_t nslots, Args&&... args);
337 
338 
347 
348 
355 
356 
357  // Make these explicit to prevent warnings from coverity.
358  // (copy/assign are implicitly deleted due to the mutex member.)
359  RCUObject (const RCUObject&) = delete;
360  RCUObject& operator= (const RCUObject&) = delete;
362 
363 
367  Read_t reader() const;
368 
369 
378 
379 
386  ReadQuiesce_t readerQuiesce (const EventContext& ctx);
387  ReadQuiesce_t readerQuiesce (const EventContext&& ctx) = delete;
388 
389 
396 
397 
402  Update_t updater (const EventContext& ctx);
403  Update_t updater (const EventContext&& ctx) = delete;
404 
405 
416  void discard (std::unique_ptr<const T> p);
417 
418 
419 protected:
425  void discard (lock_t& /*lock*/, std::unique_ptr<const T> p);
426 
427 
428 private:
435  virtual void clearAll (lock_t& /*lock*/) override;
436 
437 
446  virtual bool clearOld (lock_t& /*lock*/, size_t nold) override;
447 
448 
449 private:
450  template <class U> friend class RCUReadQuiesce;
451  template <class U> friend class RCURead;
452  template <class U> friend class RCUUpdate;
453 
455  std::unique_ptr<T> m_objref;
456 
458  std::atomic<const T*> m_obj;
459 
461  std::deque<std::unique_ptr<const T> > m_garbage;
462 };
463 
464 
470 template <class T>
471 class RCURead
472 {
473 public:
478  RCURead (const RCUObject<T>& rcuobj);
479 
480 
481  operator bool() const { return m_obj != nullptr; }
482 
483 
487  const T& operator*() const;
488 
489 
493  const T* operator->() const;
494 
495 
496 private:
498  const T* m_obj;
499 };
500 
501 
509 template <class T>
510 class RCUReadQuiesce
511  : public RCURead<T>
512 {
513 public:
521 
522 
528  RCUReadQuiesce (RCUObject<T>& rcuobj, const EventContext& ctx);
529  RCUReadQuiesce (RCUObject<T>& rcuobj, const EventContext&& ctx) = delete;
530 
531 
538 
539 
540 private:
543 
545  const EventContext& m_ctx;
546 };
547 
548 
554 template <class T>
555 class RCUUpdate
556 {
557 public:
565 
566 
572  RCUUpdate (RCUObject<T>& rcuobj, const EventContext& ctx);
573  RCUUpdate (RCUObject<T>& rcuobj, const EventContext&& ctx) = delete;
574 
575 
579  const T& operator*() const;
580 
581 
585  const T* operator->() const;
586 
587 
592  void update (std::unique_ptr<T> ptr);
593 
594 
595 private:
598 
600  const EventContext& m_ctx;
601 
603  std::unique_lock<std::mutex> m_g;
604 };
605 
606 
607 } // namespace Athena
608 
609 
611 
612 
613 #endif // not ATHENAKERNEL_RCUOBJECT_H
Athena::IRCUObject::quiescentOol
void quiescentOol(const EventContext &ctx)
Out-of-line part of quiescent().
Definition: RCUObject.cxx:138
Athena::RCUObject
Wrapper object controlled by RCU synchonization.
Definition: RCUObject.h:312
Athena::IRCUObject::m_dirty
std::atomic< bool > m_dirty
True if there are any objects pending deletion.
Definition: RCUObject.h:300
Athena::RCUObject::readerQuiesce
ReadQuiesce_t readerQuiesce()
Return a reader for this RCUObject.
Athena::RCUObject::RCUObject
RCUObject(IRCUSvc &svc, NoObjectEnum)
Constructor, with RCUSvc.
Athena::RCUUpdate::operator->
const T * operator->() const
Access data.
Athena::IRCUObject::IRCUObject
IRCUObject(IRCUSvc &svc)
Constructor, with RCUSvc.
Definition: RCUObject.cxx:72
Athena::RCUUpdate::update
void update(std::unique_ptr< T > ptr)
Publish a new version of the data object.
Athena::RCURead::operator*
const T & operator*() const
Access data.
Athena::RCUUpdate
Helper to update data in a RCUObject.
Definition: RCUObject.h:137
Athena::RCUObject::reader
Read_t reader() const
Return a reader for this RCUObject.
Athena::RCUObject::m_objref
std::unique_ptr< T > m_objref
Owning reference to the current object.
Definition: RCUObject.h:455
python.CaloAddPedShiftConfig.args
args
Definition: CaloAddPedShiftConfig.py:47
Athena::RCUObject::readerQuiesce
ReadQuiesce_t readerQuiesce(const EventContext &ctx)
Return a reader for this RCUObject.
Athena::IRCUObject::m_svc
IRCUSvc * m_svc
The service with which we're registered, or null.
Definition: RCUObject.h:288
BeamSpot::mutex
std::mutex mutex
Definition: InDetBeamSpotVertex.cxx:18
Athena::RCUObject::Update_t
RCUUpdate< T > Update_t
Definition: RCUObject.h:316
Athena::IRCUObject::clearOld
virtual bool clearOld(lock_t &, size_t nold)=0
Delete old objects.
Athena::RCUObject::clearAll
virtual void clearAll(lock_t &) override
Delete all objects.
Athena::RCURead::RCURead
RCURead(const RCUObject< T > &rcuobj)
Constructor.
Athena::RCUObjectGraceSets
Definition: RCUObject.cxx:50
Athena::IRCUObject::quiescent
void quiescent(const EventContext &ctx)
Declare the event slot ctx of this object to be quiescent.
Athena::IRCUObject::~IRCUObject
virtual ~IRCUObject()
Destructor.
Definition: RCUObject.cxx:102
Athena::RCUReadQuiesce::RCUReadQuiesce
RCUReadQuiesce(RCUObject< T > &rcuobj, const EventContext &&ctx)=delete
Athena::RCUReadQuiesce::RCUReadQuiesce
RCUReadQuiesce(RCUObject< T > &rcuobj, const EventContext &ctx)
Constructor.
Athena::RCUObject::Read_t
RCURead< T > Read_t
Definition: RCUObject.h:314
Athena::RCUReadQuiesce::m_ctx
const EventContext & m_ctx
The current event context.
Definition: RCUObject.h:545
Athena::IRCUObject::mutex
mutex_t & mutex()
Return the mutex for this object.
python.RatesEmulationExample.lock
lock
Definition: RatesEmulationExample.py:148
Athena::RCUObject::ReadQuiesce_t
RCUReadQuiesce< T > ReadQuiesce_t
Definition: RCUObject.h:315
Athena::IRCUObject::m_nold
size_t m_nold
Number of old objects.
Definition: RCUObject.h:296
Athena::RCUObject::updater
Update_t updater(const EventContext &ctx)
Return an updater for this RCUObject.
dbg::ptr
void * ptr(T *p)
Definition: SGImplSvc.cxx:74
Args
Definition: test_lwtnn_fastgraph.cxx:12
Athena::RCUObject::m_garbage
std::deque< std::unique_ptr< const T > > m_garbage
List of objects pending cleanup.
Definition: RCUObject.h:461
Athena::IRCUObject::IRCUObject
IRCUObject(const IRCUObject &)=delete
Athena::RCUObject::clearOld
virtual bool clearOld(lock_t &, size_t nold) override
Delete old objects.
Athena::RCUObject::m_obj
std::atomic< const T * > m_obj
Pointer to the current object.
Definition: RCUObject.h:458
Athena::RCUUpdate::m_g
std::unique_lock< std::mutex > m_g
Lock for synchonization.
Definition: RCUObject.h:603
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:209
Athena::RCUReadQuiesce::m_rcuobj
RCUObject< T > & m_rcuobj
The RCUObject we're referencing.
Definition: RCUObject.h:542
Athena::RCUObject::RCUObject
RCUObject(const RCUObject &)=delete
Athena::RCUReadQuiesce::~RCUReadQuiesce
~RCUReadQuiesce()
Destructor.
Athena
Some weak symbol referencing magic...
Definition: AthLegacySequence.h:21
Athena::RCUObject::discard
void discard(std::unique_ptr< const T > p)
Queue an object for later deletion.
Athena::RCUUpdate::RCUUpdate
RCUUpdate(RCUObject< T > &rcuobj, const EventContext &ctx)
Constructor.
Athena::RCURead
Helper to read data from a RCUObject.
Definition: RCUObject.h:135
Athena::IRCUObject::makeOld
void makeOld(lock_t &lock, size_t garbageSize)
Make existing pending objects old, if possible.
Definition: RCUObject.cxx:193
Athena::IRCUSvc
Interface for RCU service.
Definition: IRCUSvc.h:40
Athena::RCUObject::discard
void discard(lock_t &, std::unique_ptr< const T > p)
Queue an object for later deletion.
Athena::IRCUObject::m_mutex
std::mutex m_mutex
The mutex for this object.
Definition: RCUObject.h:285
Athena::IRCUObject::quiescent
void quiescent()
Declare the current event slot of this object to be quiescent.
Athena::IRCUObject::lock_t
std::unique_lock< mutex_t > lock_t
Definition: RCUObject.h:214
Handler::svc
AthROOTErrorHandlerSvc * svc
Definition: AthROOTErrorHandlerSvc.cxx:10
Athena::RCUUpdate::m_rcuobj
RCUObject< T > & m_rcuobj
The object we're referencing.
Definition: RCUObject.h:597
Athena::RCURead::operator->
const T * operator->() const
Access data.
Athena::IRCUObject::operator=
IRCUObject & operator=(const IRCUObject &)=delete
Athena::RCUUpdate::RCUUpdate
RCUUpdate(RCUObject< T > &rcuobj)
Constructor.
Athena::IRCUObject::NoObject
@ NoObject
Definition: RCUObject.h:151
Athena::RCUObject::RCUObject
RCUObject(RCUObject &&other)
Move constructor.
Athena::RCUUpdate::RCUUpdate
RCUUpdate(RCUObject< T > &rcuobj, const EventContext &&ctx)=delete
Athena::IRCUObject::setGrace
void setGrace(lock_t &)
Declare that all slots are in a grace period.
Definition: RCUObject.cxx:177
WriteCalibToCool.nold
nold
Definition: WriteCalibToCool.py:464
Athena::RCURead::m_obj
const T * m_obj
The data object we're reading.
Definition: RCUObject.h:498
Athena::RCUObject::readerQuiesce
ReadQuiesce_t readerQuiesce(const EventContext &&ctx)=delete
Athena::RCUObject::updater
Update_t updater()
Return an updater for this RCUObject.
Athena::RCUUpdate::m_ctx
const EventContext & m_ctx
The event context.
Definition: RCUObject.h:600
Athena::RCUObject::updater
Update_t updater(const EventContext &&ctx)=delete
Athena::IRCUObject
Base object class for RCU-style synchronization for Athena.
Definition: RCUObject.h:147
Athena::RCUObject::RCUObject
RCUObject(size_t nslots, Args &&... args)
Constructor, with number of slots.
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
Athena::IRCUObject::clearAll
virtual void clearAll(lock_t &)=0
Delete all objects.
Athena::IRCUObject::endGrace
bool endGrace(lock_t &lock, const EventContext &ctx)
Declare that the grace period for a slot is ending.
Definition: RCUObject.cxx:165
Athena::RCUObject::operator=
RCUObject & operator=(const RCUObject &)=delete
xAOD::bool
setBGCode setTAP setLVL2ErrorBits bool
Definition: TrigDecision_v1.cxx:60
Athena::IRCUObject::mutex_t
std::mutex mutex_t
Definition: RCUObject.h:213
Athena::RCUReadQuiesce::RCUReadQuiesce
RCUReadQuiesce(RCUObject< T > &rcuobj)
Constructor.
Athena::RCUReadQuiesce
Helper to read data from a RCUObject.
Definition: RCUObject.h:136
Athena::RCUUpdate::operator*
const T & operator*() const
Access data.
RCUObject.icc
Athena::IRCUObject::m_graceSets
std::unique_ptr< RCUObjectGraceSets > m_graceSets
Holds the current and old grace period bitmasks.
Definition: RCUObject.h:292
Athena::IRCUObject::NoObjectEnum
NoObjectEnum
Value to pass to a constructor to mark that we shouldn't allocate an object.
Definition: RCUObject.h:151
Athena::RCUObject::RCUObject
RCUObject(IRCUSvc &svc, Args &&... args)
Constructor, with RCUSvc.