ucommon
Data Structures | Public Member Functions | Protected Member Functions | Friends
ucommon::TimerQueue Class Reference

A timer queue for timer events. More...

#include <timers.h>

Inheritance diagram for ucommon::TimerQueue:
Inheritance graph
[legend]
Collaboration diagram for ucommon::TimerQueue:
Collaboration graph
[legend]

Data Structures

class  event
 A timer event object that lives on a timer queue. More...

Public Member Functions

timeout_t expire ()
 Process timer queue and find when next event triggers.
void operator+= (event &timer)
 Add a timer event to the timer queue.
void operator-= (event &timer)
 Remove a timer event from the timer queue.
 TimerQueue ()
 Create an empty timer queue.
virtual ~TimerQueue ()
 Destroy queue, does not remove event objects.
- Public Member Functions inherited from ucommon::OrderedIndex
void add (OrderedObject *ordered)
 Add an object into the ordered index.
LinkedObjectbegin (void)
 Return first object in list for iterators.
unsigned count (void)
 Count of objects this list manages.
LinkedObjectend (void)
 Return last object in list for iterators.
LinkedObjectfind (unsigned offset)
 Find a specific member in the ordered list.
LinkedObjectget (void)
 Get (pull) object off the list.
LinkedObjectgetIndexed (unsigned index)
 Get an indexed member from the ordered index.
LinkedObject ** index (void)
 Return a pointer to the head of the list.
virtual void lock_index (void)
 Used to synchronize lists managed by multiple threads.
LinkedObjectoperator* ()
 Return head object pointer.
void operator*= (OrderedObject *object)
 Add object to our list.
 OrderedIndex ()
 Create and initialize an empty index.
void purge (void)
 Purge the linked list and then set the index to empty.
void reset (void)
 Reset linked list to empty without purging.
virtual void unlock_index (void)
 Used to synchronize lists managed by multiple threads.
virtual ~OrderedIndex ()
 Destroy index.

Protected Member Functions

virtual void modify (void)=0
 Called in derived class when the queue is being modified.
virtual void update (void)=0
 Called in derived class after the queue has been modified.

Friends

class event

Additional Inherited Members

- Protected Attributes inherited from ucommon::OrderedIndex
OrderedObjecthead
OrderedObjecttail

Detailed Description

A timer queue for timer events.

The timer queue is used to hold a linked list of timers that must be processed together. The timer queue processes the timer event list and calls an expired function on events that have expired. The timer queue also determines the wait time until the next timer will expire. When timer events are modified, they can retrigger the queue to re-examine the list to find when the next timer will now expire.

Author
David Sugar dyfet.nosp@m.@gnu.nosp@m.telep.nosp@m.hony.nosp@m..org

Definition at line 269 of file timers.h.

Member Function Documentation

timeout_t ucommon::TimerQueue::expire ( )

Process timer queue and find when next event triggers.

This function will call the expired methods on expired timers. Normally this function will be called in the context of a timer thread which sleeps for the timeout returned unless it is awoken on an update event.

Returns
timeout until next timer expires in milliseconds.
virtual void ucommon::TimerQueue::modify ( void  )
protectedpure virtual

Called in derived class when the queue is being modified.

This is often used to lock the list.

void ucommon::TimerQueue::operator+= ( event timer)

Add a timer event to the timer queue.

Parameters
timerevent to add.
void ucommon::TimerQueue::operator-= ( event timer)

Remove a timer event from the timer queue.

Parameters
timerevent to remove.
virtual void ucommon::TimerQueue::update ( void  )
protectedpure virtual

Called in derived class after the queue has been modified.

This often releases a lock that modify set and to wakeup a timer thread to evaluate when the next timer will now expire.


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