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

# ACE_Timer_Queue_T Class Template Reference

Provides an interface to timers. More...

`#include <Timer_Queue_T.h>`

Inheritance diagram for ACE_Timer_Queue_T:

[legend]
Collaboration diagram for ACE_Timer_Queue_T:

[legend]
List of all members.

## Public Types
typedef ACE_Timer_Queue_Iterator_T< TYPE, FUNCTOR, ACE_LOCK > | ITERATOR
| Type of Iterator. More...
## Public Methods
| ACE_Timer_Queue_T (FUNCTOR *upcall_functor=0, ACE_Free_List< ACE_Timer_Node_T< TYPE > > *freelist=0)
| Default constructor. More...
virtual | ~ACE_Timer_Queue_T (void)
| Destructor - make virtual for proper destruction of inherited classes. More...
virtual int | is_empty (void) const=0
| True if queue is empty, else false. More...
virtual const ACE_Time_Value & | earliest_time (void) const=0
| Returns the time of the earlier node in the Timer_Queue. Must be called on a non-empty queue. More...
virtual long | schedule (const TYPE &type, const void *act, const ACE_Time_Value &future_time, const ACE_Time_Value &interval=ACE_Time_Value::zero)=0
| Schedule <type> that will expire at <future_time>, which is specified in absolute time. More...
virtual int | reset_interval (long timer_id, const ACE_Time_Value &interval)=0
| Resets the interval of the timer represented by <timer_id> to <interval>, which is specified in relative time to the current <gettimeofday>. More...
virtual int | cancel (const TYPE &type, int dont_call_handle_close=1)=0
| Cancel all timer associated with <type>. More...
virtual int | cancel (long timer_id, const void **act=0, int dont_call_handle_close=1)=0
| Cancel the single timer that matches the <timer_id> value (which was returned from the <schedule> method). More...
virtual int | expire (const ACE_Time_Value &current_time)
| Run the <functor> for all timers whose values are <= <cur_time>. More...
int | dispatch_info (const ACE_Time_Value &current_time, ACE_Timer_Node_Dispatch_Info_T< TYPE > &info)
| Get the dispatch information for a timer whose value is <= <cur_time>. More...
int | expire (void)
| Run the <functor> for all timers whose values are <= <ACE_OS::gettimeofday>. More...
ACE_Time_Value | gettimeofday (void)
| Returns the current time of day. More...
void | gettimeofday (ACE_Time_Value(*gettimeofday)(void))
| Allows applications to control how the timer queue gets the time of day. More...
virtual ACE_Time_Value * | calculate_timeout (ACE_Time_Value *max)
| Determine the next event to timeout. Returns <max> if there are no pending timers or if all pending timers are longer than max. More...
virtual ACE_Time_Value * | calculate_timeout (ACE_Time_Value *max, ACE_Time_Value *the_timeout)
| Determine the next event to timeout. More...
void | timer_skew (const ACE_Time_Value &skew)
| Set the timer skew for the Timer_Queue. More...
const ACE_Time_Value & | timer_skew (void) const
| Get the timer skew for the Timer_Queue. More...
ACE_LOCK & | mutex (void)
| Synchronization variable used by the queue. More...
FUNCTOR & | upcall_functor (void)
| Accessor to the upcall functor. More...
virtual ITERATOR & | iter (void)=0
| Returns a pointer to this <ACE_Timer_Queue>'s iterator. More...
virtual ACE_Timer_Node_T< TYPE > * | remove_first (void)=0
| Removes the earliest node from the queue and returns it. More...
virtual void | dump (void) const
| Dump the state of a object. More...
virtual ACE_Timer_Node_T< TYPE > * | get_first (void)=0
| Reads the earliest node from the queue and returns it. More...
virtual void | return_node (ACE_Timer_Node_T< TYPE > *)
| Method used to return a timer node to the queue's ownership after it is returned by a method like <remove_first>. More...
void | upcall (TYPE &type, const void *act, const ACE_Time_Value &cur_time)
| This method will call the <functor> with the <type>, <act> and <cur_time>. More...
## Protected Methods
virtual void | reschedule (ACE_Timer_Node_T< TYPE > *)=0
| Reschedule an "interval" <ACE_Timer_Node>. More...
virtual ACE_Timer_Node_T< TYPE > * | alloc_node (void)
| Factory method that allocates a new node. More...
virtual void | free_node (ACE_Timer_Node_T< TYPE > *)
| Factory method that frees a previously allocated node. More...
int | dispatch_info_i (const ACE_Time_Value &current_time, ACE_Timer_Node_Dispatch_Info_T< TYPE > &info)
| Non-locking version of dispatch_info (). More...
## Protected Attributes
ACE_LOCK | mutex_
| Synchronization variable for <ACE_Timer_Queue>. NOTE: the right name would be lock_, but HP/C++ will choke on that! More...
ACE_Free_List< ACE_Timer_Node_T< TYPE > > * | free_list_
| Class that implements a free list. More...
ACE_Time_Value(* | gettimeofday_ )(void)
| Pointer to function that returns the current time of day. More...
FUNCTOR * | upcall_functor_
| Upcall functor. More...
int | delete_upcall_functor_
| To delete or not to delete is the question? More...
int | delete_free_list_
| Flag to delete only if the class created the <free_list_>. More...
## Private Methods
| ACE_Timer_Queue_T (const ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK > &)
void | operator= (const ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK > &)
## Private Attributes
ACE_Time_Value | timeout_
| Returned by <calculate_timeout>. More...
ACE_Time_Value | timer_skew_
| Adjusts for timer skew in various clocks. More...

## Detailed Description

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

Provides an interface to timers.

This is an abstract base class that provides hook for implementing specialized policies such as <ACE_Timer_List> and <ACE_Timer_Heap>.

## Member Typedef Documentation

template<class TYPE, class FUNCTOR, class ACE_LOCK>
typedef ACE_Timer_Queue_Iterator_T<TYPE, FUNCTOR, ACE_LOCK> ACE_Timer_Queue_T::ITERATOR

| Type of Iterator.

## Constructor & Destructor Documentation

template<class TYPE, class FUNCTOR, class ACE_LOCK>
ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >::ACE_Timer_Queue_T | ( | FUNCTOR * | upcall_functor = 0,
|  | ACE_Free_List< ACE_Timer_Node_T< TYPE > > * | freelist = 0
| ) |

| Default constructor. <upcall_functor> is the instance of the FUNCTOR to be used by the queue. If <upcall_functor> is 0, Timer Queue will create a default FUNCTOR. <freelist> the freelist of timer nodes. If 0, then a default freelist will be created.

template<class TYPE, class FUNCTOR, class ACE_LOCK>
ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >::~ACE_Timer_Queue_T | ( | void |  | ) | `[virtual]`

| Destructor - make virtual for proper destruction of inherited classes.

template<class TYPE, class FUNCTOR, class ACE_LOCK>
ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >::ACE_Timer_Queue_T | ( | const ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK > & |  | ) | `[private]`

## Member Function Documentation

template<class TYPE, class FUNCTOR, class ACE_LOCK>
ACE_Timer_Node_T< TYPE > * ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >::alloc_node | ( | void |  | ) | `[protected, virtual]`

| Factory method that allocates a new node. Reimplemented in ACE_Timer_Heap_T.

template<class TYPE, class FUNCTOR, class ACE_LOCK>
ACE_Time_Value * ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >::calculate_timeout | ( | ACE_Time_Value * | max_wait_time,
|  | ACE_Time_Value * | the_timeout
| ) | `[virtual]`

| Determine the next event to timeout. Returns <max> if there are no pending timers or if all pending timers are longer than max. <the_timeout> should be a pointer to storage for the timeout value, and this value is also returned.

template<class TYPE, class FUNCTOR, class ACE_LOCK>
ACE_Time_Value * ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >::calculate_timeout | ( | ACE_Time_Value * | max_wait_time | ) | `[virtual]`

| Determine the next event to timeout. Returns <max> if there are no pending timers or if all pending timers are longer than max.

template<class TYPE, class FUNCTOR, class ACE_LOCK>
virtual int ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >::cancel | ( | long | timer_id,
|  | const void ** | act = 0,
|  | int | skip_close = 1
| ) | `[pure virtual]`

| Cancel the single timer that matches the <timer_id> value (which was returned from the <schedule> method). If act is non-NULL then it will be set to point to the ``magic cookie'' argument passed in when the timer was registered. This makes it possible to free up the memory and avoid memory leaks. If <dont_call_handle_close> is 0 then the <functor> will be invoked, which typically calls the <handle_close> hook. Returns 1 if cancellation succeeded and 0 if the <timer_id> wasn't found. Reimplemented in ACE_Timer_Hash_T, ACE_Timer_Heap_T, ACE_Timer_List_T, and ACE_Timer_Wheel_T.

template<class TYPE, class FUNCTOR, class ACE_LOCK>
virtual int ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >::cancel | ( | const TYPE & | type,
|  | int | skip_close = 1
| ) | `[pure virtual]`

| Cancel all timer associated with <type>. If <dont_call_handle_close> is 0 then the <functor> will be invoked, which typically invokes the <handle_close> hook. Returns number of timers cancelled. Reimplemented in ACE_Timer_Hash_T, ACE_Timer_Heap_T, ACE_Timer_List_T, and ACE_Timer_Wheel_T.

template<class TYPE, class FUNCTOR, class ACE_LOCK>
int ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >::dispatch_info | ( | const ACE_Time_Value & | cur_time,
|  | ACE_Timer_Node_Dispatch_Info_T< TYPE > & | info
| ) |

| Get the dispatch information for a timer whose value is <= <cur_time>. This does not account for <timer_skew>. Returns 1 if there is a node whose value <= <cur_time> else returns a 0.

template<class TYPE, class FUNCTOR, class ACE_LOCK>
int ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >::dispatch_info_i | ( | const ACE_Time_Value & | cur_time,
|  | ACE_Timer_Node_Dispatch_Info_T< TYPE > & | info
| ) | `[protected]`

| Non-locking version of dispatch_info ().

template<class TYPE, class FUNCTOR, class ACE_LOCK>
void ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >::dump | ( | void |  | ) | const`[virtual]`

| Dump the state of a object. Reimplemented in ACE_Timer_Hash_T, ACE_Timer_Heap_T, ACE_Timer_List_T, and ACE_Timer_Wheel_T.

template<class TYPE, class FUNCTOR, class ACE_LOCK>
virtual const ACE_Time_Value& ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >::earliest_time | ( | void |  | ) | const`[pure virtual]`

| Returns the time of the earlier node in the Timer_Queue. Must be called on a non-empty queue. Reimplemented in ACE_Timer_Hash_T, ACE_Timer_Heap_T, ACE_Timer_List_T, and ACE_Timer_Wheel_T.

template<class TYPE, class FUNCTOR, class ACE_LOCK>
ACE_INLINE int ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >::expire | ( | void |  | ) |

| Run the <functor> for all timers whose values are <= <ACE_OS::gettimeofday>. Also accounts for <timer_skew>. Depending on the resolution of the underlying OS the system calls like select()/poll() might return at time different than that is specified in the timeout. Suppose the OS guarantees a resolution of t ms. The timeline will look like A B | | V V |-------------|-------------|-------------|-------------| t t t t t If you specify a timeout value of A, then the timeout will not occur at A but at the next interval of the timer, which is later than that is expected. Similarly, if your timeout value is equal to B, then the timeout will occur at interval after B. Now depending upon the resolution of your timeouts and the accuracy of the timeouts needed for your application, you should set the value of <timer_skew>. In the above case, if you want the timeout A to fire no later than A, then you should specify your <timer_skew> to be A % t. The timeout value should be specified via the macro ACE_TIMER_SKEW in your config.h file. The default value is zero. Things get interesting if the t before the timeout value B is zero i.e your timeout is less than the interval. In that case, you are almost sure of not getting the desired timeout behaviour. Maybe you should look for a better OS :-) Returns the number of timers canceled. Reimplemented in ACE_Timer_Hash_T, and ACE_Timer_Wheel_T.

template<class TYPE, class FUNCTOR, class ACE_LOCK>
int ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >::expire | ( | const ACE_Time_Value & | cur_time | ) | `[virtual]`

| Run the <functor> for all timers whose values are <= <cur_time>. This does not account for <timer_skew>. Returns the number of timers canceled. Reimplemented in ACE_Timer_Hash_T, and ACE_Timer_Wheel_T.

template<class TYPE, class FUNCTOR, class ACE_LOCK>
void ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >::free_node | ( | ACE_Timer_Node_T< TYPE > * | node | ) | `[protected, virtual]`

| Factory method that frees a previously allocated node. Reimplemented in ACE_Timer_Heap_T.

template<class TYPE, class FUNCTOR, class ACE_LOCK>
virtual ACE_Timer_Node_T<TYPE>* ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >::get_first | ( | void |  | ) | `[pure virtual]`

| Reads the earliest node from the queue and returns it. Reimplemented in ACE_Timer_Hash_T, ACE_Timer_Heap_T, ACE_Timer_List_T, and ACE_Timer_Wheel_T.

template<class TYPE, class FUNCTOR, class ACE_LOCK>
ACE_INLINE void ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >::gettimeofday | ( | ACE_Time_Value(* | gettimeofday)(void) | ) |

| Allows applications to control how the timer queue gets the time of day.

template<class TYPE, class FUNCTOR, class ACE_LOCK>
ACE_INLINE ACE_Time_Value ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >::gettimeofday | ( | void |  | ) |

| Returns the current time of day. This method allows different implementations of the timer queue to use special high resolution timers.

template<class TYPE, class FUNCTOR, class ACE_LOCK>
virtual int ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >::is_empty | ( | void |  | ) | const`[pure virtual]`

| True if queue is empty, else false. Reimplemented in ACE_Timer_Hash_T, ACE_Timer_Heap_T, ACE_Timer_List_T, and ACE_Timer_Wheel_T.

template<class TYPE, class FUNCTOR, class ACE_LOCK>
virtual ITERATOR& ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >::iter | ( | void |  | ) | `[pure virtual]`

| Returns a pointer to this <ACE_Timer_Queue>'s iterator. Reimplemented in ACE_Timer_Hash_T, ACE_Timer_Heap_T, ACE_Timer_List_T, and ACE_Timer_Wheel_T.

template<class TYPE, class FUNCTOR, class ACE_LOCK>
ACE_LOCK & ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >::mutex | ( | void |  | ) |

| Synchronization variable used by the queue.

template<class TYPE, class FUNCTOR, class ACE_LOCK>
void ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >::operator= | ( | const ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK > & |  | ) | `[private]`

template<class TYPE, class FUNCTOR, class ACE_LOCK>
virtual ACE_Timer_Node_T<TYPE>* ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >::remove_first | ( | void |  | ) | `[pure virtual]`

| Removes the earliest node from the queue and returns it. Reimplemented in ACE_Timer_Hash_T, ACE_Timer_Heap_T, ACE_Timer_List_T, and ACE_Timer_Wheel_T.

template<class TYPE, class FUNCTOR, class ACE_LOCK>
virtual void ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >::reschedule | ( | ACE_Timer_Node_T< TYPE > * | expired | ) | `[protected, pure virtual]`

| Reschedule an "interval" <ACE_Timer_Node>. Reimplemented in ACE_Timer_Hash_T, ACE_Timer_Heap_T, ACE_Timer_List_T, and ACE_Timer_Wheel_T.

template<class TYPE, class FUNCTOR, class ACE_LOCK>
virtual int ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >::reset_interval | ( | long | timer_id,
|  | const ACE_Time_Value & | interval
| ) | `[pure virtual]`

| Resets the interval of the timer represented by <timer_id> to <interval>, which is specified in relative time to the current <gettimeofday>. If <interval> is equal to <ACE_Time_Value::zero>, the timer will become a non-rescheduling timer. Returns 0 if successful, -1 if not. Reimplemented in ACE_Timer_Hash_T, ACE_Timer_Heap_T, ACE_Timer_List_T, and ACE_Timer_Wheel_T.

template<class TYPE, class FUNCTOR, class ACE_LOCK>
void ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >::return_node | ( | ACE_Timer_Node_T< TYPE > * | node | ) | `[virtual]`

| Method used to return a timer node to the queue's ownership after it is returned by a method like <remove_first>.

template<class TYPE, class FUNCTOR, class ACE_LOCK>
virtual long ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >::schedule | ( | const TYPE & | type,
|  | const void * | act,
|  | const ACE_Time_Value & | future_time,
|  | const ACE_Time_Value & | interval = ACE_Time_Value::zero
| ) | `[pure virtual]`

| Schedule <type> that will expire at <future_time>, which is specified in absolute time. If it expires then <act> is passed in as the value to the <functor>. If <interval> is != to <ACE_Time_Value::zero> then it is used to reschedule the <type> automatically, using relative time to the current <gettimeofday>. This method returns a <timer_id> that uniquely identifies the the <type> entry in an internal list. This <timer_id> can be used to cancel the timer before it expires. The cancellation ensures that <timer_ids> are unique up to values of greater than 2 billion timers. As long as timers don't stay around longer than this there should be no problems with accidentally deleting the wrong timer. Returns -1 on failure (which is guaranteed never to be a valid <timer_id>). Reimplemented in ACE_Timer_Hash_T, ACE_Timer_Heap_T, ACE_Timer_List_T, and ACE_Timer_Wheel_T.

template<class TYPE, class FUNCTOR, class ACE_LOCK>
ACE_INLINE const ACE_Time_Value & ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >::timer_skew | ( | void |  | ) | const

| Get the timer skew for the Timer_Queue.

template<class TYPE, class FUNCTOR, class ACE_LOCK>
ACE_INLINE void ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >::timer_skew | ( | const ACE_Time_Value & | skew | ) |

| Set the timer skew for the Timer_Queue.

template<class TYPE, class FUNCTOR, class ACE_LOCK>
ACE_INLINE void ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >::upcall | ( | TYPE & | type,
|  | const void * | act,
|  | const ACE_Time_Value & | cur_time
| ) |

| This method will call the <functor> with the <type>, <act> and <cur_time>.

template<class TYPE, class FUNCTOR, class ACE_LOCK>
ACE_INLINE FUNCTOR & ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >::upcall_functor | ( | void |  | ) |

| Accessor to the upcall functor.

## Member Data Documentation

template<class TYPE, class FUNCTOR, class ACE_LOCK>
int ACE_Timer_Queue_T::delete_free_list_`[protected]`

| Flag to delete only if the class created the <free_list_>.

template<class TYPE, class FUNCTOR, class ACE_LOCK>
int ACE_Timer_Queue_T::delete_upcall_functor_`[protected]`

| To delete or not to delete is the question?

template<class TYPE, class FUNCTOR, class ACE_LOCK>
ACE_Free_List<ACE_Timer_Node_T<TYPE> >* ACE_Timer_Queue_T::free_list_`[protected]`

| Class that implements a free list.

template<class TYPE, class FUNCTOR, class ACE_LOCK>
ACE_Time_Value(* ACE_Timer_Queue_T::gettimeofday_)(void)`[protected]`

| Pointer to function that returns the current time of day.

template<class TYPE, class FUNCTOR, class ACE_LOCK>
ACE_LOCK ACE_Timer_Queue_T::mutex_`[protected]`

| Synchronization variable for <ACE_Timer_Queue>. NOTE: the right name would be lock_, but HP/C++ will choke on that!

template<class TYPE, class FUNCTOR, class ACE_LOCK>
ACE_Time_Value ACE_Timer_Queue_T::timeout_`[private]`

| Returned by <calculate_timeout>.

template<class TYPE, class FUNCTOR, class ACE_LOCK>
ACE_Time_Value ACE_Timer_Queue_T::timer_skew_`[private]`

| Adjusts for timer skew in various clocks.

template<class TYPE, class FUNCTOR, class ACE_LOCK>
FUNCTOR* ACE_Timer_Queue_T::upcall_functor_`[protected]`

| Upcall functor.

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

- Timer_Queue_T.h
- Timer_Queue_T.cpp
- Timer_Queue_T.i