#include <Timer_Heap_T.h>
Inheritance diagram for ACE_Timer_Heap_T:


Public Types | |
| typedef ACE_Timer_Heap_Iterator_T< TYPE, FUNCTOR, ACE_LOCK > | HEAP_ITERATOR |
| typedef ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK > | INHERITED |
Public Methods | |
| ACE_Timer_Heap_T (size_t size, int preallocated=0, FUNCTOR *upcall_functor=0, ACE_Free_List< ACE_Timer_Node_T< TYPE > > *freelist=0) | |
| ACE_Timer_Heap_T (FUNCTOR *upcall_functor=0, ACE_Free_List< ACE_Timer_Node_T< TYPE > > *freelist=0) | |
| virtual | ~ACE_Timer_Heap_T (void) |
| Destructor. More... | |
| virtual int | is_empty (void) const |
| True if heap is empty, else false. More... | |
| virtual const ACE_Time_Value & | earliest_time (void) const |
| Returns the time of the earliest 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) |
| 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... | |
| ACE_Timer_Node_T< TYPE > * | remove_first (void) |
| 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 Methods | |
| virtual void | reschedule (ACE_Timer_Node_T< TYPE > *) |
| Reschedule an "interval" <ACE_Timer_Node>. More... | |
| virtual ACE_Timer_Node_T< TYPE > * | alloc_node (void) |
| Factory method that allocates a new node (uses operator new if we're *not* preallocating, otherwise uses an internal freelist). More... | |
| virtual void | free_node (ACE_Timer_Node_T< TYPE > *) |
Private Methods | |
| ACE_Timer_Node_T< TYPE > * | remove (size_t slot) |
| Remove and return the <slot>th <ACE_Timer_Node> and restore the heap property. More... | |
| void | insert (ACE_Timer_Node_T< TYPE > *new_node) |
| Insert new_node into the heap and restore the heap property. More... | |
| void | grow_heap (void) |
| void | reheap_up (ACE_Timer_Node_T< TYPE > *new_node, size_t slot, size_t parent) |
| Restore the heap property, starting at <slot>. More... | |
| void | reheap_down (ACE_Timer_Node_T< TYPE > *moved_node, size_t slot, size_t child) |
| Restore the heap property, starting at <slot>. More... | |
| void | copy (size_t slot, ACE_Timer_Node_T< TYPE > *moved_node) |
| Copy <moved_node> into the <slot> slot of <heap_> and move <slot> into the corresponding slot in the <timer_id_> array. More... | |
| int | timer_id (void) |
| int | pop_freelist (void) |
| Pops and returns a new timer id from the freelist. More... | |
| void | push_freelist (int old_id) |
| Pushes <old_id> onto the freelist. More... | |
| ACE_Timer_Heap_T (const ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK > &) | |
| void | operator= (const ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK > &) |
Private Attributes | |
| size_t | max_size_ |
| Maximum size of the heap. More... | |
| size_t | cur_size_ |
| Current size of the heap. More... | |
| size_t | cur_limbo_ |
| Number of heap entries in transition (removed from the queue, but not freed) and may be rescheduled or freed. More... | |
| HEAP_ITERATOR * | iterator_ |
| Iterator used to expire timers. More... | |
| ACE_Timer_Node_T< TYPE > ** | heap_ |
| ssize_t * | timer_ids_ |
| size_t | timer_ids_curr_ |
| "Pointer" to the element in the <timer_ids_> array that was last given out as a timer ID. More... | |
| size_t | timer_ids_min_free_ |
| Index representing the lowest timer ID that has been freed. When the timer_ids_next_ value wraps around, it starts back at this point. More... | |
| ACE_Timer_Node_T< TYPE > * | preallocated_nodes_ |
| ACE_Timer_Node_T< TYPE > * | preallocated_nodes_freelist_ |
| This points to the head of the <preallocated_nodes_> freelist, which is organized as a stack. More... | |
| ACE_Unbounded_Set< ACE_Timer_Node_T< TYPE > * > | preallocated_node_set_ |
| Set of pointers to the arrays of preallocated timer nodes. Used to delete the allocated memory when required. More... | |
Friends | |
| class | ACE_Timer_Heap_Iterator_T< TYPE, FUNCTOR, ACE_LOCK > |
This implementation uses a heap-based callout queue of absolute times. Therefore, in the average and worst case, scheduling, canceling, and expiring timers is O(log N) (where N is the total number of timers). In addition, we can also preallocate as many ACE_Timer_Node objects as there are slots in the heap. This allows us to completely remove the need for dynamic memory allocation, which is important for real-time systems.
Definition at line 84 of file Timer_Heap_T.h.
|
|||||
|
Definition at line 87 of file Timer_Heap_T.h. |
|
|||||
|
Definition at line 90 of file Timer_Heap_T.h. |
|
||||||||||||||||||||||||
|
The Constructor creates a heap with specified number of elements. This can also take in a upcall functor and freelist (if 0, then defaults will be created).
Definition at line 75 of file Timer_Heap_T.cpp. References ACE_NEW, ACE_TRACE, ACE_Unbounded_Set< ACE_Timer_Node_T< TYPE > * >::insert, iterator_, preallocated_node_set_, preallocated_nodes_, preallocated_nodes_freelist_, ssize_t, and timer_ids_.
00079 : ACE_Timer_Queue_T<TYPE,FUNCTOR,ACE_LOCK> (upcall_functor, freelist), 00080 max_size_ (size), 00081 cur_size_ (0), 00082 cur_limbo_ (0), 00083 timer_ids_curr_ (0), 00084 timer_ids_min_free_ (0), 00085 preallocated_nodes_ (0), 00086 preallocated_nodes_freelist_ (0) 00087 { 00088 ACE_TRACE ("ACE_Timer_Heap_T::ACE_Timer_Heap_T"); 00089 00090 // Create the heap array. 00091 ACE_NEW (this->heap_, 00092 ACE_Timer_Node_T<TYPE> *[size]); 00093 00094 // Create the parallel 00095 ACE_NEW (this->timer_ids_, 00096 ssize_t[size]); 00097 00098 // Initialize the "freelist," which uses negative values to 00099 // distinguish freelist elements from "pointers" into the <heap_> 00100 // array. 00101 for (size_t i = 0; i < size; i++) 00102 this->timer_ids_[i] = -1; 00103 00104 if (preallocate) 00105 { 00106 ACE_NEW (this->preallocated_nodes_, 00107 ACE_Timer_Node_T<TYPE>[size]); 00108 00109 // Add allocated array to set of such arrays for deletion on 00110 // cleanup. 00111 this->preallocated_node_set_.insert (this->preallocated_nodes_); 00112 00113 // Form the freelist by linking the next_ pointers together. 00114 for (size_t j = 1; j < size; j++) 00115 this->preallocated_nodes_[j - 1].set_next (&this->preallocated_nodes_[j]); 00116 00117 // NULL-terminate the freelist. 00118 this->preallocated_nodes_[size - 1].set_next (0); 00119 00120 // Assign the freelist pointer to the front of the list. 00121 this->preallocated_nodes_freelist_ = 00122 &this->preallocated_nodes_[0]; 00123 } 00124 00125 ACE_NEW (iterator_, 00126 HEAP_ITERATOR (*this)); 00127 } |
|
||||||||||||||||
|
Default constructor. Definition at line 134 of file Timer_Heap_T.cpp. References ACE_DEFAULT_TIMERS, ACE_NEW, ACE_TRACE, iterator_, max_size_, ssize_t, and timer_ids_.
00136 : ACE_Timer_Queue_T<TYPE,FUNCTOR,ACE_LOCK> (upcall_functor, freelist), 00137 max_size_ (ACE_DEFAULT_TIMERS), 00138 cur_size_ (0), 00139 cur_limbo_ (0), 00140 timer_ids_curr_ (0), 00141 timer_ids_min_free_ (0), 00142 preallocated_nodes_ (0), 00143 preallocated_nodes_freelist_ (0) 00144 { 00145 ACE_TRACE ("ACE_Timer_Heap_T::ACE_Timer_Heap_T"); 00146 00147 // Create the heap array. 00148 #if defined (__IBMCPP__) && (__IBMCPP__ >= 400) && defined (_WINDOWS) 00149 ACE_NEW (this->heap_, 00150 ACE_Timer_Node_T<TYPE> *[ACE_DEFAULT_TIMERS]); 00151 #else 00152 ACE_NEW (this->heap_, 00153 ACE_Timer_Node_T<TYPE> *[this->max_size_]); 00154 #endif /* defined (__IBMCPP__) && (__IBMCPP__ >= 400) && defined (_WINDOWS) */ 00155 00156 // Create the parallel array. 00157 ACE_NEW (this->timer_ids_, 00158 ssize_t[this->max_size_]); 00159 00160 // Initialize the "freelist," which uses negative values to 00161 // distinguish freelist elements from "pointers" into the <heap_> 00162 // array. 00163 for (size_t i = 0; i < this->max_size_; i++) 00164 this->timer_ids_[i] = -1; 00165 00166 ACE_NEW (iterator_, 00167 HEAP_ITERATOR (*this)); 00168 } |
|
||||||||||
|
Destructor.
Definition at line 171 of file Timer_Heap_T.cpp. References ACE_TRACE, ACE_Unbounded_Set_Iterator::advance, cur_size_, free_node, heap_, iterator_, ACE_Unbounded_Set_Iterator::next, preallocated_nodes_, timer_ids_, and ACE_Timer_Queue_T::upcall_functor.
00172 {
00173 ACE_TRACE ("ACE_Timer_Heap_T::~ACE_Timer_Heap_T");
00174
00175 delete iterator_;
00176
00177 // Clean up all the nodes still in the queue
00178 for (size_t i = 0; i < this->cur_size_; i++)
00179 {
00180 this->upcall_functor ().deletion (*this,
00181 this->heap_[i]->get_type (),
00182 this->heap_[i]->get_act ());
00183 this->free_node (this->heap_[i]);
00184 }
00185
00186 delete [] this->heap_;
00187 delete [] this->timer_ids_;
00188
00189 // clean up any preallocated timer nodes
00190 if (preallocated_nodes_ != 0)
00191 {
00192 ACE_Unbounded_Set_Iterator<ACE_Timer_Node_T<TYPE> *>
00193 set_iterator (this->preallocated_node_set_);
00194
00195 for (ACE_Timer_Node_T<TYPE> **entry = 0;
00196 set_iterator.next (entry) !=0;
00197 set_iterator.advance ())
00198 delete [] *entry;
00199 }
00200 }
|
|
||||||||||
|
|
|
||||||||||
|
Factory method that allocates a new node (uses operator new if we're *not* preallocating, otherwise uses an internal freelist).
Reimplemented from ACE_Timer_Queue_T. Definition at line 570 of file Timer_Heap_T.cpp. References ACE_NEW_RETURN, grow_heap, preallocated_nodes_, and preallocated_nodes_freelist_.
00571 {
00572 ACE_Timer_Node_T<TYPE> *temp = 0;
00573
00574 // Only allocate a node if we are *not* using the preallocated heap.
00575 if (this->preallocated_nodes_ == 0)
00576 ACE_NEW_RETURN (temp,
00577 ACE_Timer_Node_T<TYPE>,
00578 0);
00579 else
00580 {
00581 // check to see if the heap needs to grow
00582 if (this->preallocated_nodes_freelist_ == 0)
00583 this->grow_heap ();
00584
00585 temp = this->preallocated_nodes_freelist_;
00586
00587 // Remove the first element from the freelist.
00588 this->preallocated_nodes_freelist_ =
00589 this->preallocated_nodes_freelist_->get_next ();
00590 }
00591 return temp;
00592 }
|
|
||||||||||||||||||||
|
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 653 of file Timer_Heap_T.cpp. References ACE_ASSERT, ACE_GUARD_RETURN, ACE_MT, ACE_TRACE, free_node, ACE_Timer_Node_T::get_act, ACE_Timer_Node_T::get_type, heap_, max_size_, remove, ssize_t, timer_id, timer_ids_, and ACE_Timer_Queue_T::upcall_functor.
00656 {
00657 ACE_TRACE ("ACE_Timer_Heap_T::cancel");
00658 ACE_MT (ACE_GUARD_RETURN (ACE_LOCK, ace_mon, this->mutex_, -1));
00659
00660 // Locate the ACE_Timer_Node that corresponds to the timer_id.
00661
00662 // Check to see if the timer_id is out of range
00663 if (timer_id < 0
00664 || (size_t) timer_id > this->max_size_)
00665 return 0;
00666
00667 ssize_t timer_node_slot = this->timer_ids_[timer_id];
00668
00669 // Check to see if timer_id is still valid.
00670 if (timer_node_slot < 0)
00671 return 0;
00672
00673 if (timer_id != this->heap_[timer_node_slot]->get_timer_id ())
00674 {
00675 ACE_ASSERT (timer_id == this->heap_[timer_node_slot]->get_timer_id ());
00676 return 0;
00677 }
00678 else
00679 {
00680 ACE_Timer_Node_T<TYPE> *temp =
00681 this->remove (timer_node_slot);
00682
00683 if (dont_call == 0)
00684 // Call the close hook.
00685 this->upcall_functor ().cancellation (*this,
00686 temp->get_type ());
00687
00688 if (act != 0)
00689 *act = temp->get_act ();
00690
00691 this->free_node (temp);
00692 return 1;
00693 }
00694 }
|
|
||||||||||||||||
|
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 734 of file Timer_Heap_T.cpp. References ACE_GUARD_RETURN, ACE_MT, ACE_TRACE, cur_size_, free_node, heap_, remove, and ACE_Timer_Queue_T::upcall_functor.
00736 {
00737 ACE_TRACE ("ACE_Timer_Heap_T::cancel");
00738
00739 int number_of_cancellations = 0;
00740
00741 // Try to locate the ACE_Timer_Node that matches the timer_id.
00742 {
00743 ACE_MT (ACE_GUARD_RETURN (ACE_LOCK, ace_mon, this->mutex_, -1));
00744
00745 for (size_t i = 0; i < this->cur_size_; )
00746 {
00747 if (this->heap_[i]->get_type () == type)
00748 {
00749 ACE_Timer_Node_T<TYPE> *temp = this->remove (i);
00750
00751 number_of_cancellations++;
00752
00753 this->free_node (temp);
00754 }
00755 else
00756 i++;
00757 }
00758 }
00759
00760 if (dont_call == 0)
00761 this->upcall_functor ().cancellation (*this, type);
00762
00763 return number_of_cancellations;
00764 }
|
|
||||||||||||||||
|
Copy <moved_node> into the <slot> slot of <heap_> and move <slot> into the corresponding slot in the <timer_id_> array.
Definition at line 331 of file Timer_Heap_T.cpp. References ACE_ASSERT, ACE_Timer_Node_T::get_timer_id, heap_, max_size_, and timer_ids_. Referenced by reheap_down, reheap_up, and remove.
00333 {
00334 // Insert <moved_node> into its new location in the heap.
00335 this->heap_[slot] = moved_node;
00336
00337 ACE_ASSERT (moved_node->get_timer_id () >= 0
00338 && moved_node->get_timer_id () < (int) this->max_size_);
00339
00340 // Update the corresponding slot in the parallel <timer_ids_> array.
00341 this->timer_ids_[moved_node->get_timer_id ()] = slot;
00342 }
|
|
||||||||||
|
Dump the state of an object.
Reimplemented from ACE_Timer_Queue_T. Definition at line 296 of file Timer_Heap_T.cpp. References ACE_BEGIN_DUMP, ACE_DEBUG, ACE_END_DUMP, ACE_LIB_TEXT, ACE_TRACE, cur_size_, heap_, LM_DEBUG, and max_size_.
00297 {
00298 ACE_TRACE ("ACE_Timer_Heap_T::dump");
00299 ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
00300
00301 ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\nmax_size_ = %d"), this->max_size_));
00302 ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\ncur_size_ = %d"), this->cur_size_));
00303 ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\ncur_limbo_= %d"), this->cur_limbo_));
00304 ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\nids_curr_ = %d"),
00305 this->timer_ids_curr_));
00306 ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\nmin_free_ = %d"),
00307 this->timer_ids_min_free_));
00308
00309 ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\nheap_ = \n")));
00310
00311 for (size_t i = 0; i < this->cur_size_; i++)
00312 {
00313 ACE_DEBUG ((LM_DEBUG,
00314 ACE_LIB_TEXT ("%d\n"),
00315 i));
00316 this->heap_[i]->dump ();
00317 }
00318
00319 ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\ntimer_ids_ = \n")));
00320
00321 for (size_t j = 0; j < this->max_size_; j++)
00322 ACE_DEBUG ((LM_DEBUG,
00323 ACE_LIB_TEXT ("%d\t%d\n"),
00324 j,
00325 this->timer_ids_[j]));
00326
00327 ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00328 }
|
|
||||||||||
|
Returns the time of the earliest node in the Timer_Queue. Must be called on a non-empty queue.
Implements ACE_Timer_Queue_T. Definition at line 289 of file Timer_Heap_T.cpp. References ACE_TRACE, and heap_.
|
|
||||||||||
|
Factory method that frees a previously allocated node (uses operator delete if we're *not* preallocating, otherwise uses an internal freelist). Reimplemented from ACE_Timer_Queue_T. Definition at line 595 of file Timer_Heap_T.cpp. References ACE_Timer_Node_T::get_timer_id, preallocated_nodes_, preallocated_nodes_freelist_, push_freelist, and ACE_Timer_Node_T::set_next. Referenced by cancel, and ~ACE_Timer_Heap_T.
00596 {
00597
00598 // Return this timer id to the freelist.
00599 this->push_freelist (node->get_timer_id ());
00600
00601 // Only free up a node if we are *not* using the preallocated heap.
00602 if (this->preallocated_nodes_ == 0)
00603 delete node;
00604 else
00605 {
00606 node->set_next (this->preallocated_nodes_freelist_);
00607 this->preallocated_nodes_freelist_ = node;
00608 }
00609 }
|
|
||||||||||
|
Reads the earliest node from the queue and returns it.
Implements ACE_Timer_Queue_T. Definition at line 780 of file Timer_Heap_T.cpp. References ACE_TRACE, cur_size_, and heap_.
|
|
||||||||||
|
Doubles the size of the heap and the corresponding timer_ids array. If preallocation is used, will also double the size of the preallocated array of ACE_Timer_Nodes. Definition at line 467 of file Timer_Heap_T.cpp. References ACE_NEW, ACE_Timer_Node_T::get_next, heap_, ACE_Unbounded_Set< ACE_Timer_Node_T< TYPE > * >::insert, max_size_, ACE_OS_String::memcpy, preallocated_node_set_, preallocated_nodes_, preallocated_nodes_freelist_, ACE_Timer_Node_T::set_next, ssize_t, and timer_ids_. Referenced by alloc_node, and insert.
00468 {
00469 // All the containers will double in size from max_size_
00470 size_t new_size = this->max_size_ * 2;
00471
00472 // First grow the heap itself.
00473
00474 ACE_Timer_Node_T<TYPE> **new_heap = 0;
00475
00476 #if defined (__IBMCPP__) && (__IBMCPP__ >= 400) && defined (_WINDOWS)
00477 ACE_NEW (new_heap,
00478 ACE_Timer_Node_T<TYPE> *[1024]);
00479 #else
00480 ACE_NEW (new_heap,
00481 ACE_Timer_Node_T<TYPE> *[new_size]);
00482 #endif /* defined (__IBMCPP__) && (__IBMCPP__ >= 400) && defined (_WINDOWS) */
00483 ACE_OS::memcpy (new_heap,
00484 this->heap_,
00485 this->max_size_ * sizeof *new_heap);
00486 delete [] this->heap_;
00487 this->heap_ = new_heap;
00488
00489 // Grow the array of timer ids.
00490
00491 ssize_t *new_timer_ids = 0;
00492
00493 ACE_NEW (new_timer_ids,
00494 ssize_t[new_size]);
00495
00496 ACE_OS::memcpy (new_timer_ids,
00497 this->timer_ids_,
00498 this->max_size_ * sizeof (ssize_t));
00499
00500 delete [] timer_ids_;
00501 this->timer_ids_ = new_timer_ids;
00502
00503 // And add the new elements to the end of the "freelist".
00504 for (size_t i = this->max_size_; i < new_size; i++)
00505 this->timer_ids_[i] = -(ACE_static_cast (ssize_t, i) + 1);
00506
00507 // Grow the preallocation array (if using preallocation)
00508 if (this->preallocated_nodes_ != 0)
00509 {
00510 // Create a new array with max_size elements to link in to
00511 // existing list.
00512 #if defined (__IBMCPP__) && (__IBMCPP__ >= 400) && defined (_WINDOWS)
00513 ACE_NEW (this->preallocated_nodes_,
00514 ACE_Timer_Node_T<TYPE>[88]);
00515 #else
00516 ACE_NEW (this->preallocated_nodes_,
00517 ACE_Timer_Node_T<TYPE>[this->max_size_]);
00518 #endif /* defined (__IBMCPP__) && (__IBMCPP__ >= 400) && defined (_WINDOWS) */
00519
00520 // Add it to the set for later deletion
00521 this->preallocated_node_set_.insert (this->preallocated_nodes_);
00522
00523 // Link new nodes together (as for original list).
00524 for (size_t k = 1; k < this->max_size_; k++)
00525 this->preallocated_nodes_[k - 1].set_next (&this->preallocated_nodes_[k]);
00526
00527 // NULL-terminate the new list.
00528 this->preallocated_nodes_[this->max_size_ - 1].set_next (0);
00529
00530 // Link new array to the end of the existling list.
00531 if (this->preallocated_nodes_freelist_ == 0)
00532 this->preallocated_nodes_freelist_ =
00533 &preallocated_nodes_[0];
00534 else
00535 {
00536 ACE_Timer_Node_T<TYPE> *previous =
00537 this->preallocated_nodes_freelist_;
00538
00539 for (ACE_Timer_Node_T<TYPE> *current = this->preallocated_nodes_freelist_->get_next ();
00540 current != 0;
00541 current = current->get_next ())
00542 previous = current;
00543
00544 previous->set_next (&this->preallocated_nodes_[0]);
00545 }
00546 }
00547
00548 this->max_size_ = new_size;
00549 }
|
|
||||||||||
|
Insert new_node into the heap and restore the heap property.
Definition at line 455 of file Timer_Heap_T.cpp. References ACE_HEAP_PARENT, cur_size_, grow_heap, max_size_, and reheap_up. Referenced by reschedule, and schedule.
|
|
||||||||||
|
True if heap is empty, else false.
Implements ACE_Timer_Queue_T. Definition at line 273 of file Timer_Heap_T.cpp. References ACE_TRACE, and cur_size_.
|
|
||||||||||
|
Returns a pointer to this <ACE_Timer_Queue>'s iterator.
Implements ACE_Timer_Queue_T. Definition at line 280 of file Timer_Heap_T.cpp. References ACE_Timer_Heap_Iterator_T::first, and iterator_.
|
|
||||||||||
|
|
|
||||||||||
|
Pops and returns a new timer id from the freelist.
Definition at line 203 of file Timer_Heap_T.cpp. References ACE_ASSERT, ACE_TRACE, max_size_, timer_ids_, timer_ids_curr_, and timer_ids_min_free_. Referenced by timer_id.
00204 {
00205 ACE_TRACE ("ACE_Timer_Heap_T::pop_freelist");
00206
00207 // Scan for a free timer ID. Note that since this function is called
00208 // _after_ the check for a full timer heap, we are guaranteed to find
00209 // a free ID, even if we need to wrap around and start reusing freed IDs.
00210 // On entry, the curr_ index is at the previous ID given out; start
00211 // up where we left off last time.
00212 // NOTE - a timer_ids_ slot with -2 is out of the heap, but not freed.
00213 // It must be either freed (free_node) or rescheduled (reschedule).
00214 ++this->timer_ids_curr_;
00215 while (this->timer_ids_curr_ < this->max_size_ &&
00216 (this->timer_ids_[this->timer_ids_curr_] >= 0 ||
00217 this->timer_ids_[this->timer_ids_curr_] == -2 ))
00218 ++this->timer_ids_curr_;
00219 if (this->timer_ids_curr_ == this->max_size_)
00220 {
00221 ACE_ASSERT (this->timer_ids_min_free_ < this->max_size_);
00222 this->timer_ids_curr_ = this->timer_ids_min_free_;
00223 // We restarted the free search at min. Since min won't be
00224 // free anymore, and curr_ will just keep marching up the list
00225 // on each successive need for an ID, reset min_free_ to the
00226 // size of the list until an ID is freed that curr_ has already
00227 // gone past (see push_freelist).
00228 this->timer_ids_min_free_ = this->max_size_;
00229 }
00230
00231 // We need to truncate this to <int> for backwards compatibility.
00232 int new_id = ACE_static_cast (int,
00233 this->timer_ids_curr_);
00234 return new_id;
00235 }
|
|
||||||||||
|
Pushes <old_id> onto the freelist.
Definition at line 238 of file Timer_Heap_T.cpp. References ACE_ASSERT, ACE_TRACE, cur_limbo_, cur_size_, timer_ids_, timer_ids_curr_, and timer_ids_min_free_. Referenced by free_node.
00239 {
00240 ACE_TRACE ("ACE_Timer_Heap_T::push_freelist");
00241
00242 // Since this ID has already been checked by one of the public
00243 // functions, it's safe to cast it here.
00244 size_t oldid = size_t (old_id);
00245
00246 // The freelist values in the <timer_ids_> are negative, so set the
00247 // freed entry back to 'free'. If this is the new lowest value free
00248 // timer ID that curr_ won't see on it's normal march through the list,
00249 // remember it.
00250 ACE_ASSERT (this->timer_ids_[oldid] >= 0 || this->timer_ids_[oldid] == -2);
00251 if (this->timer_ids_[oldid] == -2)
00252 --this->cur_limbo_;
00253 else
00254 --this->cur_size_;
00255 this->timer_ids_[oldid] = -1;
00256 if (oldid < this->timer_ids_min_free_ && oldid <= this->timer_ids_curr_)
00257 this->timer_ids_min_free_ = oldid;
00258 return;
00259 }
|
|
||||||||||||||||||||
|
Restore the heap property, starting at <slot>.
Definition at line 394 of file Timer_Heap_T.cpp. References ACE_HEAP_LCHILD, copy, cur_size_, ACE_Timer_Node_T::get_timer_value, and heap_. Referenced by remove.
00397 {
00398 // Restore the heap property after a deletion.
00399
00400 while (child < this->cur_size_)
00401 {
00402 // Choose the smaller of the two children.
00403 if (child + 1 < this->cur_size_
00404 && this->heap_[child + 1]->get_timer_value ()
00405 < this->heap_[child]->get_timer_value ())
00406 child++;
00407
00408 // Perform a <copy> if the child has a larger timeout value than
00409 // the <moved_node>.
00410 if (this->heap_[child]->get_timer_value ()
00411 < moved_node->get_timer_value ())
00412 {
00413 this->copy (slot,
00414 this->heap_[child]);
00415 slot = child;
00416 child = ACE_HEAP_LCHILD (child);
00417 }
00418 else
00419 // We've found our location in the heap.
00420 break;
00421 }
00422
00423 this->copy (slot, moved_node);
00424 }
|
|
||||||||||||||||||||
|
Restore the heap property, starting at <slot>.
Definition at line 427 of file Timer_Heap_T.cpp. References ACE_HEAP_PARENT, copy, ACE_Timer_Node_T::get_timer_value, and heap_. Referenced by insert, and remove.
00430 {
00431 // Restore the heap property after an insertion.
00432
00433 while (slot > 0)
00434 {
00435 // If the parent node is greater than the <moved_node> we need
00436 // to copy it down.
00437 if (moved_node->get_timer_value ()
00438 < this->heap_[parent]->get_timer_value ())
00439 {
00440 this->copy (slot, this->heap_[parent]);
00441 slot = parent;
00442 parent = ACE_HEAP_PARENT (slot);
00443 }
00444 else
00445 break;
00446 }
00447
00448 // Insert the new node into its proper resting place in the heap and
00449 // update the corresponding slot in the parallel <timer_ids> array.
00450 this->copy (slot,
00451 moved_node);
00452 }
|
|
||||||||||
|
Remove and return the <slot>th <ACE_Timer_Node> and restore the heap property.
Definition at line 350 of file Timer_Heap_T.cpp. References ACE_HEAP_LCHILD, ACE_HEAP_PARENT, copy, cur_limbo_, cur_size_, ACE_Timer_Node_T::get_timer_id, ACE_Timer_Node_T::get_timer_value, heap_, reheap_down, reheap_up, and timer_ids_. Referenced by cancel, and remove_first.
00351 {
00352 ACE_Timer_Node_T<TYPE> *removed_node =
00353 this->heap_[slot];
00354
00355 // NOTE - the cur_size_ is being decremented since the queue has one
00356 // less active timer in it. However, this ACE_Timer_Node is not being
00357 // freed, and there is still a place for it in timer_ids_ (the timer ID
00358 // is not being relinquished). The node can still be rescheduled, or
00359 // it can be freed via free_node.
00360 --this->cur_size_;
00361
00362 // Only try to reheapify if we're not deleting the last entry.
00363
00364 if (slot < this->cur_size_)
00365 {
00366 ACE_Timer_Node_T<TYPE> *moved_node =
00367 this->heap_[this->cur_size_];
00368
00369 // Move the end node to the location being removed and update
00370 // the corresponding slot in the parallel <timer_ids> array.
00371 this->copy (slot, moved_node);
00372
00373 // If the <moved_node->time_value_> is great than or equal its
00374 // parent it needs be moved down the heap.
00375 size_t parent = ACE_HEAP_PARENT (slot);
00376
00377 if (moved_node->get_timer_value ()
00378 >= this->heap_[parent]->get_timer_value ())
00379 this->reheap_down (moved_node,
00380 slot,
00381 ACE_HEAP_LCHILD (slot));
00382 else
00383 this->reheap_up (moved_node,
00384 slot,
00385 parent);
00386 }
00387
00388 this->timer_ids_[removed_node->get_timer_id ()] = -2;
00389 ++this->cur_limbo_;
00390 return removed_node;
00391 }
|
|
||||||||||
|
Removes the earliest node from the queue and returns it. Note that the timer is removed from the heap, but is not freed, and its ID is not reclaimed. The caller is responsible for calling either Implements ACE_Timer_Queue_T. Definition at line 769 of file Timer_Heap_T.cpp. References ACE_TRACE, cur_size_, and remove.
|
|
||||||||||
|
Reschedule an "interval" <ACE_Timer_Node>.
Implements ACE_Timer_Queue_T. Definition at line 555 of file Timer_Heap_T.cpp. References ACE_TRACE, cur_limbo_, ACE_Timer_Node_T::get_timer_id, insert, and timer_ids_.
00556 {
00557 ACE_TRACE ("ACE_Timer_Heap_T::reschedule");
00558
00559 // If we are rescheduling, then the most recent call was to
00560 // remove_first (). That called remove () to remove the node from the
00561 // heap, but did not free the timer ID. The ACE_Timer_Node still has
00562 // its assigned ID - just needs to be inserted at the new proper
00563 // place, and the heap restored properly.
00564 if (this->timer_ids_[expired->get_timer_id ()] == -2)
00565 --this->cur_limbo_;
00566 this->insert (expired);
00567 }
|
|
||||||||||||||||
|
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 699 of file Timer_Heap_T.cpp. References ACE_ASSERT, ACE_GUARD_RETURN, ACE_MT, ACE_TRACE, heap_, max_size_, ssize_t, timer_id, and timer_ids_.
00701 {
00702 ACE_TRACE ("ACE_Timer_Heap_T::reset_interval");
00703 ACE_MT (ACE_GUARD_RETURN (ACE_LOCK, ace_mon, this->mutex_, -1));
00704
00705 // Locate the ACE_Timer_Node that corresponds to the timer_id.
00706
00707 // Check to see if the timer_id is out of range
00708 if (timer_id < 0
00709 || (size_t) timer_id > this->max_size_)
00710 return -1;
00711
00712 ssize_t timer_node_slot = this->timer_ids_[timer_id];
00713
00714 // Check to see if timer_id is still valid.
00715 if (timer_node_slot < 0)
00716 return -1;
00717
00718 if (timer_id != this->heap_[timer_node_slot]->get_timer_id ())
00719 {
00720 ACE_ASSERT (timer_id == this->heap_[timer_node_slot]->get_timer_id ());
00721 return -1;
00722 }
00723 else
00724 {
00725 // Reset the timer interval
00726 this->heap_[timer_node_slot]->set_interval (interval);
00727 return 0;
00728 }
00729 }
|
|
||||||||||||||||||||||||
|
Schedule a timer that may optionally auto-reset. 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 615 of file Timer_Heap_T.cpp. References ACE_ALLOCATOR_RETURN, ACE_GUARD_RETURN, ACE_MT, ACE_TRACE, cur_limbo_, cur_size_, insert, max_size_, ACE_Timer_Node_T::set, and timer_id.
00619 {
00620 ACE_TRACE ("ACE_Timer_Heap_T::schedule");
00621
00622 ACE_MT (ACE_GUARD_RETURN (ACE_LOCK, ace_mon, this->mutex_, -1));
00623
00624 if ((this->cur_size_ + this->cur_limbo_) < this->max_size_)
00625 {
00626 // Obtain the next unique sequence number.
00627 int timer_id = this->timer_id ();
00628
00629 // Obtain the memory to the new node.
00630 ACE_Timer_Node_T<TYPE> *temp = 0;
00631
00632 ACE_ALLOCATOR_RETURN (temp,
00633 this->alloc_node (),
00634 -1);
00635 temp->set (type,
00636 act,
00637 future_time,
00638 interval,
00639 0,
00640 timer_id);
00641
00642 this->insert (temp);
00643 return timer_id;
00644 }
00645 else
00646 return -1;
00647 }
|
|
||||||||||
|
Returns a timer id that uniquely identifies this timer. This id can be used to cancel a timer via the <cancel (int)> method. The timer id returned from this method will never == -1 to avoid conflicts with other failure return values. Definition at line 262 of file Timer_Heap_T.cpp. References ACE_TRACE, and pop_freelist. Referenced by cancel, reset_interval, and schedule.
00263 {
00264 ACE_TRACE ("ACE_Timer_Heap_T::timer_id");
00265
00266 // Return the next item off the freelist and use it as the timer id.
00267 return this->pop_freelist ();
00268 }
|
|
|||||
|
Definition at line 88 of file Timer_Heap_T.h. |
|
|||||
|
Number of heap entries in transition (removed from the queue, but not freed) and may be rescheduled or freed.
Definition at line 269 of file Timer_Heap_T.h. Referenced by push_freelist, remove, reschedule, and schedule. |
|
|||||
|
Current size of the heap.
Definition at line 265 of file Timer_Heap_T.h. Referenced by cancel, dump, get_first, insert, is_empty, push_freelist, reheap_down, remove, remove_first, schedule, and ~ACE_Timer_Heap_T. |
|
|||||
|
Current contents of the Heap, which is organized as a "heap" of <ACE_Timer_Node> *'s. In this context, a heap is a "partially ordered, almost complete" binary tree, which is stored in an array. Definition at line 280 of file Timer_Heap_T.h. Referenced by cancel, copy, dump, earliest_time, get_first, grow_heap, reheap_down, reheap_up, remove, reset_interval, and ~ACE_Timer_Heap_T. |
|
|||||
|
Iterator used to expire timers.
Definition at line 272 of file Timer_Heap_T.h. Referenced by ACE_Timer_Heap_T, iter, and ~ACE_Timer_Heap_T. |
|
|||||
|
Maximum size of the heap.
Definition at line 262 of file Timer_Heap_T.h. Referenced by ACE_Timer_Heap_T, cancel, copy, dump, grow_heap, insert, pop_freelist, reset_interval, and schedule. |
|
|||||
|
Set of pointers to the arrays of preallocated timer nodes. Used to delete the allocated memory when required.
Definition at line 317 of file Timer_Heap_T.h. Referenced by ACE_Timer_Heap_T, and grow_heap. |
|
|||||
|
If this is non-0, then we preallocate <max_size_> number of <ACE_Timer_Node> objects in order to reduce dynamic allocation costs. In auto-growing implementation, this points to the last array of nodes allocated. Definition at line 309 of file Timer_Heap_T.h. Referenced by ACE_Timer_Heap_T, alloc_node, free_node, grow_heap, and ~ACE_Timer_Heap_T. |
|
|||||
|
This points to the head of the <preallocated_nodes_> freelist, which is organized as a stack.
Definition at line 313 of file Timer_Heap_T.h. Referenced by ACE_Timer_Heap_T, alloc_node, free_node, and grow_heap. |
|
|||||
|
An array of "pointers" that allows each <ACE_Timer_Node> in the <heap_> to be located in O(1) time. Basically, <timer_id_[i]> contains the slot in the <heap_> array where an <ACE_Timer_Node> * with timer id <i> resides. Thus, the timer id passed back from <schedule> is really a slot into the <timer_ids> array. The <timer_ids_> array serves two purposes: negative values are indications of free timer IDs, whereas positive values are "pointers" into the <heap_> array for assigned timer IDs. Definition at line 292 of file Timer_Heap_T.h. Referenced by ACE_Timer_Heap_T, cancel, copy, grow_heap, pop_freelist, push_freelist, remove, reschedule, reset_interval, and ~ACE_Timer_Heap_T. |
|
|||||
|
"Pointer" to the element in the <timer_ids_> array that was last given out as a timer ID.
Definition at line 296 of file Timer_Heap_T.h. Referenced by pop_freelist, and push_freelist. |
|
|||||
|
Index representing the lowest timer ID that has been freed. When the timer_ids_next_ value wraps around, it starts back at this point.
Definition at line 301 of file Timer_Heap_T.h. Referenced by pop_freelist, and push_freelist. |
1.2.14 written by Dimitri van Heesch,
© 1997-2002