ACE  6.5.11
Public Types | Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
ACE_Timer_Wheel_T Class Reference

Provides a Timing Wheel version of ACE_Timer_Queue. More...

#include <Timer_Wheel_T.h>

Collaboration diagram for ACE_Timer_Wheel_T:
Collaboration graph
[legend]

Public Types

typedef ACE_Timer_Wheel_Iterator_T< TYPE, FUNCTOR, ACE_LOCK, TIME_POLICY > Iterator
 Type of iterator. More...
 
typedef ACE_Timer_Node_T< TYPE > Node
 
typedef ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK, TIME_POLICY > Base_Timer_Queue
 Type inherited from. More...
 
typedef ACE_Free_List< NodeFreeList
 

Public Member Functions

 ACE_Timer_Wheel_T (FUNCTOR *upcall_functor=0, FreeList *freelist=0, TIME_POLICY const &time_policy=TIME_POLICY())
 Default constructor. More...
 
 ACE_Timer_Wheel_T (u_int spoke_count, u_int resolution, size_t prealloc=0, FUNCTOR *upcall_functor=0, FreeList *freelist=0, TIME_POLICY const &time_policy=TIME_POLICY())
 Constructor with opportunities to set the wheelsize and resolution. More...
 
virtual ~ACE_Timer_Wheel_T (void)
 Destructor. More...
 
virtual bool is_empty (void) const
 True if queue is empty, else false. More...
 
virtual const ACE_Time_Valueearliest_time (void) const
 
virtual int reset_interval (long timer_id, const ACE_Time_Value &interval)
 
virtual int cancel (const TYPE &type, int dont_call_handle_close=1)
 
virtual int cancel (long timer_id, const void **act=0, int dont_call_handle_close=1)
 
virtual int close (void)
 
virtual int expire (void)
 
int expire (const ACE_Time_Value &current_time)
 
virtual ACE_Timer_Queue_Iterator_T< TYPE > & iter (void)
 Returns a pointer to this <ACE_Timer_Queue_T>'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...
 

Protected Member Functions

virtual long schedule_i (const TYPE &type, const void *act, const ACE_Time_Value &future_time, const ACE_Time_Value &interval)
 Schedules a timer. More...
 

Private Member Functions

ACE_Timer_Node_T< TYPE > * get_first_i (void) const
 
ACE_Timer_Node_T< TYPE > * remove_first_expired (const ACE_Time_Value &now)
 
void open_i (size_t prealloc, u_int spokes, u_int res)
 
virtual void reschedule (ACE_Timer_Node_T< TYPE > *)
 
ACE_Timer_Node_T< TYPE > * find_spoke_node (u_int spoke, long timer_id) const
 Searches for a node by timer_id within one spoke. More...
 
ACE_Timer_Node_T< TYPE > * find_node (long timer_id) const
 
u_int calculate_spoke (const ACE_Time_Value &expire) const
 
long generate_timer_id (u_int spoke)
 
void schedule_i (ACE_Timer_Node_T< TYPE > *n, u_int spoke, const ACE_Time_Value &expire)
 The shared scheduling functionality between schedule() and reschedule() More...
 
void cancel_i (ACE_Timer_Node_T< TYPE > *n)
 Shared subset of the two cancel() methods. More...
 
void unlink (ACE_Timer_Node_T< TYPE > *n)
 
void recalc_earliest (const ACE_Time_Value &last)
 
int power2bits (int n, int min_bits, int max_bits)
 

Private Attributes

ACE_Timer_Node_T< TYPE > ** spokes_
 Timing Wheel. More...
 
u_int spoke_count_
 Size of the timing wheel. More...
 
int spoke_bits_
 Number of timer_id bits used for the spoke. More...
 
int res_bits_
 Resolution (in microsoconds) of the timing wheel. More...
 
u_int earliest_spoke_
 Index of the list with the earliest time. More...
 
Iteratoriterator_
 Iterator used to expire timers. More...
 
ACE_Time_Value wheel_time_
 The total amount of time in one iteration of the wheel. (resolution * spoke_count) More...
 
u_int timer_count_
 The total number of timers currently scheduled. More...
 

Friends

class ACE_Timer_Wheel_Iterator_T< TYPE, FUNCTOR, ACE_LOCK, TIME_POLICY >
 Iterator is a friend. More...
 

Detailed Description

Provides a Timing Wheel version of ACE_Timer_Queue.

This implementation uses a hash table of ordered doubly- linked lists of absolute times. The enhancements over the ACE_Timer_List include 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

◆ Base_Timer_Queue

typedef ACE_Timer_Queue_T<TYPE, FUNCTOR, ACE_LOCK, TIME_POLICY> ACE_Timer_Wheel_T::Base_Timer_Queue

Type inherited from.

◆ FreeList

◆ Iterator

typedef ACE_Timer_Wheel_Iterator_T<TYPE, FUNCTOR, ACE_LOCK, TIME_POLICY> ACE_Timer_Wheel_T::Iterator

Type of iterator.

◆ Node

Constructor & Destructor Documentation

◆ ACE_Timer_Wheel_T() [1/2]

ACE_Timer_Wheel_T::ACE_Timer_Wheel_T ( FUNCTOR *  upcall_functor = 0,
FreeList freelist = 0,
TIME_POLICY const &  time_policy = TIME_POLICY() 
)

Default constructor.

◆ ACE_Timer_Wheel_T() [2/2]

ACE_Timer_Wheel_T::ACE_Timer_Wheel_T ( u_int  spoke_count,
u_int  resolution,
size_t  prealloc = 0,
FUNCTOR *  upcall_functor = 0,
FreeList freelist = 0,
TIME_POLICY const &  time_policy = TIME_POLICY() 
)

Constructor with opportunities to set the wheelsize and resolution.

◆ ~ACE_Timer_Wheel_T()

ACE_Timer_Wheel_T::~ACE_Timer_Wheel_T ( void  )
virtual

Destructor.

Destructor just cleans up its memory.

Member Function Documentation

◆ calculate_spoke()

u_int ACE_Timer_Wheel_T::calculate_spoke ( const ACE_Time_Value t) const
private

Uses a simple hash to find which spoke to use based on when the timer is due to expire. Hopefully the 64bit int operations avoid any overflow problems.

◆ cancel() [1/2]

virtual int ACE_Timer_Wheel_T::cancel ( const TYPE &  type,
int  dont_call_handle_close = 1 
)
virtual

Cancel all timer associated with type. If dont_call_handle_close is 0 then the <functor> will be invoked. Returns number of timers cancelled.

◆ cancel() [2/2]

virtual int ACE_Timer_Wheel_T::cancel ( long  timer_id,
const void **  act = 0,
int  dont_call_handle_close = 1 
)
virtual

◆ cancel_i()

void ACE_Timer_Wheel_T::cancel_i ( ACE_Timer_Node_T< TYPE > *  n)
private

Shared subset of the two cancel() methods.

◆ close()

int ACE_Timer_Wheel_T::close ( void  )
virtual

Destroy timer queue. Cancels all timers.

◆ dump()

void ACE_Timer_Wheel_T::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.

◆ earliest_time()

const ACE_Time_Value & ACE_Timer_Wheel_T::earliest_time ( void  ) const
virtual

Returns the time of the earlier node in the ACE_Timer_Wheel. Must be called on a non-empty queue.

Returns
First (earliest) node in the wheel_'s earliest_spoke_ list

◆ expire() [1/2]

int ACE_Timer_Wheel_T::expire ( const ACE_Time_Value current_time)

◆ expire() [2/2]

virtual int ACE_Timer_Wheel_T::expire ( void  )
virtual

Run the <functor> for all timers whose values are <= <ACE_OS::gettimeofday>. Also accounts for <timer_skew>. Returns the number of timers canceled.

◆ find_node()

ACE_Timer_Node_T< TYPE > * ACE_Timer_Wheel_T::find_node ( long  timer_id) const
private

Searches all spokes for a node matching the specified timer_id Uses the spoke encoded in the timer_id as a starting place.

◆ find_spoke_node()

ACE_Timer_Node_T< TYPE > * ACE_Timer_Wheel_T::find_spoke_node ( u_int  spoke,
long  timer_id 
) const
private

Searches for a node by timer_id within one spoke.

◆ generate_timer_id()

long ACE_Timer_Wheel_T::generate_timer_id ( u_int  spoke)
private

Generates a unique timer_id for the given spoke. It should be pretty fast until the point where the counter overflows. At that time you have to do exhaustive searches within the spoke to ensure that a particular timer id is not already in use. Some optimizations are in place so that this hopefully doesn't have to happen often.

◆ get_first()

ACE_Timer_Node_T< TYPE > * ACE_Timer_Wheel_T::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.

◆ get_first_i()

ACE_Timer_Node_T< TYPE > * ACE_Timer_Wheel_T::get_first_i ( void  ) const
private

◆ is_empty()

bool ACE_Timer_Wheel_T::is_empty ( void  ) const
virtual

True if queue is empty, else false.

Check to see if the wheel is empty

Returns
True if empty

◆ iter()

ACE_Timer_Queue_Iterator_T< TYPE > & ACE_Timer_Wheel_T::iter ( void  )
virtual

Returns a pointer to this <ACE_Timer_Queue_T>'s iterator.

Returns
The iterator

◆ open_i()

void ACE_Timer_Wheel_T::open_i ( size_t  prealloc,
u_int  spokes,
u_int  res 
)
private

Initialize the queue. Uses the established members for all needed information.

◆ power2bits()

int ACE_Timer_Wheel_T::power2bits ( int  n,
int  min_bits,
int  max_bits 
)
private

◆ recalc_earliest()

void ACE_Timer_Wheel_T::recalc_earliest ( const ACE_Time_Value last)
private

There are a few places where we have to figure out which timer will expire next. This method makes the assumption that spokes are always sorted, and that timers are always in the correct spoke determined from their expiration time. The last time is always passed in, even though you can often calculate it as get_first()->get_timer_value().

◆ remove_first()

ACE_Timer_Node_T< TYPE > * ACE_Timer_Wheel_T::remove_first ( void  )
virtual

Removes the earliest node from the queue and returns it.

Removes the earliest node and then find the new <earliest_spoke_>

Returns
The earliest timer node.

◆ remove_first_expired()

ACE_Timer_Node_T< TYPE > * ACE_Timer_Wheel_T::remove_first_expired ( const ACE_Time_Value now)
private

◆ reschedule()

void ACE_Timer_Wheel_T::reschedule ( ACE_Timer_Node_T< TYPE > *  n)
privatevirtual

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
nThe timer node to reschedule

◆ reset_interval()

int ACE_Timer_Wheel_T::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_idThe timer identifier
intervalThe new interval
Returns
0 if successful, -1 if no.

◆ schedule_i() [1/2]

void ACE_Timer_Wheel_T::schedule_i ( ACE_Timer_Node_T< TYPE > *  n,
u_int  spoke,
const ACE_Time_Value expire 
)
private

The shared scheduling functionality between schedule() and reschedule()

◆ schedule_i() [2/2]

long ACE_Timer_Wheel_T::schedule_i ( const TYPE &  type,
const void *  act,
const ACE_Time_Value future_time,
const ACE_Time_Value interval 
)
protectedvirtual

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.

Parameters
typeThe data of the timer node
actAsynchronous Completion Token (AKA magic cookie)
future_timeThe time the timer is scheduled for (absolute time)
intervalIf 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.

◆ unlink()

void ACE_Timer_Wheel_T::unlink ( ACE_Timer_Node_T< TYPE > *  n)
private

Friends And Related Function Documentation

◆ ACE_Timer_Wheel_Iterator_T< TYPE, FUNCTOR, ACE_LOCK, TIME_POLICY >

friend class ACE_Timer_Wheel_Iterator_T< TYPE, FUNCTOR, ACE_LOCK, TIME_POLICY >
friend

Iterator is a friend.

Member Data Documentation

◆ earliest_spoke_

u_int ACE_Timer_Wheel_T::earliest_spoke_
private

Index of the list with the earliest time.

◆ iterator_

Iterator* ACE_Timer_Wheel_T::iterator_
private

Iterator used to expire timers.

◆ res_bits_

int ACE_Timer_Wheel_T::res_bits_
private

Resolution (in microsoconds) of the timing wheel.

◆ spoke_bits_

int ACE_Timer_Wheel_T::spoke_bits_
private

Number of timer_id bits used for the spoke.

◆ spoke_count_

u_int ACE_Timer_Wheel_T::spoke_count_
private

Size of the timing wheel.

◆ spokes_

ACE_Timer_Node_T<TYPE>** ACE_Timer_Wheel_T::spokes_
private

Timing Wheel.

◆ timer_count_

u_int ACE_Timer_Wheel_T::timer_count_
private

The total number of timers currently scheduled.

◆ wheel_time_

ACE_Time_Value ACE_Timer_Wheel_T::wheel_time_
private

The total amount of time in one iteration of the wheel. (resolution * spoke_count)


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