ATLAS Offline Software
Loading...
Searching...
No Matches
Athena::IRCUObject Class Referenceabstract

Base object class for RCU-style synchronization for Athena. More...

#include <RCUObject.h>

Inheritance diagram for Athena::IRCUObject:
Collaboration diagram for Athena::IRCUObject:

Public Types

enum  NoObjectEnum { NoObject }
 Value to pass to a constructor to mark that we shouldn't allocate an object. More...

Public Member Functions

 IRCUObject (IRCUSvc &svc)
 Constructor, with RCUSvc.
 IRCUObject (size_t nslots)
 Constructor, with event slot count.
 IRCUObject (IRCUObject &&other)
 Move constructor.
 IRCUObject (const IRCUObject &)=delete
IRCUObjectoperator= (const IRCUObject &)=delete
IRCUObjectoperator= (IRCUObject &&)=delete
virtual ~IRCUObject ()
 Destructor.
void quiescent ()
 Declare the current event slot of this object to be quiescent.
void quiescent (const EventContext &ctx)
 Declare the event slot ctx of this object to be quiescent.

Protected Types

typedef std::mutex mutex_t
typedef std::unique_lock< mutex_tlock_t

Protected Member Functions

bool endGrace (lock_t &lock, const EventContext &ctx)
 Declare that the grace period for a slot is ending.
void setGrace (lock_t &)
 Declare that all slots are in a grace period.
mutex_tmutex ()
 Return the mutex for this object.
virtual void clearAll (lock_t &)=0
 Delete all objects.
virtual bool clearOld (lock_t &, size_t nold)=0
 Delete old objects.
void makeOld (lock_t &lock, size_t garbageSize)
 Make existing pending objects old, if possible.

Private Member Functions

void quiescentOol (const EventContext &ctx)
 Out-of-line part of quiescent().

Private Attributes

std::mutex m_mutex
 The mutex for this object.
IRCUSvcm_svc
 The service with which we're registered, or null.
std::unique_ptr< RCUObjectGraceSetsm_graceSets
 Holds the current and old grace period bitmasks.
size_t m_nold
 Number of old objects.
std::atomic< bool > m_dirty
 True if there are any objects pending deletion.

Detailed Description

Base object class for RCU-style synchronization for Athena.

Definition at line 146 of file RCUObject.h.

Member Typedef Documentation

◆ lock_t

typedef std::unique_lock<mutex_t> Athena::IRCUObject::lock_t
protected

Definition at line 214 of file RCUObject.h.

◆ mutex_t

typedef std::mutex Athena::IRCUObject::mutex_t
protected

Definition at line 213 of file RCUObject.h.

Member Enumeration Documentation

◆ NoObjectEnum

Value to pass to a constructor to mark that we shouldn't allocate an object.

Enumerator
NoObject 

Definition at line 151 of file RCUObject.h.

Constructor & Destructor Documentation

◆ IRCUObject() [1/4]

Athena::IRCUObject::IRCUObject ( IRCUSvc & svc)

Constructor, with RCUSvc.

Parameters
svcService with which to register.

The service will call quiescent at the end of each event.

Definition at line 72 of file RCUObject.cxx.

73 : m_svc (&svc),
74 m_graceSets (std::make_unique<RCUObjectGraceSets> (svc.getNumSlots())),
75 m_nold(0),
76 m_dirty(false)
77{
78 m_svc->add (this);
79}
IRCUSvc * m_svc
The service with which we're registered, or null.
Definition RCUObject.h:288
std::atomic< bool > m_dirty
True if there are any objects pending deletion.
Definition RCUObject.h:300
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
AthROOTErrorHandlerSvc * svc

◆ IRCUObject() [2/4]

Athena::IRCUObject::IRCUObject ( size_t nslots)

Constructor, with event slot count.

Parameters
nslotsNumber of active event slots.

This version does not register with a service.

Definition at line 88 of file RCUObject.cxx.

89 : m_svc (nullptr),
90 m_graceSets (std::make_unique<RCUObjectGraceSets> (nslots)),
91 m_nold(0),
92 m_dirty(false)
93{
94}

◆ IRCUObject() [3/4]

Athena::IRCUObject::IRCUObject ( IRCUObject && other)

Move constructor.

Allow passing these objects via move.

Definition at line 114 of file RCUObject.cxx.

115 : m_svc (other.m_svc),
116 m_graceSets (std::move (other.m_graceSets)),
117 m_nold (other.m_nold),
118 m_dirty (false)
119{
120 other.m_nold = 0;
121 if (other.m_dirty) {
122 m_dirty = true;
123 }
124 other.m_dirty = false;
125 if (m_svc) {
126 if (m_svc->remove (&other).isFailure()) {
127 std::abort();
128 }
129 other.m_svc = nullptr;
130 m_svc->add (this);
131 }
132}

◆ IRCUObject() [4/4]

Athena::IRCUObject::IRCUObject ( const IRCUObject & )
delete

◆ ~IRCUObject()

Athena::IRCUObject::~IRCUObject ( )
virtual

Destructor.

Remove this object from the service if it has been registered.

Definition at line 102 of file RCUObject.cxx.

103{
104 if (m_svc && m_svc->remove (this).isFailure())
105 std::abort();
106}

Member Function Documentation

◆ clearAll()

virtual void Athena::IRCUObject::clearAll ( lock_t & )
protectedpure virtual

Delete all objects.

Parameters
Lockobject (external locking).

The caller must be holding the mutex for this object.

Implemented in Athena::RCUObject< T >, and Athena::RCUObject< InputRenameMap_t >.

◆ clearOld()

virtual bool Athena::IRCUObject::clearOld ( lock_t & ,
size_t nold )
protectedpure virtual

Delete old objects.

Parameters
Lockobject (external locking).
noldNumber of old objects to delete.

The caller must be holding the mutex for this object. Returns true if there are no more objects pending deletion.

Implemented in Athena::RCUObject< T >, and Athena::RCUObject< InputRenameMap_t >.

◆ endGrace()

bool Athena::IRCUObject::endGrace ( lock_t & lock,
const EventContext & ctx )
protected

Declare that the grace period for a slot is ending.

Parameters
Lockobject (external locking).
ctxEvent context for the slot.
Returns
true if any slot is still in a grace period. false if no slots are in a grace period.

The caller must be holding the mutex for this object.

Parameters
lockLock object (external locking).
ctxEvent context for the slot.
Returns
true if any slot is still in a grace period. false if no slots are in a grace period.

The caller must be holding the mutex for this object.

Definition at line 165 of file RCUObject.cxx.

166{
167 return ::endGrace (ctx, m_graceSets->m_grace);
168}

◆ makeOld()

void Athena::IRCUObject::makeOld ( lock_t & lock,
size_t garbageSize )
protected

Make existing pending objects old, if possible.

Parameters
lockLock object (external locking).
garbageSizePresent number of objects pending deletion.

A new object is about to be added to the list of objects pending deletion. If there are any existing pending objects and there are no existing old objects, make the current pending objects old.

Definition at line 193 of file RCUObject.cxx.

194{
195 if (garbageSize && m_nold == 0) {
196 m_graceSets->m_oldGrace = m_graceSets->m_grace;
197 m_nold = garbageSize;
198 }
199}

◆ mutex()

mutex_t & Athena::IRCUObject::mutex ( )
protected

Return the mutex for this object.

◆ operator=() [1/2]

IRCUObject & Athena::IRCUObject::operator= ( const IRCUObject & )
delete

◆ operator=() [2/2]

IRCUObject & Athena::IRCUObject::operator= ( IRCUObject && )
delete

◆ quiescent() [1/2]

void Athena::IRCUObject::quiescent ( )

Declare the current event slot of this object to be quiescent.

This will take out a lock and possibly trigger object cleanup.

◆ quiescent() [2/2]

void Athena::IRCUObject::quiescent ( const EventContext & ctx)

Declare the event slot ctx of this object to be quiescent.

Parameters
ctxThe event context.

This will take out a lock and possibly trigger object cleanup.

◆ quiescentOol()

void Athena::IRCUObject::quiescentOol ( const EventContext & ctx)
private

Out-of-line part of quiescent().

Definition at line 138 of file RCUObject.cxx.

139{
140 // We get here after the dirty flag has already been checked.
141 lock_t g (m_mutex);
142 if (!::endGrace(ctx, m_graceSets->m_grace)) {
143 clearAll(g);
144 m_nold = 0;
145 m_dirty = false;
146 }
147 else if (m_nold > 0 && !::endGrace(ctx, m_graceSets->m_oldGrace)) {
148 if (clearOld(g, m_nold)) {
149 m_dirty = false;
150 }
151 m_nold = 0;
152 }
153}
virtual void clearAll(lock_t &)=0
Delete all objects.
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.
std::mutex m_mutex
The mutex for this object.
Definition RCUObject.h:285

◆ setGrace()

void Athena::IRCUObject::setGrace ( lock_t & )
protected

Declare that all slots are in a grace period.

Parameters
Lockobject (external locking).

The caller must be holding the mutex for this object.

Definition at line 177 of file RCUObject.cxx.

178{
179 m_graceSets->m_grace.set();
180 if (!m_dirty) m_dirty = true;
181}

Member Data Documentation

◆ m_dirty

std::atomic<bool> Athena::IRCUObject::m_dirty
private

True if there are any objects pending deletion.

Used to avoid taking the lock in quiescent() if there's nothing to do.

Definition at line 300 of file RCUObject.h.

◆ m_graceSets

std::unique_ptr<RCUObjectGraceSets> Athena::IRCUObject::m_graceSets
private

Holds the current and old grace period bitmasks.

Split off into a separate object to reduce header dependencies.

Definition at line 292 of file RCUObject.h.

◆ m_mutex

std::mutex Athena::IRCUObject::m_mutex
private

The mutex for this object.

Definition at line 285 of file RCUObject.h.

◆ m_nold

size_t Athena::IRCUObject::m_nold
private

Number of old objects.

The objects at the end of the garbage list are old.

Definition at line 296 of file RCUObject.h.

◆ m_svc

IRCUSvc* Athena::IRCUObject::m_svc
private

The service with which we're registered, or null.

Definition at line 288 of file RCUObject.h.


The documentation for this class was generated from the following files: