NAME
ACE_Timer_Queue
SYNOPSIS
#include <ace/Timer_Queue.h>
class ACE_Timer_Queue
{
public:
ACE_Timer_Queue (void);
virtual ~ACE_Timer_Queue (void);
int is_empty (void) const;
const ACE_Time_Value &earliest_time (void) const;
int schedule (
ACE_Event_Handler *event_handler,
const void *arg,
const ACE_Time_Value &delay,
const ACE_Time_Value &interval = ACE_Time_Value::zero
);
int cancel (ACE_Event_Handler *event_handler);
int cancel (int timer_id, const void **arg = 0);
int expire (const ACE_Time_Value ¤t_time);
ACE_Time_Value *calculate_timeout (ACE_Time_Value *max);
void dump (void) const;
ACE_ALLOC_HOOK_DECLARE;
private:
ACE_Time_Value timeout_;
void reschedule (ACE_Timer_Node *);
ACE_Timer_Node *head_;
int timer_id_;
ACE_Recursive_Thread_Mutex lock_;
};
DESCRIPTION
This is a simple implementation that uses a linked list of
absolute times. A more clever implementation would use a
delta-list, a heap, or timing wheels.
Initialization and termination methods.
ACE_Timer_Queue (void);
virtual ~ACE_Timer_Queue (void);
int is_empty (void) const;
True if queue is empty, else false.
const ACE_Time_Value &earliest_time (void) const;
Returns the time of the earlier node in the Timer_Queue.
int schedule (
ACE_Event_Handler *event_handler,
const void *arg,
const ACE_Time_Value &delay,
const ACE_Time_Value &interval = ACE_Time_Value::zero
);
Schedule an event_handler that will expire after delay amount
of time. If it expires then arg is passed in as the value to
the event_handler's handle_timeout callback method. If
interval is != to ACE_Time_Value::zero then it is used to
reschedule the event_handler automatically. This method
returns a timer handle that uniquely identifies the
event_handler in an internal list. This timer handle can be
used to cancel an event_handler 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.
int cancel (ACE_Event_Handler *event_handler);
Cancel all event_handlers that match the address of
event_handler.
int cancel (int timer_id, const void **arg = 0);
Cancel the single ACE_Event_Handler that matches the timer_id
value (which was returned from the schedule method). If arg is
non-NULL then it will be set to point to the ``magic cookie''
argument passed in when the Event_Handler was registered. This
makes it possible to free up the memory and avoid memory leaks.
int expire (const ACE_Time_Value ¤t_time);
Run the handle_timeout method for all Timers whose values are
= cur_time.
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.
void dump (void) const;
Dump the state of an object.
ACE_ALLOC_HOOK_DECLARE;
Declare the dynamic allocation hooks.
AUTHOR
Doug Schmidt
TITLE
Provides an interface to timers.
LIBRARY
ace