ATLAS Offline Software
Loading...
Searching...
No Matches
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*/
116
117
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
131namespace Athena {
132
133
134class IRCUSvc;
135template <class T> class RCURead;
136template <class T> class RCUReadQuiesce;
137template <class T> class RCUUpdate;
138
139
140struct RCUObjectGraceSets;
141
142
147{
148public:
152
153
160 IRCUObject (IRCUSvc& svc);
161
162
169 IRCUObject (size_t nslots);
170
171
177 IRCUObject (IRCUObject&& other);
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;
185
186
192 virtual ~IRCUObject();
193
194
200 void quiescent();
201
202
209 void quiescent (const EventContext& ctx);
210
211
212protected:
213 typedef std::mutex mutex_t;
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
277private:
281 void quiescentOol (const EventContext& ctx);
282
283
285 std::mutex m_mutex;
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
309template <class T>
311 : public IRCUObject
312{
313public:
317
318
326 template <typename... Args>
327 RCUObject (IRCUSvc& svc, Args&&... 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
419protected:
425 void discard (lock_t& /*lock*/, std::unique_ptr<const T> p);
426
427
428private:
435 virtual void clearAll (lock_t& /*lock*/) override;
436
437
446 virtual bool clearOld (lock_t& /*lock*/, size_t nold) override;
447
448
449private:
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
470template <class T>
472{
473public:
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
496private:
498 const T* m_obj;
499};
500
501
509template <class T>
511 : public RCURead<T>
512{
513public:
521
522
528 RCUReadQuiesce (RCUObject<T>& rcuobj, const EventContext& ctx);
529 RCUReadQuiesce (RCUObject<T>& rcuobj, const EventContext&& ctx) = delete;
530
531
538
539
540private:
543
545 const EventContext& m_ctx;
546};
547
548
554template <class T>
556{
557public:
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
595private:
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
Base object class for RCU-style synchronization for Athena.
Definition RCUObject.h:147
std::mutex mutex_t
Definition RCUObject.h:213
virtual void clearAll(lock_t &)=0
Delete all objects.
IRCUObject(const IRCUObject &)=delete
void setGrace(lock_t &)
Declare that all slots are in a grace period.
void makeOld(lock_t &lock, size_t garbageSize)
Make existing pending objects old, if possible.
IRCUSvc * m_svc
The service with which we're registered, or null.
Definition RCUObject.h:288
void quiescent()
Declare the current event slot of this object to be quiescent.
IRCUObject & operator=(const IRCUObject &)=delete
std::atomic< bool > m_dirty
True if there are any objects pending deletion.
Definition RCUObject.h:300
IRCUObject(IRCUSvc &svc)
Constructor, with RCUSvc.
Definition RCUObject.cxx:72
virtual bool clearOld(lock_t &, size_t nold)=0
Delete old objects.
std::unique_lock< mutex_t > lock_t
Definition RCUObject.h:214
bool endGrace(lock_t &lock, const EventContext &ctx)
Declare that the grace period for a slot is ending.
NoObjectEnum
Value to pass to a constructor to mark that we shouldn't allocate an object.
Definition RCUObject.h:151
std::mutex m_mutex
The mutex for this object.
Definition RCUObject.h:285
void quiescent(const EventContext &ctx)
Declare the event slot ctx of this object to be quiescent.
void quiescentOol(const EventContext &ctx)
Out-of-line part of quiescent().
mutex_t & mutex()
Return the mutex for this object.
virtual ~IRCUObject()
Destructor.
std::unique_ptr< RCUObjectGraceSets > m_graceSets
Holds the current and old grace period bitmasks.
Definition RCUObject.h:292
size_t m_nold
Number of old objects.
Definition RCUObject.h:296
Interface for RCU service.
Definition IRCUSvc.h:40
Wrapper object controlled by RCU synchonization.
Definition RCUObject.h:312
Update_t updater(const EventContext &&ctx)=delete
RCUUpdate< InputRenameMap_t > Update_t
Definition RCUObject.h:316
RCUObject(IRCUSvc &svc, NoObjectEnum)
Constructor, with RCUSvc.
RCUObject(const RCUObject &)=delete
Read_t reader() const
Return a reader for this RCUObject.
RCUReadQuiesce< InputRenameMap_t > ReadQuiesce_t
Definition RCUObject.h:315
RCUObject(size_t nslots, Args &&... args)
Constructor, with number of slots.
std::atomic< const InputRenameMap_t * > m_obj
Definition RCUObject.h:458
ReadQuiesce_t readerQuiesce()
Return a reader for this RCUObject.
void discard(lock_t &, std::unique_ptr< const T > p)
Queue an object for later deletion.
std::unique_ptr< InputRenameMap_t > m_objref
Definition RCUObject.h:455
ReadQuiesce_t readerQuiesce(const EventContext &ctx)
Return a reader for this RCUObject.
Update_t updater(const EventContext &ctx)
Return an updater for this RCUObject.
Update_t updater()
Return an updater for this RCUObject.
std::deque< std::unique_ptr< const InputRenameMap_t > > m_garbage
Definition RCUObject.h:461
void discard(std::unique_ptr< const T > p)
Queue an object for later deletion.
RCUObject & operator=(const RCUObject &)=delete
RCURead< InputRenameMap_t > Read_t
Definition RCUObject.h:314
RCUObject(IRCUSvc &svc, Args &&... args)
Constructor, with RCUSvc.
ReadQuiesce_t readerQuiesce(const EventContext &&ctx)=delete
virtual void clearAll(lock_t &) override
Delete all objects.
virtual bool clearOld(lock_t &, size_t nold) override
Delete old objects.
RCUObject(RCUObject &&other)
Move constructor.
Helper to read data from a RCUObject.
Definition RCUObject.h:512
const EventContext & m_ctx
The current event context.
Definition RCUObject.h:545
RCUObject< T > & m_rcuobj
The RCUObject we're referencing.
Definition RCUObject.h:542
RCUReadQuiesce(RCUObject< T > &rcuobj)
Constructor.
RCUReadQuiesce(RCUObject< T > &rcuobj, const EventContext &ctx)
Constructor.
~RCUReadQuiesce()
Destructor.
RCUReadQuiesce(RCUObject< T > &rcuobj, const EventContext &&ctx)=delete
Helper to read data from a RCUObject.
Definition RCUObject.h:472
const T * operator->() const
Access data.
const T * m_obj
The data object we're reading.
Definition RCUObject.h:498
RCURead(const RCUObject< T > &rcuobj)
Constructor.
const T & operator*() const
Access data.
Helper to update data in a RCUObject.
Definition RCUObject.h:556
RCUUpdate(RCUObject< T > &rcuobj)
Constructor.
const T * operator->() const
Access data.
const EventContext & m_ctx
The event context.
Definition RCUObject.h:600
RCUObject< T > & m_rcuobj
The object we're referencing.
Definition RCUObject.h:597
RCUUpdate(RCUObject< T > &rcuobj, const EventContext &ctx)
Constructor.
void update(std::unique_ptr< T > ptr)
Publish a new version of the data object.
const T & operator*() const
Access data.
std::unique_lock< std::mutex > m_g
Lock for synchonization.
Definition RCUObject.h:603
RCUUpdate(RCUObject< T > &rcuobj, const EventContext &&ctx)=delete
Some weak symbol referencing magic... These are declared in AthenaKernel/getMessageSvc....