ATLAS Offline Software
Loading...
Searching...
No Matches
Athena::RCUObject< T > Class Template Reference

Wrapper object controlled by RCU synchonization. More...

#include <RCUObject.h>

Inheritance diagram for Athena::RCUObject< T >:
Collaboration diagram for Athena::RCUObject< T >:

Public Types

typedef RCURead< T > Read_t
typedef RCUReadQuiesce< T > ReadQuiesce_t
typedef RCUUpdate< T > Update_t
enum  NoObjectEnum { NoObject }
 Value to pass to a constructor to mark that we shouldn't allocate an object. More...

Public Member Functions

template<typename... Args>
 RCUObject (IRCUSvc &svc, Args &&... args)
 Constructor, with RCUSvc.
template<typename... Args>
 RCUObject (size_t nslots, Args &&... args)
 Constructor, with number of slots.
 RCUObject (IRCUSvc &svc, NoObjectEnum)
 Constructor, with RCUSvc.
 RCUObject (RCUObject &&other)
 Move constructor.
 RCUObject (const RCUObject &)=delete
RCUObjectoperator= (const RCUObject &)=delete
RCUObjectoperator= (RCUObject &&)=delete
Read_t reader () const
 Return a reader for this RCUObject.
ReadQuiesce_t readerQuiesce ()
 Return a reader for this RCUObject.
ReadQuiesce_t readerQuiesce (const EventContext &ctx)
 Return a reader for this RCUObject.
ReadQuiesce_t readerQuiesce (const EventContext &&ctx)=delete
Update_t updater ()
 Return an updater for this RCUObject.
Update_t updater (const EventContext &ctx)
 Return an updater for this RCUObject.
Update_t updater (const EventContext &&ctx)=delete
void discard (std::unique_ptr< const T > p)
 Queue an object for later deletion.
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

void discard (lock_t &, std::unique_ptr< const T > p)
 Queue an object for later deletion.
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.
void makeOld (lock_t &lock, size_t garbageSize)
 Make existing pending objects old, if possible.

Private Member Functions

virtual void clearAll (lock_t &) override
 Delete all objects.
virtual bool clearOld (lock_t &, size_t nold) override
 Delete old objects.
void quiescentOol (const EventContext &ctx)
 Out-of-line part of quiescent().

Private Attributes

std::unique_ptr< T > m_objref
 Owning reference to the current object.
std::atomic< const T * > m_obj
 Pointer to the current object.
std::deque< std::unique_ptr< const T > > m_garbage
 List of objects pending cleanup.
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.

Friends

template<class U>
class RCUReadQuiesce
template<class U>
class RCURead
template<class U>
class RCUUpdate

Detailed Description

template<class T>
class Athena::RCUObject< T >

Wrapper object controlled by RCU synchonization.

See the comments at the top of the file for complete comments.

Definition at line 310 of file RCUObject.h.

Member Typedef Documentation

◆ lock_t

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

Definition at line 214 of file RCUObject.h.

◆ mutex_t

typedef std::mutex Athena::IRCUObject::mutex_t
protectedinherited

Definition at line 213 of file RCUObject.h.

◆ Read_t

template<class T>
typedef RCURead<T> Athena::RCUObject< T >::Read_t

Definition at line 314 of file RCUObject.h.

◆ ReadQuiesce_t

template<class T>
typedef RCUReadQuiesce<T> Athena::RCUObject< T >::ReadQuiesce_t

Definition at line 315 of file RCUObject.h.

◆ Update_t

template<class T>
typedef RCUUpdate<T> Athena::RCUObject< T >::Update_t

Definition at line 316 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

◆ RCUObject() [1/5]

template<class T>
template<typename... Args>
Athena::RCUObject< T >::RCUObject ( IRCUSvc & svc,
Args &&... args )

Constructor, with RCUSvc.

Parameters
svcService with which to register.
args...Additional arguments to pass to the T constructor.

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

◆ RCUObject() [2/5]

template<class T>
template<typename... Args>
Athena::RCUObject< T >::RCUObject ( size_t nslots,
Args &&... args )

Constructor, with number of slots.

Parameters
nslotsNumber of event slots.
args...Additional arguments to pass to the T constructor.

◆ RCUObject() [3/5]

template<class T>
Athena::RCUObject< T >::RCUObject ( IRCUSvc & svc,
NoObjectEnum  )

Constructor, with RCUSvc.

Parameters
svcService with which to register.

The service will call quiescent at the end of each event. No current object will be created.

◆ RCUObject() [4/5]

template<class T>
Athena::RCUObject< T >::RCUObject ( RCUObject< T > && other)

Move constructor.

Allow passing these objects via move.

◆ RCUObject() [5/5]

template<class T>
Athena::RCUObject< T >::RCUObject ( const RCUObject< T > & )
delete

Member Function Documentation

◆ clearAll()

template<class T>
virtual void Athena::RCUObject< T >::clearAll ( lock_t & )
overrideprivatevirtual

Delete all objects.

Parameters
Lockobject (external locking).

The caller must be holding the mutex for this object.

Implements Athena::IRCUObject.

◆ clearOld()

template<class T>
virtual bool Athena::RCUObject< T >::clearOld ( lock_t & ,
size_t nold )
overrideprivatevirtual

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.

Implements Athena::IRCUObject.

◆ discard() [1/2]

template<class T>
void Athena::RCUObject< T >::discard ( lock_t & ,
std::unique_ptr< const T > p )
protected

Queue an object for later deletion.

Parameters
lockLock object (external locking).
pThe object to delete.

◆ discard() [2/2]

template<class T>
void Athena::RCUObject< T >::discard ( std::unique_ptr< const T > p)

Queue an object for later deletion.

Parameters
pThe object to delete.

The object p will be queued for deletion once a grace period has passed for all slots. In contrast to using updater, this does not change the current object. It also does not mark the current slot as having completed the grace period (so this can be called by a thread running outside of a slot context).

◆ endGrace()

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

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}
std::unique_ptr< RCUObjectGraceSets > m_graceSets
Holds the current and old grace period bitmasks.
Definition RCUObject.h:292

◆ makeOld()

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

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}
size_t m_nold
Number of old objects.
Definition RCUObject.h:296

◆ mutex()

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

Return the mutex for this object.

◆ operator=() [1/2]

template<class T>
RCUObject & Athena::RCUObject< T >::operator= ( const RCUObject< T > & )
delete

◆ operator=() [2/2]

template<class T>
RCUObject & Athena::RCUObject< T >::operator= ( RCUObject< T > && )
delete

◆ quiescent() [1/2]

void Athena::IRCUObject::quiescent ( )
inherited

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)
inherited

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)
privateinherited

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.
std::atomic< bool > m_dirty
True if there are any objects pending deletion.
Definition RCUObject.h:300
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

◆ reader()

template<class T>
Read_t Athena::RCUObject< T >::reader ( ) const

Return a reader for this RCUObject.

◆ readerQuiesce() [1/3]

template<class T>
ReadQuiesce_t Athena::RCUObject< T >::readerQuiesce ( )

Return a reader for this RCUObject.

When destroyed, this reader will declare the RCUObject as quiescent

This version will read the global event context.

◆ readerQuiesce() [2/3]

template<class T>
ReadQuiesce_t Athena::RCUObject< T >::readerQuiesce ( const EventContext && ctx)
delete

◆ readerQuiesce() [3/3]

template<class T>
ReadQuiesce_t Athena::RCUObject< T >::readerQuiesce ( const EventContext & ctx)

Return a reader for this RCUObject.

When destroyed, this reader will declare the RCUObject as quiescent

Parameters
ctxThe event context (must not be a temporary).

◆ setGrace()

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

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}

◆ updater() [1/3]

template<class T>
Update_t Athena::RCUObject< T >::updater ( )

Return an updater for this RCUObject.

This version will read the global event context.

◆ updater() [2/3]

template<class T>
Update_t Athena::RCUObject< T >::updater ( const EventContext && ctx)
delete

◆ updater() [3/3]

template<class T>
Update_t Athena::RCUObject< T >::updater ( const EventContext & ctx)

Return an updater for this RCUObject.

Parameters
ctxThe event context (must not be a temporary).

◆ RCURead

template<class T>
template<class U>
friend class RCURead
friend

Definition at line 451 of file RCUObject.h.

◆ RCUReadQuiesce

template<class T>
template<class U>
friend class RCUReadQuiesce
friend

Definition at line 450 of file RCUObject.h.

◆ RCUUpdate

template<class T>
template<class U>
friend class RCUUpdate
friend

Definition at line 452 of file RCUObject.h.

Member Data Documentation

◆ m_dirty

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

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_garbage

template<class T>
std::deque<std::unique_ptr<const T> > Athena::RCUObject< T >::m_garbage
private

List of objects pending cleanup.

Definition at line 461 of file RCUObject.h.

◆ m_graceSets

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

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
privateinherited

The mutex for this object.

Definition at line 285 of file RCUObject.h.

◆ m_nold

size_t Athena::IRCUObject::m_nold
privateinherited

Number of old objects.

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

Definition at line 296 of file RCUObject.h.

◆ m_obj

template<class T>
std::atomic<const T*> Athena::RCUObject< T >::m_obj
private

Pointer to the current object.

Definition at line 458 of file RCUObject.h.

◆ m_objref

template<class T>
std::unique_ptr<T> Athena::RCUObject< T >::m_objref
private

Owning reference to the current object.

Definition at line 455 of file RCUObject.h.

◆ m_svc

IRCUSvc* Athena::IRCUObject::m_svc
privateinherited

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 file: