#include <Timer_List_T.h>
Inheritance diagram for ACE_Timer_List_T:


Public Types | |
| typedef ACE_Timer_List_Iterator_T< TYPE, FUNCTOR, ACE_LOCK > | Iterator |
| Type of iterator. More... | |
| typedef ACE_Timer_Node_T< TYPE > | Node |
| typedef ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK > | Base |
| Type inherited from. More... | |
| typedef ACE_Free_List< Node > | FreeList |
Public Methods | |
| ACE_Timer_List_T (FUNCTOR *upcall_functor=0, FreeList *freelist=0) | |
| virtual | ~ACE_Timer_List_T (void) |
| Destructor. More... | |
| 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 <ACE_Timer_List>. 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) |
| 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 ACE_Timer_Queue_Iterator_T< TYPE, FUNCTOR, ACE_LOCK > & | iter (void) |
| Returns a pointer to this <ACE_Timer_Queue>'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 void | reschedule (ACE_Timer_Node_T< TYPE > *) |
| Reschedule an "interval" <ACE_Timer_Node>. This should be private but for now it needs to be public for <ACE_Timer_Hash_T>. More... | |
| virtual ACE_Timer_Node_T< TYPE > * | get_first (void) |
| Reads the earliest node from the queue and returns it. More... | |
Private Methods | |
| void | schedule_i (ACE_Timer_Node_T< TYPE > *n, const ACE_Time_Value &exp) |
| The shared scheduling functionality between schedule() and reschedule(). More... | |
| ACE_Timer_Node_T< TYPE > * | find_node (long timer_id) const |
| void | cancel_i (ACE_Timer_Node_T< TYPE > *n, int skip_close) |
| Shared subset of the two cancel() methods. More... | |
| void | unlink (ACE_Timer_Node_T< TYPE > *n) |
| ACE_Timer_Node_T< TYPE > * | get_first_i (void) const |
| ACE_Timer_List_T (const ACE_Timer_List_T< TYPE, FUNCTOR, ACE_LOCK > &) | |
| void | operator= (const ACE_Timer_List_T< TYPE, FUNCTOR, ACE_LOCK > &) |
Private Attributes | |
| ACE_Timer_Node_T< TYPE > * | head_ |
| Pointer to linked list of <ACE_Timer_Handles>. More... | |
| Iterator * | iterator_ |
| Iterator used to expire timers. More... | |
| long | id_counter_ |
Friends | |
| class | ACE_Timer_List_Iterator_T< TYPE, FUNCTOR, ACE_LOCK > |
| Iterator is a friend. More... | |
This implementation uses a linked list of absolute times. Therefore, in the average case, scheduling and canceling timers is O(N) (where N is the total number of timers) and expiring timers is O(K) (where K is the total number of timers that are < the current time of day). More clever implementations could use a delta-list, a heap, or timing wheels, etc. For instance, <ACE_Timer_Heap> is a subclass of <ACE_Timer_List> that implements a heap-based callout queue. For most applications, the <ACE_Timer_Heap> will perform substantially faster than the <ACE_Timer_List>.
Definition at line 85 of file Timer_List_T.h.
|
|||||
|
Type inherited from.
Definition at line 96 of file Timer_List_T.h. |
|
|||||
|
Definition at line 97 of file Timer_List_T.h. |
|
|||||
|
Type of iterator.
Definition at line 89 of file Timer_List_T.h. Referenced by ACE_Timer_List_T. |
|
|||||
|
Definition at line 94 of file Timer_List_T.h. |
|
||||||||||||||||
|
Default constructor. <upcall_functor> is the instance of the FUNCTOR to be used by the list. If <upcall_functor> is 0, a default FUNCTOR will be created. <freelist> the freelist of timer nodes. If 0, then a default freelist will be created. Definition at line 82 of file Timer_List_T.cpp. References ACE_NEW, ACE_TRACE, head_, Iterator, and iterator_.
00083 : Base(uf, fl) 00084 , head_ (new ACE_Timer_Node_T<TYPE>) 00085 , id_counter_ (0) 00086 { 00087 ACE_TRACE ("ACE_Timer_List_T::ACE_Timer_List_T"); 00088 00089 this->head_->set_next (this->head_); 00090 this->head_->set_prev (this->head_); 00091 00092 ACE_NEW (iterator_, Iterator(*this)); 00093 } |
|
||||||||||
|
Destructor.
Definition at line 122 of file Timer_List_T.cpp. References ACE_GUARD, ACE_MT, ACE_TRACE, ACE_Timer_Queue_T::free_node, ACE_Timer_Node_T::get_act, get_first, ACE_Timer_Node_T::get_next, ACE_Timer_Node_T::get_type, head_, is_empty, iterator_, and ACE_Timer_Queue_T::upcall_functor.
00123 {
00124 ACE_TRACE ("ACE_Timer_List_T::~ACE_Timer_List_T");
00125 ACE_MT (ACE_GUARD (ACE_LOCK, ace_mon, this->mutex_));
00126
00127 delete iterator_;
00128
00129 if (! this->is_empty()) {
00130 for (ACE_Timer_Node_T<TYPE>* n = this->get_first(); n != this->head_;) {
00131 ACE_Timer_Node_T<TYPE>* next = n->get_next();
00132 this->upcall_functor ().deletion (*this, n->get_type(), n->get_act());
00133 this->free_node(n);
00134 n = next;
00135 }
00136 }
00137
00138 // delete the dummy node
00139 delete this->head_;
00140 }
|
|
||||||||||
|
|
|
||||||||||||||||||||
|
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> is 0 then the <functor> will be invoked. Returns 1 if cancellation succeeded and 0 if the <timer_id> wasn't found. Implements ACE_Timer_Queue_T. Definition at line 265 of file Timer_List_T.cpp. References ACE_GUARD_RETURN, ACE_MT, ACE_TRACE, cancel_i, find_node, and ACE_Timer_Node_T::get_act.
00268 {
00269 ACE_TRACE ("ACE_Timer_List_T::cancel");
00270 ACE_MT (ACE_GUARD_RETURN (ACE_LOCK, ace_mon, this->mutex_, -1));
00271 ACE_Timer_Node_T<TYPE>* n = this->find_node(timer_id);
00272 if (n != 0) {
00273 if (act != 0)
00274 *act = n->get_act();
00275 this->cancel_i(n, skip_close);
00276 return 1;
00277 }
00278 return 0;
00279 }
|
|
||||||||||||||||
|
Cancel all timers associated with <type>. If <dont_call> is 0 then the <functor> will be invoked. Returns number of timers cancelled. Implements ACE_Timer_Queue_T. Definition at line 283 of file Timer_List_T.cpp. References ACE_GUARD_RETURN, ACE_MT, ACE_TRACE, cancel_i, get_first, ACE_Timer_Node_T::get_next, ACE_Timer_Node_T::get_type, head_, is_empty, and ACE_Timer_Queue_T::upcall_functor.
00284 {
00285 ACE_TRACE ("ACE_Timer_List_T::cancel");
00286 ACE_MT (ACE_GUARD_RETURN (ACE_LOCK, ace_mon, this->mutex_, -1));
00287
00288 int num_canceled = 0; // Note : Technically this can overflow.
00289
00290 if (! this->is_empty()) {
00291
00292 for (ACE_Timer_Node_T<TYPE>* n = this->get_first(); n != this->head_;)
00293 {
00294 if (n->get_type() == type) // Note: Typically Type is an ACE_Event_Handler*
00295 {
00296 ++num_canceled;
00297
00298 ACE_Timer_Node_T<TYPE>* tmp = n;
00299 n = n->get_next();
00300 int always_skip_close = 1; // todo : Is this correct?
00301 this->cancel_i(tmp, always_skip_close);
00302 }
00303 else
00304 {
00305 n = n->get_next();
00306 }
00307 }
00308
00309 }
00310
00311 if (! skip_close) { // && num_canceled > 0) {
00312 this->upcall_functor().cancellation (*this, type);
00313 }
00314 return num_canceled;
00315 }
|
|
||||||||||||||||
|
Shared subset of the two cancel() methods.
Definition at line 328 of file Timer_List_T.cpp. References ACE_Timer_Queue_T::free_node, ACE_Timer_Node_T::get_type, unlink, and ACE_Timer_Queue_T::upcall_functor. Referenced by cancel.
00329 {
00330 this->unlink(n);
00331 this->free_node (n);
00332 if (! skip_close) {
00333 this->upcall_functor().cancellation (*this, n->get_type());
00334 }
00335 }
|
|
||||||||||
|
Dump the state of an object.
Reimplemented from ACE_Timer_Queue_T. Definition at line 143 of file Timer_List_T.cpp. References ACE_BEGIN_DUMP, ACE_DEBUG, ACE_END_DUMP, ACE_LIB_TEXT, ACE_TRACE, get_first_i, ACE_Timer_Node_T::get_next, head_, and LM_DEBUG.
00144 {
00145 ACE_TRACE ("ACE_Timer_List_T::dump");
00146 ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
00147
00148 int count = 0;
00149
00150 ACE_Timer_Node_T<TYPE>* n = this->get_first_i();
00151 if (n != 0) {
00152 for (; n != this->head_; n = n->get_next()) {
00153 count++;
00154 }
00155 }
00156
00157 ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\nsize_ = %d"), count));
00158 ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00159 }
|
|
||||||||||
|
Returns the time of the earlier node in the <ACE_Timer_List>. Must be called on a non-empty queue.
Implements ACE_Timer_Queue_T. Definition at line 109 of file Timer_List_T.cpp. References ACE_TRACE, get_first_i, ACE_Timer_Node_T::get_timer_value, and ACE_Time_Value::zero.
00110 {
00111 ACE_TRACE ("ACE_Timer_List_T::earliest_time");
00112 ACE_Timer_Node_T<TYPE>* first = this->get_first_i();
00113 if (first != 0)
00114 return first->get_timer_value ();
00115 return ACE_Time_Value::zero;
00116 }
|
|
||||||||||
|
Definition at line 233 of file Timer_List_T.cpp. References get_first_i, ACE_Timer_Node_T::get_next, ACE_Timer_Node_T::get_timer_id, and head_. Referenced by cancel, and reset_interval.
00234 {
00235 ACE_Timer_Node_T<TYPE>* n = this->get_first_i();
00236 if (n == 0)
00237 return 0;
00238
00239 for (; n != this->head_; n = n->get_next()) {
00240 if (n->get_timer_id() == timer_id) {
00241 return n;
00242 }
00243 }
00244 return 0;
00245 }
|
|
||||||||||
|
Reads the earliest node from the queue and returns it.
Implements ACE_Timer_Queue_T. Definition at line 339 of file Timer_List_T.cpp. References ACE_TRACE, and get_first_i. Referenced by cancel, ACE_Timer_List_Iterator_T::first, remove_first, and ~ACE_Timer_List_T.
00340 {
00341 ACE_TRACE ("ACE_Timer_List_T::get_first");
00342 return this->get_first_i();
00343 }
|
|
||||||||||
|
Definition at line 346 of file Timer_List_T.cpp. References ACE_TRACE, and head_. Referenced by dump, earliest_time, find_node, get_first, and is_empty.
00347 {
00348 ACE_TRACE ("ACE_Timer_List_T::get_first_i");
00349 ACE_Timer_Node_T<TYPE>* first = this->head_->get_next();
00350 if (first != this->head_) // Note : is_empty() uses get_first()
00351 return first;
00352 return 0;
00353 }
|
|
||||||||||
|
True if queue is empty, else false.
Implements ACE_Timer_Queue_T. Definition at line 99 of file Timer_List_T.cpp. References ACE_TRACE, and get_first_i. Referenced by cancel, schedule_i, and ~ACE_Timer_List_T.
00100 {
00101 ACE_TRACE ("ACE_Timer_List_T::is_empty");
00102 return this->get_first_i() == 0;
00103 }
|
|
||||||||||
|
Returns a pointer to this <ACE_Timer_Queue>'s iterator.
Implements ACE_Timer_Queue_T. Definition at line 73 of file Timer_List_T.cpp. References ACE_Timer_List_Iterator_T::first, and iterator_.
|
|
||||||||||
|
|
|
||||||||||
|
Removes the earliest node from the queue and returns it.
Implements ACE_Timer_Queue_T. Definition at line 359 of file Timer_List_T.cpp. References ACE_TRACE, get_first, and unlink.
00360 {
00361 ACE_TRACE ("ACE_Timer_List_T::remove_first");
00362 ACE_Timer_Node_T<TYPE>* first = this->get_first();
00363 if (first != 0) {
00364 this->unlink(first);
00365 return first;
00366 }
00367 return 0;
00368 }
|
|
||||||||||
|
Reschedule an "interval" <ACE_Timer_Node>. This should be private but for now it needs to be public for <ACE_Timer_Hash_T>.
Implements ACE_Timer_Queue_T. Definition at line 166 of file Timer_List_T.cpp. References ACE_TRACE, ACE_Timer_Node_T::get_timer_value, and schedule_i.
00167 {
00168 ACE_TRACE ("ACE_Timer_List_T::reschedule");
00169 this->schedule_i(n, n->get_timer_value());
00170 }
|
|
||||||||||||||||
|
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. Implements ACE_Timer_Queue_T. Definition at line 249 of file Timer_List_T.cpp. References ACE_GUARD_RETURN, ACE_MT, ACE_TRACE, find_node, and ACE_Timer_Node_T::set_interval.
00251 {
00252 ACE_TRACE ("ACE_Timer_List_T::reset_interval");
00253 ACE_MT (ACE_GUARD_RETURN (ACE_LOCK, ace_mon, this->mutex_, -1));
00254 ACE_Timer_Node_T<TYPE>* n = this->find_node(timer_id);
00255 if (n != 0) {
00256 n->set_interval(interval); // The interval will take effect the next time this node is expired.
00257 return 0;
00258 }
00259 return -1;
00260 }
|
|
||||||||||||||||||||||||
|
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>). Implements ACE_Timer_Queue_T. Definition at line 177 of file Timer_List_T.cpp. References ACE_GUARD_RETURN, ACE_MT, ACE_TRACE, ACE_Timer_Queue_T::alloc_node, id_counter_, schedule_i, and ACE_Timer_Node_T::set.
00181 {
00182 ACE_TRACE ("ACE_Timer_List_T::schedule");
00183 ACE_MT (ACE_GUARD_RETURN (ACE_LOCK, ace_mon, this->mutex_, -1));
00184
00185 ACE_Timer_Node_T<TYPE>* n = this->alloc_node();
00186
00187 if (n != 0)
00188 {
00189 long id = this->id_counter_++;
00190
00191 if (id != -1) {
00192 n->set (type, act, future_time, interval, 0, 0, id);
00193 this->schedule_i (n, future_time);
00194 }
00195 return id;
00196 }
00197
00198 // Failure return
00199 errno = ENOMEM;
00200 return -1;
00201 }
|
|
||||||||||||||||
|
The shared scheduling functionality between schedule() and reschedule().
Definition at line 205 of file Timer_List_T.cpp. References ACE_Timer_Node_T::get_next, ACE_Timer_Node_T::get_prev, ACE_Timer_Node_T::get_timer_value, head_, is_empty, ACE_Timer_Node_T::set_next, and ACE_Timer_Node_T::set_prev. Referenced by reschedule, and schedule.
00207 {
00208 if (this->is_empty()) {
00209 n->set_prev(this->head_);
00210 n->set_next(this->head_);
00211 this->head_->set_prev(n);
00212 this->head_->set_next(n);
00213 return;
00214 }
00215
00216 // We always want to search backwards from the tail of the list, because
00217 // this minimizes the search in the extreme case when lots of timers are
00218 // scheduled for exactly the same time, and it also assumes that most of
00219 // the timers will be scheduled later than existing timers.
00220 ACE_Timer_Node_T<TYPE>* p = this->head_->get_prev();
00221 while (p != this->head_ && p->get_timer_value() > expire)
00222 p = p->get_prev();
00223
00224 // insert after
00225 n->set_prev(p);
00226 n->set_next(p->get_next());
00227 p->get_next()->set_prev(n);
00228 p->set_next(n);
00229 }
|
|
||||||||||
|
Definition at line 318 of file Timer_List_T.cpp. References ACE_Timer_Node_T::get_next, ACE_Timer_Node_T::get_prev, ACE_Timer_Node_T::set_next, and ACE_Timer_Node_T::set_prev. Referenced by cancel_i, and remove_first.
|
|
|||||
|
Iterator is a friend.
Definition at line 92 of file Timer_List_T.h. |
|
|||||
|
Pointer to linked list of <ACE_Timer_Handles>.
Definition at line 196 of file Timer_List_T.h. Referenced by ACE_Timer_List_T, cancel, dump, find_node, get_first_i, ACE_Timer_List_Iterator_T::next, schedule_i, and ~ACE_Timer_List_T. |
|
|||||
|
Keeps track of the timer id that uniquely identifies each timer. This id can be used to cancel a timer via the <cancel(long)> method. Definition at line 206 of file Timer_List_T.h. Referenced by schedule. |
|
|||||
|
Iterator used to expire timers.
Definition at line 199 of file Timer_List_T.h. Referenced by ACE_Timer_List_T, iter, and ~ACE_Timer_List_T. |
1.2.14 written by Dimitri van Heesch,
© 1997-2002