Main Page Class Hierarchy Alphabetical List Compound List File List Compound Members File Members Related Pages

# ACE_Timer_Wheel_T Class Template Reference

Provides a Timing Wheel version of Timer Queue. More...

`#include <Timer_Wheel_T.h>`

Inheritance diagram for ACE_Timer_Wheel_T

[legend]
Collaboration diagram for ACE_Timer_Wheel_T:

[legend]
List of all members.

## Public Types
typedef ACE_Timer_Wheel_Iterator_T< TYPE, FUNCTOR, ACE_LOCK> | WHEEL_ITERATOR
| Type of iterator.
typedef ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK> | INHERITED
| Type inherited from.
## Public Methods
| ACE_Timer_Wheel_T (FUNCTOR *upcall_functor = 0, ACE_Free_List<ACE_Timer_Node_T <TYPE> > *freelist = 0)
| Default constructor. More...
| ACE_Timer_Wheel_T (size_t wheelsize, size_t resolution, size_t prealloc = 0, FUNCTOR *upcall_functor = 0, ACE_Free_List<ACE_Timer_Node_T <TYPE> > *freelist = 0)
| Constructor with opportunities to set the wheelsize and resolution. More...
virtual | ~ACE_Timer_Wheel_T (void)
| Destructor.
virtual int | is_empty (void) const
| True if queue is empty, else false. More...
virtual const ACE_Time_Value& | earliest_time (void) const
| Returns the time of the earlier node in the . Must be called on a non-empty queue. More...
virtual long | schedule (const TYPE &type, const void *act, const ACE_Time_Value &delay, const ACE_Time_Value &interval = ACE_Time_Value::zero)
| Schedules a timer. More...
virtual int | reset_interval (long timer_id, const ACE_Time_Value &interval)
| Changes the interval of a timer (and can make it periodic or non periodic by setting it to ACE_Time_Value::zero or not). More...
virtual int | cancel (const TYPE &type, int dont_call_handle_close = 1)
| Cancel all timer associated with <type>. If <dont_call> is 0 then the <functor> will be invoked. Returns number of timers cancelled. More...
virtual int | cancel (long timer_id, const void **act = 0, int dont_call_handle_close = 1)
virtual int | expire (void)
| Run the <functor> for all timers whose values are <= . Also accounts for <timer_skew>. Returns the number of timers canceled. More...
int | expire (const ACE_Time_Value &)
virtual ACE_Timer_Queue_Iterator_T< TYPE, FUNCTOR, ACE_LOCK>& | iter (void)
| Returns a pointer to this 's iterator. More...
virtual ACE_Timer_Node_T<TYPE>* | remove_first (void)
| Removes the earliest node from the queue and returns it. More...
virtual void | dump (void) const
| Dump the state of an object. More...
virtual ACE_Timer_Node_T<TYPE>* | get_first (void)
| Reads the earliest node from the queue and returns it. More...
## Private Methods
virtual void | reschedule (ACE_Timer_Node_T<TYPE> *)
| Reschedule an "interval" node. More...
| ACE_Timer_Wheel_T (const ACE_Timer_Wheel_T<TYPE, FUNCTOR, ACE_LOCK> &)
void | operator= (const ACE_Timer_Wheel_T<TYPE, FUNCTOR, ACE_LOCK> &)
## Private Attributes
ACE_Timer_Node_T<TYPE>** | wheel_
| Timing Wheel.
size_t | wheel_size_
| Size of the timing wheel.
size_t | resolution_
| Resolution (in microsoconds) of the timing wheel.
size_t | earliest_pos_
| Index of the list with the earliest time.
long | size_
| Keeps track of the size of the queue.
WHEEL_ITERATOR* | iterator_
| Iterator used to expire timers.
ACE_Timer_Node_T<TYPE>* | freelist_
| Pointer to the freelist of >.
## Friends
class | ACE_Timer_Wheel_Iterator_T< TYPE,FUNCTOR,ACE_LOCK >

## Detailed Description

### template<class TYPE, class FUNCTOR, class ACE_LOCK> template class ACE_Timer_Wheel_T

Provides a Timing Wheel version of Timer Queue.

This implementation uses a hash table of ordered doubly- linked lists of absolute times. The other enhancements to Timer List include using the pointer to the node as the timer id (to speed up removing), adding a free list and the ability to preallocate nodes. Timer Wheel is based on the timing wheel implementation used in Adam M. Costello and George Varghese's paper "Redesigning the BSD Callout and Timer Facilities" (http://dworkin.wustl.edu/~varghese/PAPERS/newbsd.ps.Z)

## Member Typedef Documentation

template<classTYPE, classFUNCTOR, classACE_LOCK>
typedef ACE_Timer_Queue_T<TYPE, FUNCTOR, ACE_LOCK> ACE_Timer_Wheel_T<TYPE, FUNCTOR, ACE_LOCK>::INHERITED

| Type inherited from.

template<classTYPE, classFUNCTOR, classACE_LOCK>
typedef ACE_Timer_Wheel_Iterator_T<TYPE, FUNCTOR, ACE_LOCK> ACE_Timer_Wheel_T<TYPE, FUNCTOR, ACE_LOCK>::WHEEL_ITERATOR

| Type of iterator.

## Constructor & Destructor Documentation

template<classTYPE, classFUNCTOR, classACE_LOCK>
ACE_Timer_Wheel_T<TYPE, FUNCTOR, ACE_LOCK>::ACE_Timer_Wheel_T<TYPE, FUNCTOR, ACE_LOCK> ( | FUNCTOR * upcall_functor = 0,
| ACE_Free_List< ACE_Timer_Node_T< TYPE > >* freelist = 0 )

  | Default constructor. Default Constructor that sets defaults for wheel_size_ and resolution_ and doesn't do any preallocation. Parameters:
  upcall_functor | A pointer to a functor to use instead of the default
  freelist | A pointer to a freelist to use instead of the default

template<classTYPE, classFUNCTOR, classACE_LOCK>
ACE_Timer_Wheel_T<TYPE, FUNCTOR, ACE_LOCK>::ACE_Timer_Wheel_T<TYPE, FUNCTOR, ACE_LOCK> ( | size_t wheelsize,
| size_t resolution,
| size_t prealloc = 0,
| FUNCTOR * upcall_functor = 0,
| ACE_Free_List< ACE_Timer_Node_T< TYPE > >* freelist = 0 )

  | Constructor with opportunities to set the wheelsize and resolution. Constructor that sets up the timing wheel and also may preallocate some nodes on the free list Parameters:
  wheelsize | The number of lists in the timer wheel
  resolution | The time resolution used by the hashing function
  prealloc | The number of entries to prealloc in the free_list
  upcall_functor | A pointer to a functor to use instead of the default
  freelist | A pointer to a freelist to use instead of the default

template<classTYPE, classFUNCTOR, classACE_LOCK>
ACE_Timer_Wheel_T<TYPE, FUNCTOR, ACE_LOCK>::~ACE_Timer_Wheel_T<TYPE, FUNCTOR, ACE_LOCK> ( | void )`[virtual]`

| Destructor.

template<classTYPE, classFUNCTOR, classACE_LOCK>
ACE_Timer_Wheel_T<TYPE, FUNCTOR, ACE_LOCK>::ACE_Timer_Wheel_T<TYPE, FUNCTOR, ACE_LOCK> ( | const ACE_Timer_Wheel_T< TYPE,FUNCTOR,ACE_LOCK >& )`[private]`

## Member Function Documentation

template<classTYPE, classFUNCTOR, classACE_LOCK>
int ACE_Timer_Wheel_T< TYPE,FUNCTOR,ACE_LOCK >::cancel ( | long timer_id,
| const void ** act = 0,
| int skip_close = 1 )`[virtual]`

  | Cancels the single timer that is specified by the timer_id. In this case the timer_id is actually a pointer to the node, so we cast it to the node. This can be dangerous if the timer_id is made up (or deleted twice) so we do a little sanity check. Finally we update the earliest time in case the earliest timer was removed. Parameters:
  timer_id | Timer Identifier
  act | Asychronous Completion Token (AKA magic cookie): If this is non-zero, stores the magic cookie of the cancelled timer here.
  skip_close | If this non-zero, the cancellation method of the functor will not be called.
Returns: 1 for sucess and 0 if the timer_id wasn't found (or was found to be invalid) Reimplemented from ACE_Timer_Queue_T.

template<classTYPE, classFUNCTOR, classACE_LOCK>
int ACE_Timer_Wheel_T<TYPE, FUNCTOR, ACE_LOCK>::cancel ( | const TYPE & type,
| int dont_call_handle_close = 1 )`[virtual]`

  | Cancel all timer associated with <type>. If <dont_call> is 0 then the <functor> will be invoked. Returns number of timers cancelled. Goes through every list in the wheel and whenever we find one with the correct type value, we remove it and continue. At the end make sure we reset the earliest time value in case the earliest timers were removed. Parameters:
  type | The value to search for.
  skip_close | If this non-zero, the cancellation method of the functor will not be called for each cancelled timer.
Returns: Number of timers cancelled Reimplemented from ACE_Timer_Queue_T.

template<classTYPE, classFUNCTOR, classACE_LOCK>
void ACE_Timer_Wheel_T<TYPE, FUNCTOR, ACE_LOCK>::dump ( | void ) const`[virtual]`

| Dump the state of an object. Dumps out the size of the wheel, the resolution, and the contents of the wheel. Reimplemented from ACE_Timer_Queue_T.

template<classTYPE, classFUNCTOR, classACE_LOCK>
const ACE_Time_Value & ACE_Timer_Wheel_T<TYPE, FUNCTOR, ACE_LOCK>::earliest_time ( | void ) const`[virtual]`

| Returns the time of the earlier node in the . Must be called on a non-empty queue. Returns: First (earliest) node in the wheel_'s earliest_pos_ list Reimplemented from ACE_Timer_Queue_T.

template<classTYPE, classFUNCTOR, classACE_LOCK>
int ACE_Timer_Wheel_T< TYPE,FUNCTOR,ACE_LOCK >::expire ( | const ACE_Time_Value & cur_time )`[virtual]`

  | This is a specialized version of expire that is more suited for the internal data representation. Notice that we are still expiring timers in order, even though this can be really speeded up if we didn't worry about this. Parameters:
  cur_time | The time to expire timers up to.
Returns: Number of timers expired Reimplemented from ACE_Timer_Queue_T.

template<classTYPE, classFUNCTOR, classACE_LOCK>
int ACE_Timer_Wheel_T<TYPE, FUNCTOR, ACE_LOCK>::expire ( | void )`[virtual]`

| Run the <functor> for all timers whose values are <= . Also accounts for <timer_skew>. Returns the number of timers canceled. Dummy version of expire to get rid of warnings in Sun CC 4.2 Just call the expire of the base class. Reimplemented from ACE_Timer_Queue_T.

template<classTYPE, classFUNCTOR, classACE_LOCK>
ACE_Timer_Node_T< TYPE >* ACE_Timer_Wheel_T<TYPE, FUNCTOR, ACE_LOCK>::get_first ( | void )`[virtual]`

| Reads the earliest node from the queue and returns it. Returns the earliest node without removing it Returns: The earliest timer node. Reimplemented from ACE_Timer_Queue_T.

template<classTYPE, classFUNCTOR, classACE_LOCK>
int ACE_Timer_Wheel_T<TYPE, FUNCTOR, ACE_LOCK>::is_empty ( | void ) const`[virtual]`

| True if queue is empty, else false. Checks to see if <earliest_pos> points to a empty list (then it is empty). Returns: True if empty Reimplemented from ACE_Timer_Queue_T.

template<classTYPE, classFUNCTOR, classACE_LOCK>
ACE_Timer_Queue_Iterator_T< TYPE,FUNCTOR,ACE_LOCK >& ACE_Timer_Wheel_T<TYPE, FUNCTOR, ACE_LOCK>::iter ( | void )`[virtual]`

| Returns a pointer to this 's iterator. Returns: The iterator Reimplemented from ACE_Timer_Queue_T.

template<classTYPE, classFUNCTOR, classACE_LOCK>
void ACE_Timer_Wheel_T<TYPE, FUNCTOR, ACE_LOCK>::operator= ( | const ACE_Timer_Wheel_T< TYPE,FUNCTOR,ACE_LOCK >& )`[private]`

template<classTYPE, classFUNCTOR, classACE_LOCK>
ACE_Timer_Node_T< TYPE >* ACE_Timer_Wheel_T<TYPE, FUNCTOR, ACE_LOCK>::remove_first ( | void )`[virtual]`

| Removes the earliest node from the queue and returns it. Removes the earliest node and then find the new <earliest_pos_> Returns: The earliest timer node. Reimplemented from ACE_Timer_Queue_T.

template<classTYPE, classFUNCTOR, classACE_LOCK>
void ACE_Timer_Wheel_T<TYPE, FUNCTOR, ACE_LOCK>::reschedule ( | ACE_Timer_Node_T< TYPE >* expired )`[private, virtual]`

  | Reschedule an "interval" node. Takes an ACE_Timer_Node and inserts it into the correct position in the correct list. Also makes sure to update the earliest time. Parameters:
  expired | The timer node to reschedule
Reimplemented from ACE_Timer_Queue_T.

template<classTYPE, classFUNCTOR, classACE_LOCK>
int ACE_Timer_Wheel_T<TYPE, FUNCTOR, ACE_LOCK>::reset_interval ( | long timer_id,
| const ACE_Time_Value & interval )`[virtual]`

  | Changes the interval of a timer (and can make it periodic or non periodic by setting it to ACE_Time_Value::zero or not). Find the timer node by using the id as a pointer. Then use set_interval () on the node to update the interval. Parameters:
  timer_id | The timer identifier
  interval | The new interval
Returns: 0 if successful, -1 if no. Reimplemented from ACE_Timer_Queue_T.

template<classTYPE, classFUNCTOR, classACE_LOCK>
long ACE_Timer_Wheel_T<TYPE, FUNCTOR, ACE_LOCK>::schedule ( | const TYPE & type,
| const void * act,
| const ACE_Time_Value & delay,
| const ACE_Time_Value & interval = ACE_Time_Value::zero )`[virtual]`

  | Schedules a timer. Creates a ACE_Timer_Node_T based on the input parameters. Then inserts the node into the wheel using reschedule (). Then returns a timer_id (which is actually a pointer to the actual timer_node). Parameters:
  type | The data of the timer node
  act | Asynchronous Completion Token (AKA magic cookie)
  delay | The time the timer is scheduled for (in absolute time)
  interval | If not ACE_Time_Value::zero, then this is a periodic timer and interval is the time period
Returns: Unique identifier (can be used to cancel the timer. -1 on failure. Reimplemented from ACE_Timer_Queue_T.

## Friends And Related Function Documentation

template<classTYPE, classFUNCTOR, classACE_LOCK>
class ACE_Timer_Wheel_Iterator_T`[friend]`

| Iterator is a friend.

## Member Data Documentation

template<classTYPE, classFUNCTOR, classACE_LOCK>
size_t ACE_Timer_Wheel_T<TYPE, FUNCTOR, ACE_LOCK>::earliest_pos_`[private]`

| Index of the list with the earliest time.

template<classTYPE, classFUNCTOR, classACE_LOCK>
ACE_Timer_Node_T< TYPE >* ACE_Timer_Wheel_T<TYPE, FUNCTOR, ACE_LOCK>::freelist_`[private]`

| Pointer to the freelist of >.

template<classTYPE, classFUNCTOR, classACE_LOCK>
WHEEL_ITERATOR * ACE_Timer_Wheel_T<TYPE, FUNCTOR, ACE_LOCK>::iterator_`[private]`

| Iterator used to expire timers.

template<classTYPE, classFUNCTOR, classACE_LOCK>
size_t ACE_Timer_Wheel_T<TYPE, FUNCTOR, ACE_LOCK>::resolution_`[private]`

| Resolution (in microsoconds) of the timing wheel.

template<classTYPE, classFUNCTOR, classACE_LOCK>
long ACE_Timer_Wheel_T<TYPE, FUNCTOR, ACE_LOCK>::size_`[private]`

| Keeps track of the size of the queue.

template<classTYPE, classFUNCTOR, classACE_LOCK>
ACE_Timer_Node_T< TYPE >** ACE_Timer_Wheel_T<TYPE, FUNCTOR, ACE_LOCK>::wheel_`[private]`

| Timing Wheel.

template<classTYPE, classFUNCTOR, classACE_LOCK>
size_t ACE_Timer_Wheel_T<TYPE, FUNCTOR, ACE_LOCK>::wheel_size_`[private]`

| Size of the timing wheel.

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

- Timer_Wheel_T.h
- Timer_Wheel_T.cpp