Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
ActiveTimers Class Reference

Class that manages the list of active timers. More...

#include <Timer.hxx>

Inheritance diagram for ActiveTimers:
Executable Notifiable QMember Destructable

Public Member Functions

 ActiveTimers (ExecutorBase *executor)
 Constructor.
 
long long get_next_timeout ()
 Tell when the first timer will expire.
 
bool empty ()
 
void schedule_timer (::Timer *timer)
 Adds a new timer to the active timer list.
 
void update_timer (::Timer *timer)
 Updates the expiration time of an already scheduled timer.
 
void remove_timer (::Timer *timer)
 Deletes an already scheduled but not yet expired timer.
 
ExecutorBaseexecutor ()
 
void notify () override
 Notification callback from the timer.
 
void run () override
 Callback from the executor.
 
- Public Member Functions inherited from Executable
void test_deletion ()
 
void notify () override
 Crashes the program – everyone who is expecting notify calls must override this function.
 
virtual void alloc_result (QMember *item)
 Return the result of an alloc_async() from a memory Pool.
 
- Public Member Functions inherited from QMember
void init ()
 Initiailize a QMember, in place of a public placement construction.
 

Private Member Functions

void remove_locked (::Timer *timer)
 Removes a timer from the active list.
 
void insert_locked (::Timer *timer)
 Inserts a timer into the active list.
 
 DISALLOW_COPY_AND_ASSIGN (ActiveTimers)
 

Private Attributes

ExecutorBaseexecutor_
 Parent.
 
OSMutex lock_
 Protects the timer list.
 
QMember activeTimers_
 List of timers that are scheduled.
 
std::atomic_uint_least8_t isPending_
 1 if we in the executor's queue.
 

Friends

class TimerTest
 

Additional Inherited Members

- Protected Member Functions inherited from QMember
 QMember ()
 Constructor.
 
 ~QMember ()
 Destructor.
 
- Protected Attributes inherited from QMember
QMembernext
 pointer to the next member in the queue
 

Detailed Description

Class that manages the list of active timers.

The Executor uses this class tightly in its sleep-execute loop.

Definition at line 48 of file Timer.hxx.

Constructor & Destructor Documentation

◆ ActiveTimers()

ActiveTimers::ActiveTimers ( ExecutorBase executor)
inline

Constructor.

Parameters
executorparent that will use this instance.

Definition at line 54 of file Timer.hxx.

◆ ~ActiveTimers()

ActiveTimers::~ActiveTimers ( )

Definition at line 65 of file Timer.cxx.

Member Function Documentation

◆ empty()

bool ActiveTimers::empty ( )
Returns
true if there are no timers waiting.

Definition at line 124 of file Timer.cxx.

◆ executor()

ExecutorBase * ActiveTimers::executor ( )
inline
Returns
the executor on which the timers will be scheduled.

Definition at line 94 of file Timer.hxx.

◆ get_next_timeout()

long long ActiveTimers::get_next_timeout ( )

Tell when the first timer will expire.

If there are no active timers, returns a large number.

Returns
the timer in nanoseconds to sleep until the next timer to wake up. Can return 0 if there is an expired timer.

Definition at line 84 of file Timer.cxx.

◆ insert_locked()

void ActiveTimers::insert_locked ( ::Timer timer)
private

Inserts a timer into the active list.

Caller must hold the lock.

Parameters
timerwhat to insert into the active list.

Definition at line 138 of file Timer.cxx.

◆ notify()

void ActiveTimers::notify ( )
overridevirtual

Notification callback from the timer.

Schedules *this on the executor.

Implements Notifiable.

Definition at line 69 of file Timer.cxx.

◆ remove_locked()

void ActiveTimers::remove_locked ( ::Timer timer)
private

Removes a timer from the active list.

Assert fails if it is not there. Caller must hold the lock.

Parameters
timerwhat to remove from the active list.

Definition at line 159 of file Timer.cxx.

◆ remove_timer()

void ActiveTimers::remove_timer ( ::Timer timer)

Deletes an already scheduled but not yet expired timer.

This call is somewhat expensive, because it needs to walk the entire queue of active timers. Asserts that the timer is in fact not yet expired.

Parameters
timeris the timer to delete.

Definition at line 181 of file Timer.cxx.

◆ run()

void ActiveTimers::run ( )
overridevirtual

Callback from the executor.

Puts all expired timers on the executor.

Implements Executable.

Definition at line 77 of file Timer.cxx.

◆ schedule_timer()

void ActiveTimers::schedule_timer ( ::Timer timer)

Adds a new timer to the active timer list.

It is OK to schedule a timer that is already expired, which will then wake up the executor.

Parameters
timeris the timer to schedule. It must not be already scheduled.

Definition at line 132 of file Timer.cxx.

◆ update_timer()

void ActiveTimers::update_timer ( ::Timer timer)

Updates the expiration time of an already scheduled timer.

This call is somewhat expensive, because it needs to walk the entire queue of active timers. May wake up the executor.

Parameters
timeris the timer whose next execution time has been updated. It must already be scheduled.

Definition at line 173 of file Timer.cxx.

Friends And Related Symbol Documentation

◆ TimerTest

friend class TimerTest
friend

Definition at line 125 of file Timer.hxx.

Member Data Documentation

◆ activeTimers_

QMember ActiveTimers::activeTimers_
private

List of timers that are scheduled.

Definition at line 121 of file Timer.hxx.

◆ executor_

ExecutorBase* ActiveTimers::executor_
private

Parent.

Definition at line 117 of file Timer.hxx.

◆ isPending_

std::atomic_uint_least8_t ActiveTimers::isPending_
private

1 if we in the executor's queue.

Definition at line 123 of file Timer.hxx.

◆ lock_

OSMutex ActiveTimers::lock_
private

Protects the timer list.

Definition at line 119 of file Timer.hxx.


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