ATLAS Offline Software
Public Types | Public Member Functions | Protected Types | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
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. More...
 
 IRCUObject (size_t nslots)
 Constructor, with event slot count. More...
 
 IRCUObject (IRCUObject &&other)
 Move constructor. More...
 
 IRCUObject (const IRCUObject &)=delete
 
IRCUObjectoperator= (const IRCUObject &)=delete
 
IRCUObjectoperator= (IRCUObject &&)=delete
 
virtual ~IRCUObject ()
 Destructor. More...
 
void quiescent ()
 Declare the current event slot of this object to be quiescent. More...
 
void quiescent (const EventContext &ctx)
 Declare the event slot ctx of this object to be quiescent. More...
 

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. More...
 
void setGrace (lock_t &)
 Declare that all slots are in a grace period. More...
 
mutex_tmutex ()
 Return the mutex for this object. More...
 
virtual void clearAll (lock_t &)=0
 Delete all objects. More...
 
virtual bool clearOld (lock_t &, size_t nold)=0
 Delete old objects. More...
 
void makeOld (lock_t &lock, size_t garbageSize)
 Make existing pending objects old, if possible. More...
 

Private Member Functions

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

Private Attributes

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

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.

151 { NoObject };

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 }

◆ 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 >.

◆ 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 >.

◆ 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 }

◆ 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:
Athena::IRCUObject::m_dirty
std::atomic< bool > m_dirty
True if there are any objects pending deletion.
Definition: RCUObject.h:300
Athena::IRCUObject::m_svc
IRCUSvc * m_svc
The service with which we're registered, or null.
Definition: RCUObject.h:288
Athena::IRCUObject::clearOld
virtual bool clearOld(lock_t &, size_t nold)=0
Delete old objects.
Athena::IRCUSvc::add
virtual void add(IRCUObject *obj)=0
Add a new RCU object to the set being managed.
Athena::IRCUObject::m_nold
size_t m_nold
Number of old objects.
Definition: RCUObject.h:296
python.CaloCondTools.g
g
Definition: CaloCondTools.py:15
Athena::IRCUObject::m_mutex
std::mutex m_mutex
The mutex for this object.
Definition: RCUObject.h:285
Athena::IRCUObject::lock_t
std::unique_lock< mutex_t > lock_t
Definition: RCUObject.h:214
Handler::svc
AthROOTErrorHandlerSvc * svc
Definition: AthROOTErrorHandlerSvc.cxx:10
Athena::IRCUSvc::remove
virtual StatusCode remove(IRCUObject *obj)=0
Remove an object from the service.
Athena::IRCUObject::NoObject
@ NoObject
Definition: RCUObject.h:151
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::IRCUObject::m_graceSets
std::unique_ptr< RCUObjectGraceSets > m_graceSets
Holds the current and old grace period bitmasks.
Definition: RCUObject.h:292