#include <Timer_Queue_T.h>
Inheritance diagram for ACE_Timer_Queue_T:


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) | |
| 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 |
| virtual int | reset_interval (long timer_id, const ACE_Time_Value &interval)=0 |
| virtual int | cancel (const TYPE &type, int dont_call_handle_close=1)=0 |
| virtual int | cancel (long timer_id, const void **act=0, int dont_call_handle_close=1)=0 |
| virtual int | expire (const ACE_Time_Value ¤t_time) |
| int | dispatch_info (const ACE_Time_Value ¤t_time, ACE_Timer_Node_Dispatch_Info_T< TYPE > &info) |
| int | expire (void) |
| ACE_Time_Value | gettimeofday (void) |
| 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. This method acquires a lock internally since it modifies internal state. More... | |
| virtual ACE_Time_Value * | calculate_timeout (ACE_Time_Value *max, ACE_Time_Value *the_timeout) |
| 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 ¤t_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... | |
This is an abstract base class that provides hook for implementing specialized policies such as <ACE_Timer_List> and <ACE_Timer_Heap>.
Definition at line 201 of file Timer_Queue_T.h.
|
|||||
|
Type of Iterator.
Definition at line 205 of file Timer_Queue_T.h. |
|
||||||||||||||||
|
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. Definition at line 151 of file Timer_Queue_T.cpp. References ACE_NEW, ACE_TIMER_SKEW, ACE_TRACE, free_list_, upcall_functor, and upcall_functor_.
00153 : gettimeofday_ (ACE_OS::gettimeofday), 00154 delete_upcall_functor_ (upcall_functor == 0), 00155 delete_free_list_ (freelist == 0), 00156 timer_skew_ (0, ACE_TIMER_SKEW) 00157 { 00158 ACE_TRACE ("ACE_Timer_Queue_T::ACE_Timer_Queue_T"); 00159 00160 if (!freelist) 00161 ACE_NEW (free_list_, 00162 (ACE_Locked_Free_List<ACE_Timer_Node_T<TYPE>,ACE_Null_Mutex>)); 00163 else 00164 free_list_ = freelist; 00165 00166 if (!upcall_functor) 00167 ACE_NEW (upcall_functor_, 00168 FUNCTOR); 00169 else 00170 upcall_functor_ = upcall_functor; 00171 } |
|
||||||||||
|
Destructor - make virtual for proper destruction of inherited classes.
Definition at line 174 of file Timer_Queue_T.cpp. References ACE_TRACE, delete_free_list_, delete_upcall_functor_, free_list_, and upcall_functor_.
00175 {
00176 ACE_TRACE ("ACE_Timer_Queue_T::~ACE_Timer_Queue_T");
00177
00178 // Cleanup the functor and free_list on the way out
00179 if (this->delete_upcall_functor_)
00180 delete this->upcall_functor_;
00181
00182 if (this->delete_free_list_)
00183 delete this->free_list_;
00184 }
|
|
||||||||||
|
|
|
||||||||||
|
Factory method that allocates a new node.
Reimplemented in ACE_Timer_Heap_T. Definition at line 187 of file Timer_Queue_T.cpp. References free_list_, and ACE_Free_List< ACE_Timer_Node_T< TYPE > >::remove. Referenced by ACE_Timer_Wheel_T::schedule, and ACE_Timer_List_T::schedule.
00188 {
00189 return this->free_list_->remove ();
00190 }
|
|
||||||||||||||||
|
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. This method does not acquire a lock internally since it doesn't modify internal state. If you need to call this method when the queue is being modified concurrently, however, you should make sure to acquire the <mutex()> externally before making the call. Definition at line 98 of file Timer_Queue_T.cpp. References ACE_TRACE, earliest_time, gettimeofday, is_empty, and ACE_Time_Value::zero.
00100 {
00101 ACE_TRACE ("ACE_Timer_Queue_T::calculate_timeout");
00102
00103 if (the_timeout == 0)
00104 return 0;
00105
00106 if (this->is_empty ())
00107 {
00108 // Nothing on the Timer_Queue, so use whatever the caller gave us.
00109 if (max_wait_time)
00110 *the_timeout = *max_wait_time;
00111 else
00112 return 0;
00113 }
00114 else
00115 {
00116 ACE_Time_Value cur_time = this->gettimeofday ();
00117
00118 if (this->earliest_time () > cur_time)
00119 {
00120 // The earliest item on the Timer_Queue is still in the
00121 // future. Therefore, use the smaller of (1) caller's wait
00122 // time or (2) the delta time between now and the earliest
00123 // time on the Timer_Queue.
00124
00125 *the_timeout = this->earliest_time () - cur_time;
00126 if (!(max_wait_time == 0 || *max_wait_time > *the_timeout))
00127 *the_timeout = *max_wait_time;
00128 }
00129 else
00130 {
00131 // The earliest item on the Timer_Queue is now in the past.
00132 // Therefore, we've got to "poll" the Reactor, i.e., it must
00133 // just check the descriptors and then dispatch timers, etc.
00134 *the_timeout = ACE_Time_Value::zero;
00135 }
00136 }
00137 return the_timeout;
00138 }
|
|
||||||||||
|
Determine the next event to timeout. Returns <max> if there are no pending timers or if all pending timers are longer than max. This method acquires a lock internally since it modifies internal state.
Definition at line 61 of file Timer_Queue_T.cpp. References ACE_GUARD_RETURN, ACE_MT, ACE_TRACE, earliest_time, gettimeofday, is_empty, timeout_, and ACE_Time_Value::zero.
00062 {
00063 ACE_TRACE ("ACE_Timer_Queue_T::calculate_timeout");
00064 ACE_MT (ACE_GUARD_RETURN (ACE_LOCK, ace_mon, this->mutex_, max_wait_time));
00065
00066 if (this->is_empty ())
00067 // Nothing on the Timer_Queue, so use whatever the caller gave us.
00068 return max_wait_time;
00069 else
00070 {
00071 ACE_Time_Value cur_time = this->gettimeofday ();
00072
00073 if (this->earliest_time () > cur_time)
00074 {
00075 // The earliest item on the Timer_Queue is still in the
00076 // future. Therefore, use the smaller of (1) caller's wait
00077 // time or (2) the delta time between now and the earliest
00078 // time on the Timer_Queue.
00079
00080 this->timeout_ = this->earliest_time () - cur_time;
00081 if (max_wait_time == 0 || *max_wait_time > timeout_)
00082 return &this->timeout_;
00083 else
00084 return max_wait_time;
00085 }
00086 else
00087 {
00088 // The earliest item on the Timer_Queue is now in the past.
00089 // Therefore, we've got to "poll" the Reactor, i.e., it must
00090 // just check the descriptors and then dispatch timers, etc.
00091 this->timeout_ = ACE_Time_Value::zero;
00092 return &this->timeout_;
00093 }
00094 }
00095 }
|
|
||||||||||||||||||||
|
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. Implemented in ACE_Timer_Hash_T. |
|
||||||||||||||||
|
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. Implemented in ACE_Timer_Hash_T. Referenced by ACE_Event_Handler_Handle_Timeout_Upcall::timeout. |
|
||||||||||||||||
|
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. Definition at line 153 of file Timer_Queue_T.i. References ACE_GUARD_RETURN, ACE_MT, ACE_TRACE, and dispatch_info_i.
00155 {
00156 ACE_TRACE ("ACE_Timer_Queue_T::dispatch_info");
00157 ACE_MT (ACE_GUARD_RETURN (ACE_LOCK, ace_mon, this->mutex_, 0));
00158
00159 return this->dispatch_info_i (cur_time, info);
00160 }
|
|
||||||||||||||||
|
Non-locking version of dispatch_info ().
Definition at line 240 of file Timer_Queue_T.cpp. References ACE_TRACE, earliest_time, free_node, ACE_Timer_Node_T::get_dispatch_info, ACE_Timer_Node_T::get_interval, ACE_Timer_Node_T::get_timer_value, is_empty, remove_first, reschedule, ACE_Timer_Node_T::set_timer_value, and ACE_Time_Value::zero. Referenced by dispatch_info, and expire.
00242 {
00243 ACE_TRACE ("ACE_Timer_Queue_T::dispatch_info_i");
00244
00245 if (this->is_empty ())
00246 return 0;
00247
00248 ACE_Timer_Node_T<TYPE> *expired = 0;
00249
00250 if (this->earliest_time () <= cur_time)
00251 {
00252 expired = this->remove_first ();
00253
00254 // Get the dispatch info
00255 expired->get_dispatch_info (info);
00256
00257 // Check if this is an interval timer.
00258 if (expired->get_interval () > ACE_Time_Value::zero)
00259 {
00260 // Make sure that we skip past values that have already
00261 // "expired".
00262 do
00263 expired->set_timer_value (expired->get_timer_value () + expired->get_interval ());
00264 while (expired->get_timer_value () <= cur_time);
00265
00266 // Since this is an interval timer, we need to reschedule
00267 // it.
00268 this->reschedule (expired);
00269 }
00270 else
00271 {
00272 // Call the factory method to free up the node.
00273 this->free_node (expired);
00274 }
00275
00276 return 1;
00277 }
00278
00279 return 0;
00280 }
|
|
||||||||||
|
Dump the state of a object.
Reimplemented in ACE_Timer_Hash_T. Definition at line 141 of file Timer_Queue_T.cpp. References ACE_BEGIN_DUMP, ACE_DEBUG, ACE_END_DUMP, ACE_TRACE, ACE_Time_Value::dump, LM_DEBUG, timeout_, and timer_skew_.
00142 {
00143 ACE_TRACE ("ACE_Timer_Queue_T::dump");
00144 ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
00145 this->timeout_.dump ();
00146 this->timer_skew_.dump ();
00147 ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00148 }
|
|
||||||||||
|
Returns the time of the earlier node in the Timer_Queue. Must be called on a non-empty queue.
Implemented in ACE_Timer_Hash_T. Referenced by calculate_timeout, and dispatch_info_i. |
|
||||||||||
|
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. Definition at line 144 of file Timer_Queue_T.i. References is_empty, and timer_skew_. Referenced by ACE_Timer_Wheel_T::expire, and ACE_Timer_Hash_T::expire.
00145 {
00146 if (!this->is_empty ())
00147 return this->expire (this->gettimeofday () + timer_skew_);
00148 else
00149 return 0;
00150 }
|
|
||||||||||
|
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. Definition at line 208 of file Timer_Queue_T.cpp. References ACE_GUARD_RETURN, ACE_MT, ACE_TRACE, ACE_Timer_Node_Dispatch_Info_T::act_, dispatch_info_i, is_empty, ACE_Timer_Node_Dispatch_Info_T::type_, and upcall.
00209 {
00210 ACE_TRACE ("ACE_Timer_Queue_T::expire");
00211 ACE_MT (ACE_GUARD_RETURN (ACE_LOCK, ace_mon, this->mutex_, -1));
00212
00213 // Keep looping while there are timers remaining and the earliest
00214 // timer is <= the <cur_time> passed in to the method.
00215
00216 if (this->is_empty ())
00217 return 0;
00218
00219 int number_of_timers_expired = 0;
00220 int result = 0;
00221
00222 ACE_Timer_Node_Dispatch_Info_T<TYPE> info;
00223
00224 while ((result = this->dispatch_info_i (cur_time,
00225 info)) != 0)
00226 {
00227 // call the functor
00228 this->upcall (info.type_, info.act_, cur_time);
00229
00230 number_of_timers_expired++;
00231
00232 }
00233
00234 ACE_UNUSED_ARG (result);
00235 return number_of_timers_expired;
00236 }
|
|
||||||||||
|
Factory method that frees a previously allocated node.
Reimplemented in ACE_Timer_Heap_T. Definition at line 193 of file Timer_Queue_T.cpp. References ACE_Free_List< ACE_Timer_Node_T< TYPE > >::add, and free_list_. Referenced by ACE_Timer_Wheel_T::cancel_i, ACE_Timer_List_T::cancel_i, dispatch_info_i, ACE_Timer_Wheel_T::expire, return_node, ACE_Timer_List_T::~ACE_Timer_List_T, and ACE_Timer_Wheel_T::~ACE_Timer_Wheel_T.
00194 {
00195 this->free_list_->add (node);
00196 }
|
|
||||||||||
|
Reads the earliest node from the queue and returns it.
Implemented in ACE_Timer_Hash_T. |
|
||||||||||
|
Allows applications to control how the timer queue gets the time of day.
Definition at line 179 of file Timer_Queue_T.i. References gettimeofday, and gettimeofday_.
00180 {
00181 this->gettimeofday_ = gettimeofday;
00182 }
|
|
||||||||||
|
Returns the current time of day. This method allows different implementations of the timer queue to use special high resolution timers. Definition at line 172 of file Timer_Queue_T.i. References gettimeofday_. Referenced by ACE_Timer_Hash_T::ACE_Timer_Hash_T, calculate_timeout, and gettimeofday.
00173 {
00174 // Invoke gettimeofday via pointer to function.
00175 return this->gettimeofday_ ();
00176 }
|
|
||||||||||
|
True if queue is empty, else false.
Implemented in ACE_Timer_Hash_T. Referenced by calculate_timeout, dispatch_info_i, and expire. |
|
||||||||||
|
Returns a pointer to this <ACE_Timer_Queue>'s iterator.
Implemented in ACE_Timer_Hash_T. |
|
||||||||||
|
Synchronization variable used by the queue.
Definition at line 199 of file Timer_Queue_T.cpp. References mutex_.
00200 {
00201 return this->mutex_;
00202 }
|
|
||||||||||
|
|
|
||||||||||
|
Removes the earliest node from the queue and returns it.
Implemented in ACE_Timer_Hash_T. Referenced by dispatch_info_i. |
|
||||||||||
|
Reschedule an "interval" <ACE_Timer_Node>.
Implemented in ACE_Timer_Hash_T. Referenced by dispatch_info_i. |
|
||||||||||||||||
|
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. Implemented in ACE_Timer_Hash_T. |
|
||||||||||
|
Method used to return a timer node to the queue's ownership after it is returned by a method like <remove_first>.
Definition at line 284 of file Timer_Queue_T.cpp. References ACE_GUARD, ACE_MT, and free_node.
|
|
||||||||||||||||||||||||
|
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>). Implemented in ACE_Timer_Hash_T. |
|
||||||||||
|
Get the timer skew for the Timer_Queue.
Definition at line 138 of file Timer_Queue_T.i. References timer_skew_.
00139 {
00140 return timer_skew_;
00141 }
|
|
||||||||||
|
Set the timer skew for the Timer_Queue.
Definition at line 132 of file Timer_Queue_T.i. References timer_skew_.
00133 {
00134 timer_skew_ = skew;
00135 }
|
|
||||||||||||||||||||
|
This method will call the <functor> with the <type>, <act> and <cur_time>.
Definition at line 163 of file Timer_Queue_T.i. References upcall_functor. Referenced by ACE_Timer_Wheel_T::expire, expire, and ACE_Timer_Hash_T::expire.
00166 {
00167 this->upcall_functor ().timeout (*this, type, act, cur_time);
00168 }
|
|
||||||||||
|
Accessor to the upcall functor.
Definition at line 185 of file Timer_Queue_T.i. References upcall_functor_. Referenced by ACE_Timer_Queue_T, ACE_Timer_Wheel_T::cancel, ACE_Timer_List_T::cancel, ACE_Timer_Heap_T::cancel, ACE_Timer_Hash_T::cancel, ACE_Timer_Wheel_T::cancel_i, ACE_Timer_List_T::cancel_i, upcall, ACE_Timer_Heap_T::~ACE_Timer_Heap_T, ACE_Timer_List_T::~ACE_Timer_List_T, and ACE_Timer_Wheel_T::~ACE_Timer_Wheel_T.
00186 {
00187 return *this->upcall_functor_;
00188 }
|
|
|||||
|
Flag to delete only if the class created the <free_list_>.
Definition at line 431 of file Timer_Queue_T.h. Referenced by ~ACE_Timer_Queue_T. |
|
|||||
|
To delete or not to delete is the question?
Definition at line 428 of file Timer_Queue_T.h. Referenced by ~ACE_Timer_Queue_T. |
|
|||||
|
Class that implements a free list.
Definition at line 419 of file Timer_Queue_T.h. Referenced by ACE_Timer_Queue_T, alloc_node, free_node, and ~ACE_Timer_Queue_T. |
|
|||||
|
Pointer to function that returns the current time of day.
Referenced by gettimeofday. |
|
|||||
|
Synchronization variable for <ACE_Timer_Queue>. NOTE: the right name would be lock_, but HP/C++ will choke on that!
Definition at line 416 of file Timer_Queue_T.h. Referenced by mutex. |
|
|||||
|
Returned by <calculate_timeout>.
Definition at line 436 of file Timer_Queue_T.h. Referenced by calculate_timeout, and dump. |
|
|||||
|
Adjusts for timer skew in various clocks.
Definition at line 439 of file Timer_Queue_T.h. Referenced by dump, expire, and timer_skew. |
|
|||||
|
Upcall functor.
Definition at line 425 of file Timer_Queue_T.h. Referenced by ACE_Timer_Queue_T, upcall_functor, and ~ACE_Timer_Queue_T. |
1.2.14 written by Dimitri van Heesch,
© 1997-2002