The Pedigree Project 0.1
Classes | Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
TimerHandlerRegistry Class Reference

#include <TimerHandlerRegistry.h>

+ Collaboration diagram for TimerHandlerRegistry:

Classes

struct  ActiveDispatch
 
struct  DispatchCleanup
 
struct  HandlerSlot
 

Public Member Functions

bool registerHandler (TimerHandler *handler)
 
bool armHandler (TimerHandler *handler, uint64_t deadline, uint64_t now)
 
uint64_t nextDeadline () const
 
bool unregisterHandler (TimerHandler *handler)
 
bool dispatch (uint64_t delta, TimerHandler *onlyHandler=nullptr)
 
bool dispatchDue (uint64_t now)
 
void reset ()
 

Private Types

enum class  SlotMode : size_t {
  Empty = 0 , Enabled , Draining , Deferred ,
  Retiring
}
 

Private Member Functions

bool retireSlot (HandlerSlot &slot, size_t expectedPublication, TimerHandler *expectedHandler)
 
bool publishDispatch (DispatchCleanup &cleanup)
 
bool unpublishDispatch (DispatchCleanup &cleanup, bool required)
 
bool hasActiveDispatch (HandlerSlot &slot) const
 
bool findCurrentDispatch (void *owner, HandlerSlot *target, bool &callbackContext) const
 
bool dispatchSelected (uint64_t delta, TimerHandler *onlyHandler, bool dueOnly, uint64_t now)
 

Static Private Member Functions

static size_t makePublication (size_t generation, SlotMode mode, bool selfRemoval=false, bool synchronousDrain=false)
 
static size_t generationOf (size_t publication)
 
static SlotMode modeOf (size_t publication)
 
static bool selfRemovalOf (size_t publication)
 
static bool synchronousDrainOf (size_t publication)
 
static void abandonDispatch (void *context)
 
static void * currentDispatchOwner ()
 

Private Attributes

HandlerSlot m_Handlers [MaxHandlerSlots]
 
ActiveDispatch m_ActiveDispatches [MaxActiveDispatches]
 
WaitQueue m_DispatchWaiters
 
Spinlock m_HandlerLock
 

Static Private Attributes

static constexpr size_t MaxHandlerSlots = 32
 
static constexpr size_t MaxActiveDispatches = 64
 
static constexpr uint64_t NoDeadline = ~static_cast<uint64_t>(0)
 
static constexpr size_t ModeBits = 3
 
static constexpr size_t ModeMask = (1 << ModeBits) - 1
 
static constexpr size_t SelfRemovalBit = 1 << ModeBits
 
static constexpr size_t SynchronousDrainBit = 1 << (ModeBits + 1)
 
static constexpr size_t GenerationShift = ModeBits + 2
 

Detailed Description

Allocation-free timer callback registry with synchronous removal.

Dispatch pins atomically published slots without taking the writer lock. Removal closes admission before draining callbacks which committed a pin.

Definition at line 26 of file TimerHandlerRegistry.h.

Member Enumeration Documentation

◆ SlotMode

enum class TimerHandlerRegistry::SlotMode : size_t
strongprivate

Definition at line 79 of file TimerHandlerRegistry.h.

Constructor & Destructor Documentation

◆ TimerHandlerRegistry()

TimerHandlerRegistry::TimerHandlerRegistry ( )

Definition at line 18 of file TimerHandlerRegistry.cc.

Member Function Documentation

◆ abandonDispatch()

void TimerHandlerRegistry::abandonDispatch ( void *  context)
staticprivate

Definition at line 184 of file TimerHandlerRegistry.cc.

◆ armHandler()

bool TimerHandlerRegistry::armHandler ( TimerHandler *  handler,
uint64_t  deadline,
uint64_t  now 
)

Arms one callback at an absolute monotonic deadline; zero disarms it.

Definition at line 298 of file TimerHandlerRegistry.cc.

Referenced by Rtc::armHandler().

+ Here is the caller graph for this function:

◆ currentDispatchOwner()

void * TimerHandlerRegistry::currentDispatchOwner ( )
staticprivate

Definition at line 234 of file TimerHandlerRegistry.cc.

◆ dispatch()

bool TimerHandlerRegistry::dispatch ( uint64_t  delta,
TimerHandler *  onlyHandler = nullptr 
)

Calls each handler admitted by the current publication.

Definition at line 519 of file TimerHandlerRegistry.cc.

Referenced by Rtc::processElapsedTime(), and HostedTimer::processTimerBatch().

+ Here is the caller graph for this function:

◆ dispatchDue()

bool TimerHandlerRegistry::dispatchDue ( uint64_t  now)

Calls each due handler once, with elapsed time since its prior callback.

Definition at line 523 of file TimerHandlerRegistry.cc.

◆ dispatchSelected()

bool TimerHandlerRegistry::dispatchSelected ( uint64_t  delta,
TimerHandler *  onlyHandler,
bool  dueOnly,
uint64_t  now 
)
private

Definition at line 527 of file TimerHandlerRegistry.cc.

◆ findCurrentDispatch()

bool TimerHandlerRegistry::findCurrentDispatch ( void *  owner,
HandlerSlot *  target,
bool &  callbackContext 
) const
private

Definition at line 207 of file TimerHandlerRegistry.cc.

◆ generationOf()

size_t TimerHandlerRegistry::generationOf ( size_t  publication)
staticprivate

Definition at line 39 of file TimerHandlerRegistry.cc.

◆ hasActiveDispatch()

bool TimerHandlerRegistry::hasActiveDispatch ( HandlerSlot &  slot) const
private

Definition at line 189 of file TimerHandlerRegistry.cc.

◆ makePublication()

size_t TimerHandlerRegistry::makePublication ( size_t  generation,
SlotMode  mode,
bool  selfRemoval = false,
bool  synchronousDrain = false 
)
staticprivate

Definition at line 33 of file TimerHandlerRegistry.cc.

◆ modeOf()

TimerHandlerRegistry::SlotMode TimerHandlerRegistry::modeOf ( size_t  publication)
staticprivate

Definition at line 43 of file TimerHandlerRegistry.cc.

◆ nextDeadline()

uint64_t TimerHandlerRegistry::nextDeadline ( ) const

Returns the earliest armed deadline, or Time::Infinity if none exists.

Definition at line 331 of file TimerHandlerRegistry.cc.

◆ publishDispatch()

bool TimerHandlerRegistry::publishDispatch ( DispatchCleanup &  cleanup)
private

Definition at line 74 of file TimerHandlerRegistry.cc.

◆ registerHandler()

bool TimerHandlerRegistry::registerHandler ( TimerHandler *  handler)

Definition at line 240 of file TimerHandlerRegistry.cc.

◆ reset()

void TimerHandlerRegistry::reset ( )

Clears quiescent registry state during timer lifecycle transitions.

Definition at line 625 of file TimerHandlerRegistry.cc.

Referenced by HostedTimer::initialise1(), Rtc::initialise1(), HostedTimer::uninitialise(), and Rtc::uninitialise().

+ Here is the caller graph for this function:

◆ retireSlot()

bool TimerHandlerRegistry::retireSlot ( HandlerSlot &  slot,
size_t  expectedPublication,
TimerHandler *  expectedHandler 
)
private

Definition at line 55 of file TimerHandlerRegistry.cc.

◆ selfRemovalOf()

bool TimerHandlerRegistry::selfRemovalOf ( size_t  publication)
staticprivate

Definition at line 47 of file TimerHandlerRegistry.cc.

◆ synchronousDrainOf()

bool TimerHandlerRegistry::synchronousDrainOf ( size_t  publication)
staticprivate

Definition at line 51 of file TimerHandlerRegistry.cc.

◆ unpublishDispatch()

bool TimerHandlerRegistry::unpublishDispatch ( DispatchCleanup &  cleanup,
bool  required 
)
private

Definition at line 107 of file TimerHandlerRegistry.cc.

◆ unregisterHandler()

bool TimerHandlerRegistry::unregisterHandler ( TimerHandler *  handler)

Stops future callbacks and drains callbacks already in progress.

Self-removal is deferred until the callback returns and reports false, preserving Timer's synchronous boolean contract. Other atomic callers report false instead of waiting for an in-flight callback. A synchronous caller must not retain a resource which the active handler needs to finish.

Definition at line 348 of file TimerHandlerRegistry.cc.

References Spinlock::acquire(), ProcessorBase::getInterrupts(), ProcessorBase::information(), ProcessorBase::pause(), and Spinlock::release().

Member Data Documentation

◆ GenerationShift

constexpr size_t TimerHandlerRegistry::GenerationShift = ModeBits + 2
staticconstexprprivate

Definition at line 91 of file TimerHandlerRegistry.h.

◆ m_ActiveDispatches

ActiveDispatch TimerHandlerRegistry::m_ActiveDispatches[MaxActiveDispatches]
private

Definition at line 149 of file TimerHandlerRegistry.h.

◆ m_DispatchWaiters

WaitQueue TimerHandlerRegistry::m_DispatchWaiters
private

Definition at line 150 of file TimerHandlerRegistry.h.

◆ m_HandlerLock

Spinlock TimerHandlerRegistry::m_HandlerLock
private

Definition at line 151 of file TimerHandlerRegistry.h.

◆ m_Handlers

HandlerSlot TimerHandlerRegistry::m_Handlers[MaxHandlerSlots]
private

Definition at line 148 of file TimerHandlerRegistry.h.

◆ MaxActiveDispatches

constexpr size_t TimerHandlerRegistry::MaxActiveDispatches = 64
staticconstexprprivate

Definition at line 76 of file TimerHandlerRegistry.h.

◆ MaxHandlerSlots

constexpr size_t TimerHandlerRegistry::MaxHandlerSlots = 32
staticconstexprprivate

Definition at line 75 of file TimerHandlerRegistry.h.

◆ ModeBits

constexpr size_t TimerHandlerRegistry::ModeBits = 3
staticconstexprprivate

Definition at line 87 of file TimerHandlerRegistry.h.

◆ ModeMask

constexpr size_t TimerHandlerRegistry::ModeMask = (1 << ModeBits) - 1
staticconstexprprivate

Definition at line 88 of file TimerHandlerRegistry.h.

◆ NoDeadline

constexpr uint64_t TimerHandlerRegistry::NoDeadline = ~static_cast<uint64_t>(0)
staticconstexprprivate

Definition at line 77 of file TimerHandlerRegistry.h.

◆ SelfRemovalBit

constexpr size_t TimerHandlerRegistry::SelfRemovalBit = 1 << ModeBits
staticconstexprprivate

Definition at line 89 of file TimerHandlerRegistry.h.

◆ SynchronousDrainBit

constexpr size_t TimerHandlerRegistry::SynchronousDrainBit = 1 << (ModeBits + 1)
staticconstexprprivate

Definition at line 90 of file TimerHandlerRegistry.h.


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