ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK > Class Template Reference

Provides a very fast and predictable timer implementation. More...

#include <Timer_Heap_T.h>

Inheritance diagram for ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >:

Inheritance graph
[legend]
Collaboration diagram for ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >:

Collaboration graph
[legend]
List of all members.

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 Member Functions

 ACE_Timer_Heap_T (size_t size, bool preallocated=false, 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.
virtual bool is_empty (void) const
 True if heap is empty, else false.
virtual const ACE_Time_Valueearliest_time (void) const
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.
ACE_Timer_Node_T< TYPE > * remove_first (void)
virtual void dump (void) const
 Dump the state of an object.
virtual ACE_Timer_Node_T<
TYPE > * 
get_first (void)
 Reads the earliest node from the queue and returns it.

Protected Member Functions

virtual long schedule_i (const TYPE &type, const void *act, const ACE_Time_Value &future_time, const ACE_Time_Value &interval)
virtual void reschedule (ACE_Timer_Node_T< TYPE > *)
 Reschedule an "interval" ACE_Timer_Node.
virtual ACE_Timer_Node_T<
TYPE > * 
alloc_node (void)
virtual void free_node (ACE_Timer_Node_T< TYPE > *)

Private Member Functions

ACE_Timer_Node_T< TYPE > * remove (size_t slot)
void insert (ACE_Timer_Node_T< TYPE > *new_node)
 Insert new_node into the heap and restore the heap property.
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.
void reheap_down (ACE_Timer_Node_T< TYPE > *moved_node, size_t slot, size_t child)
 Restore the heap property, starting at slot.
void copy (size_t slot, ACE_Timer_Node_T< TYPE > *moved_node)
long timer_id (void)
long pop_freelist (void)
 Pops and returns a new timer id from the freelist.
void push_freelist (long old_id)
 Pushes old_id onto the freelist.
 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.
size_t cur_size_
 Current size of the heap.
size_t cur_limbo_
HEAP_ITERATORiterator_
 Iterator used to expire timers.
ACE_Timer_Node_T< TYPE > ** heap_
ssize_ttimer_ids_
size_t timer_ids_curr_
size_t timer_ids_min_free_
ACE_Timer_Node_T< TYPE > * preallocated_nodes_
ACE_Timer_Node_T< TYPE > * preallocated_nodes_freelist_
ACE_Unbounded_Set< ACE_Timer_Node_T<
TYPE > * > 
preallocated_node_set_

Friends

class ACE_Timer_Heap_Iterator_T< TYPE, FUNCTOR, ACE_LOCK >

Detailed Description

template<class TYPE, class FUNCTOR, class ACE_LOCK>
class ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >

Provides a very fast and predictable timer implementation.

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 86 of file Timer_Heap_T.h.


Member Typedef Documentation

template<class TYPE, class FUNCTOR, class ACE_LOCK>
typedef ACE_Timer_Heap_Iterator_T<TYPE, FUNCTOR, ACE_LOCK> ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::HEAP_ITERATOR

Definition at line 89 of file Timer_Heap_T.h.

template<class TYPE, class FUNCTOR, class ACE_LOCK>
typedef ACE_Timer_Queue_T<TYPE, FUNCTOR, ACE_LOCK> ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::INHERITED

Definition at line 92 of file Timer_Heap_T.h.


Constructor & Destructor Documentation

template<class TYPE, class FUNCTOR, class ACE_LOCK>
ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::ACE_Timer_Heap_T ( size_t  size,
bool  preallocated = false,
FUNCTOR *  upcall_functor = 0,
ACE_Free_List< ACE_Timer_Node_T< TYPE > > *  freelist = 0 
)

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).

Parameters:
size The maximum number of timers that can be inserted into the new object.
preallocated Default false, true then all the memory for the ACE_Timer_Node objects will be pre-allocated. This saves time and is more predictable (though it requires more space). Otherwise, timer nodes are allocated as needed.
freelist is the freelist of timer nodes.
upcall_functor If 0 Timer Heap will create a default FUNCTOR.

Definition at line 99 of file Timer_Heap_T.cpp.

References ACE_NEW, ACE_TRACE, ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::iterator_, ACE_Numeric_Limits< T >::max(), ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::max_size_, ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::preallocated_nodes_, and ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::preallocated_nodes_freelist_.

00104   : ACE_Timer_Queue_T<TYPE,FUNCTOR,ACE_LOCK> (upcall_functor, freelist),
00105     max_size_ (size),
00106     cur_size_ (0),
00107     cur_limbo_ (0),
00108     timer_ids_curr_ (0),
00109     timer_ids_min_free_ (0),
00110     preallocated_nodes_ (0),
00111     preallocated_nodes_freelist_ (0)
00112 {
00113   ACE_TRACE ("ACE_Timer_Heap_T::ACE_Timer_Heap_T");
00114 
00115   // Possibly reduce size to fit in a long.
00116   if (size > static_cast<size_t> (ACE_Numeric_Limits<long>::max ()))
00117     {
00118       size = static_cast<size_t> (ACE_Numeric_Limits<long>::max ());
00119       this->max_size_ = size;
00120     }
00121 
00122   // Create the heap array.
00123   ACE_NEW (this->heap_,
00124            ACE_Timer_Node_T<TYPE> *[size]);
00125 
00126   // Create the parallel
00127   ACE_NEW (this->timer_ids_,
00128            ssize_t[size]);
00129 
00130   // Initialize the "freelist," which uses negative values to
00131   // distinguish freelist elements from "pointers" into the <heap_>
00132   // array.
00133   for (size_t i = 0; i < size; ++i)
00134     this->timer_ids_[i] = -1;
00135 
00136   if (preallocated)
00137     {
00138       ACE_NEW (this->preallocated_nodes_,
00139                ACE_Timer_Node_T<TYPE>[size]);
00140 
00141       // Add allocated array to set of such arrays for deletion on
00142       // cleanup.
00143       this->preallocated_node_set_.insert (this->preallocated_nodes_);
00144 
00145       // Form the freelist by linking the next_ pointers together.
00146       for (size_t j = 1; j < size; ++j)
00147         this->preallocated_nodes_[j - 1].set_next (&this->preallocated_nodes_[j]);
00148 
00149       // NULL-terminate the freelist.
00150       this->preallocated_nodes_[size - 1].set_next (0);
00151 
00152       // Assign the freelist pointer to the front of the list.
00153       this->preallocated_nodes_freelist_ =
00154         &this->preallocated_nodes_[0];
00155     }
00156 
00157   ACE_NEW (iterator_,
00158            HEAP_ITERATOR (*this));
00159 }

template<class TYPE, class FUNCTOR, class ACE_LOCK>
ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::ACE_Timer_Heap_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 Heap will create a default FUNCTOR. freelist is the freelist of timer nodes. If 0, then a default freelist will be created. The default size will be ACE_DEFAULT_TIMERS and there will be no preallocation.

Definition at line 166 of file Timer_Heap_T.cpp.

References ACE_NEW, ACE_TRACE, ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::iterator_, ACE_Numeric_Limits< T >::max(), and ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::max_size_.

00169   : ACE_Timer_Queue_T<TYPE,FUNCTOR,ACE_LOCK> (upcall_functor, freelist),
00170     max_size_ (ACE_DEFAULT_TIMERS),
00171     cur_size_ (0),
00172     cur_limbo_ (0),
00173     timer_ids_curr_ (0),
00174     timer_ids_min_free_ (0),
00175     preallocated_nodes_ (0),
00176     preallocated_nodes_freelist_ (0)
00177 {
00178   ACE_TRACE ("ACE_Timer_Heap_T::ACE_Timer_Heap_T");
00179 
00180   // Possibly reduce size to fit in a long.
00181   if (this->max_size_ > static_cast<size_t> (ACE_Numeric_Limits<long>::max ()))
00182     this->max_size_ = static_cast<size_t> (ACE_Numeric_Limits<long>::max ());
00183 
00184   // Create the heap array.
00185     ACE_NEW (this->heap_,
00186              ACE_Timer_Node_T<TYPE> *[this->max_size_]);
00187 
00188   // Create the parallel array.
00189   ACE_NEW (this->timer_ids_,
00190            ssize_t[this->max_size_]);
00191 
00192   // Initialize the "freelist," which uses negative values to
00193   // distinguish freelist elements from "pointers" into the <heap_>
00194   // array.
00195   for (size_t i = 0; i < this->max_size_; ++i)
00196     this->timer_ids_[i] = -1;
00197 
00198   ACE_NEW (iterator_,
00199            HEAP_ITERATOR (*this));
00200 }

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

Destructor.

Definition at line 203 of file Timer_Heap_T.cpp.

References ACE_TRACE, ACE_Unbounded_Set_Ex_Iterator< T, ACE_Unbounded_Set_Default_Comparator< T > >::advance(), ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::cur_size_, ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::free_node(), ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::heap_, ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::iterator_, ACE_Unbounded_Set_Ex_Iterator< T, ACE_Unbounded_Set_Default_Comparator< T > >::next(), ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::preallocated_nodes_, ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::timer_ids_, and ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >::upcall_functor().

00204 {
00205   ACE_TRACE ("ACE_Timer_Heap_T::~ACE_Timer_Heap_T");
00206 
00207   delete iterator_;
00208 
00209   size_t current_size =
00210     this->cur_size_;
00211 
00212   // Clean up all the nodes still in the queue
00213   for (size_t i = 0; i < current_size; ++i)
00214     {
00215       // Grab the event_handler and act, then delete the node before calling
00216       // back to the handler. Prevents a handler from trying to cancel_timer()
00217       // inside handle_close(), ripping the current timer node out from
00218       // under us.
00219       TYPE eh = this->heap_[i]->get_type ();
00220       const void *act = this->heap_[i]->get_act ();
00221       this->free_node (this->heap_[i]);
00222       this->upcall_functor ().deletion (*this, eh, act);
00223     }
00224 
00225   delete [] this->heap_;
00226   delete [] this->timer_ids_;
00227 
00228   // clean up any preallocated timer nodes
00229   if (preallocated_nodes_ != 0)
00230     {
00231       ACE_Unbounded_Set_Iterator<ACE_Timer_Node_T<TYPE> *>
00232         set_iterator (this->preallocated_node_set_);
00233 
00234       for (ACE_Timer_Node_T<TYPE> **entry = 0;
00235            set_iterator.next (entry) !=0;
00236            set_iterator.advance ())
00237         delete [] *entry;
00238     }
00239 }

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


Member Function Documentation

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

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< TYPE, FUNCTOR, ACE_LOCK >.

Definition at line 633 of file Timer_Heap_T.cpp.

References ACE_NEW_RETURN, ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::grow_heap(), and ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::preallocated_nodes_freelist_.

00634 {
00635   ACE_Timer_Node_T<TYPE> *temp = 0;
00636 
00637   // Only allocate a node if we are *not* using the preallocated heap.
00638   if (this->preallocated_nodes_ == 0)
00639     ACE_NEW_RETURN (temp,
00640                     ACE_Timer_Node_T<TYPE>,
00641                     0);
00642   else
00643     {
00644       // check to see if the heap needs to grow
00645       if (this->preallocated_nodes_freelist_ == 0)
00646         this->grow_heap ();
00647 
00648       temp = this->preallocated_nodes_freelist_;
00649 
00650       // Remove the first element from the freelist.
00651       this->preallocated_nodes_freelist_ =
00652         this->preallocated_nodes_freelist_->get_next ();
00653     }
00654   return temp;
00655 }

template<class TYPE, class FUNCTOR, class ACE_LOCK>
int ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::cancel ( long  timer_id,
const void **  act = 0,
int  dont_call_handle_close = 1 
) [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. Returns 1 if cancellation succeeded and 0 if the timer_id wasn't found.

Implements ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >.

Definition at line 718 of file Timer_Heap_T.cpp.

References ACE_ASSERT, ACE_GUARD_RETURN, ACE_TRACE, ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::free_node(), ACE_Timer_Node_T< TYPE >::get_act(), ACE_Timer_Node_T< TYPE >::get_type(), ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::remove(), ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::timer_ids_, and ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >::upcall_functor().

00721 {
00722   ACE_TRACE ("ACE_Timer_Heap_T::cancel");
00723   ACE_MT (ACE_GUARD_RETURN (ACE_LOCK, ace_mon, this->mutex_, -1));
00724 
00725   // Locate the ACE_Timer_Node that corresponds to the timer_id.
00726 
00727   // Check to see if the timer_id is out of range
00728   if (timer_id < 0
00729       || (size_t) timer_id > this->max_size_)
00730     return 0;
00731 
00732   ssize_t timer_node_slot = this->timer_ids_[timer_id];
00733 
00734   // Check to see if timer_id is still valid.
00735   if (timer_node_slot < 0)
00736     return 0;
00737 
00738   if (timer_id != this->heap_[timer_node_slot]->get_timer_id ())
00739     {
00740       ACE_ASSERT (timer_id == this->heap_[timer_node_slot]->get_timer_id ());
00741       return 0;
00742     }
00743   else
00744     {
00745       ACE_Timer_Node_T<TYPE> *temp =
00746         this->remove (timer_node_slot);
00747 
00748       // Call the close hooks.
00749       int cookie = 0;
00750 
00751       // cancel_type() called once per <type>.
00752       this->upcall_functor ().cancel_type (*this,
00753                                            temp->get_type (),
00754                                            dont_call,
00755                                            cookie);
00756 
00757       // cancel_timer() called once per <timer>.
00758       this->upcall_functor ().cancel_timer (*this,
00759                                             temp->get_type (),
00760                                             dont_call,
00761                                             cookie);
00762 
00763       if (act != 0)
00764         *act = temp->get_act ();
00765 
00766       this->free_node (temp);
00767       return 1;
00768     }
00769 }

template<class TYPE, class FUNCTOR, class ACE_LOCK>
int ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::cancel ( const TYPE &  type,
int  dont_call_handle_close = 1 
) [virtual]

Cancel all timers associated with type. If dont_call_handle_close is 0then the <functor> will be invoked. Returns number of timers cancelled.

Implements ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >.

Definition at line 811 of file Timer_Heap_T.cpp.

References ACE_GUARD_RETURN, ACE_TRACE, ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::cur_size_, ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::free_node(), and ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >::upcall_functor().

00813 {
00814   ACE_TRACE ("ACE_Timer_Heap_T::cancel");
00815 
00816   ACE_MT (ACE_GUARD_RETURN (ACE_LOCK, ace_mon, this->mutex_, -1));
00817 
00818   int number_of_cancellations = 0;
00819 
00820   // Try to locate the ACE_Timer_Node that matches the timer_id.
00821 
00822   for (size_t i = 0; i < this->cur_size_; )
00823     {
00824       if (this->heap_[i]->get_type () == type)
00825         {
00826           ACE_Timer_Node_T<TYPE> *temp = this->remove (i);
00827 
00828           ++number_of_cancellations;
00829 
00830           this->free_node (temp);
00831 
00832           // We reset to zero so that we don't miss checking any nodes
00833           // if a reheapify occurs when a node is removed.  There
00834           // may be a better fix than this, however.
00835           i = 0;
00836         }
00837       else
00838         ++i;
00839     }
00840 
00841   // Call the close hooks.
00842   int cookie = 0;
00843 
00844   // cancel_type() called once per <type>.
00845   this->upcall_functor ().cancel_type (*this,
00846                                        type,
00847                                        dont_call,
00848                                        cookie);
00849 
00850   for (int j = 0;
00851        j < number_of_cancellations;
00852        ++j)
00853     {
00854       // cancel_timer() called once per <timer>.
00855       this->upcall_functor ().cancel_timer (*this,
00856                                             type,
00857                                             dont_call,
00858                                             cookie);
00859     }
00860 
00861   return number_of_cancellations;
00862 }

template<class TYPE, class FUNCTOR, class ACE_LOCK>
void ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::copy ( size_t  slot,
ACE_Timer_Node_T< TYPE > *  moved_node 
) [private]

Copy moved_node into the slot slot of <heap_> and move slot into the corresponding slot in the <timer_id_> array.

Definition at line 376 of file Timer_Heap_T.cpp.

References ACE_ASSERT, ACE_Timer_Node_T< TYPE >::get_timer_id(), ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::heap_, and ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::timer_ids_.

Referenced by ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::reheap_down(), ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::reheap_up(), and ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::remove().

00379 {
00380   // Insert <moved_node> into its new location in the heap.
00381   this->heap_[slot] = moved_node;
00382 
00383   ACE_ASSERT (moved_node->get_timer_id () >= 0
00384               && moved_node->get_timer_id () < (int) this->max_size_);
00385 
00386   // Update the corresponding slot in the parallel <timer_ids_> array.
00387   this->timer_ids_[moved_node->get_timer_id ()] = static_cast<ssize_t> (slot);
00388 }

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

Dump the state of an object.

Reimplemented from ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >.

Definition at line 338 of file Timer_Heap_T.cpp.

References ACE_BEGIN_DUMP, ACE_DEBUG, ACE_END_DUMP, ACE_TEXT, ACE_TRACE, ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::cur_size_, ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::heap_, LM_DEBUG, and ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::max_size_.

00339 {
00340 #if defined (ACE_HAS_DUMP)
00341   ACE_TRACE ("ACE_Timer_Heap_T::dump");
00342   ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
00343 
00344   ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\nmax_size_ = %d"), this->max_size_));
00345   ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\ncur_size_ = %d"), this->cur_size_));
00346   ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\ncur_limbo_= %d"), this->cur_limbo_));
00347   ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\nids_curr_ = %d"),
00348               this->timer_ids_curr_));
00349   ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\nmin_free_ = %d"),
00350               this->timer_ids_min_free_));
00351 
00352   ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\nheap_ = \n")));
00353 
00354   for (size_t i = 0; i < this->cur_size_; ++i)
00355     {
00356       ACE_DEBUG ((LM_DEBUG,
00357                   ACE_TEXT ("%d\n"),
00358                   i));
00359       this->heap_[i]->dump ();
00360     }
00361 
00362   ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\ntimer_ids_ = \n")));
00363 
00364   for (size_t j = 0; j < this->max_size_; ++j)
00365     ACE_DEBUG ((LM_DEBUG,
00366                 ACE_TEXT ("%d\t%d\n"),
00367                 j,
00368                 this->timer_ids_[j]));
00369 
00370   ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00371 #endif /* ACE_HAS_DUMP */
00372 }

template<class TYPE, class FUNCTOR, class ACE_LOCK>
const ACE_Time_Value & ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::earliest_time ( void   )  const [virtual]

Returns the time of the earliest node in the Timer_Queue. Must be called on a non-empty queue.

Implements ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >.

Definition at line 330 of file Timer_Heap_T.cpp.

References ACE_TRACE, and ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::heap_.

00331 {
00332   ACE_TRACE ("ACE_Timer_Heap_T::earliest_time");
00333   return this->heap_[0]->get_timer_value ();
00334 }

template<class TYPE, class FUNCTOR, class ACE_LOCK>
void ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::free_node ( ACE_Timer_Node_T< TYPE > *   )  [protected, virtual]

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< TYPE, FUNCTOR, ACE_LOCK >.

Definition at line 659 of file Timer_Heap_T.cpp.

References ACE_Timer_Node_T< TYPE >::get_timer_id(), ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::preallocated_nodes_freelist_, ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::push_freelist(), and ACE_Timer_Node_T< TYPE >::set_next().

Referenced by ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::cancel(), and ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::~ACE_Timer_Heap_T().

00661 {
00662   // Return this timer id to the freelist.
00663   this->push_freelist (node->get_timer_id ());
00664 
00665   // Only free up a node if we are *not* using the preallocated heap.
00666   if (this->preallocated_nodes_ == 0)
00667     delete node;
00668   else
00669     {
00670       node->set_next (this->preallocated_nodes_freelist_);
00671       this->preallocated_nodes_freelist_ = node;
00672     }
00673 }

template<class TYPE, class FUNCTOR, class ACE_LOCK>
ACE_Timer_Node_T< TYPE > * ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::get_first ( void   )  [virtual]

Reads the earliest node from the queue and returns it.

Implements ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >.

Definition at line 880 of file Timer_Heap_T.cpp.

References ACE_TRACE, ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::cur_size_, and ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::heap_.

00881 {
00882   ACE_TRACE ("ACE_Timer_Heap_T::get_first");
00883 
00884   return this->cur_size_ == 0 ? 0 : this->heap_[0];
00885 }

template<class TYPE, class FUNCTOR, class ACE_LOCK>
void ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::grow_heap ( void   )  [private]

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 520 of file Timer_Heap_T.cpp.

References ACE_NEW, ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::heap_, ACE_Unbounded_Set_Ex< T, C >::insert(), ACE_Numeric_Limits< T >::max(), ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::max_size_, ACE_OS::memcpy(), ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::preallocated_node_set_, ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::preallocated_nodes_, ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::preallocated_nodes_freelist_, ACE_Timer_Node_T< TYPE >::set_next(), ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::timer_ids_, and ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::timer_ids_min_free_.

Referenced by ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::alloc_node(), and ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::insert().

00521 {
00522   // All the containers will double in size from max_size_.
00523   size_t new_size = this->max_size_ * 2;
00524 
00525 #if 0
00526   // Yikes - there's no way to flag a failure of going out of range of
00527   // a 'long' - this is a problem that should be addressed at some point.
00528   if (new_size > ACE_Numeric_Limits<long>::max ())
00529     new_size = ACE_Numeric_Limits<long>::max ();
00530 
00531   if (new_size <= this->max_size_)   // We are already at the limit
00532     {
00533       errno = ENOMEM;
00534       return -1;
00535     }
00536 #endif /* 0 */
00537 
00538    // First grow the heap itself.
00539 
00540   ACE_Timer_Node_T<TYPE> **new_heap = 0;
00541 
00542   ACE_NEW (new_heap,
00543            ACE_Timer_Node_T<TYPE> *[new_size]);
00544 
00545   ACE_OS::memcpy (new_heap,
00546                   this->heap_,
00547                   this->max_size_ * sizeof *new_heap);
00548   delete [] this->heap_;
00549   this->heap_ = new_heap;
00550 
00551   // Grow the array of timer ids.
00552 
00553   ssize_t *new_timer_ids = 0;
00554 
00555   ACE_NEW (new_timer_ids,
00556            ssize_t[new_size]);
00557 
00558   ACE_OS::memcpy (new_timer_ids,
00559                   this->timer_ids_,
00560                   this->max_size_ * sizeof (ssize_t));
00561 
00562   delete [] timer_ids_;
00563   this->timer_ids_ = new_timer_ids;
00564 
00565   // And add the new elements to the end of the "freelist".
00566   for (size_t i = this->max_size_; i < new_size; ++i)
00567     this->timer_ids_[i] = -(static_cast<ssize_t> (i) + 1);
00568 
00569    // Grow the preallocation array (if using preallocation)
00570   if (this->preallocated_nodes_ != 0)
00571     {
00572       // Create a new array with max_size elements to link in to
00573       // existing list.
00574       ACE_NEW (this->preallocated_nodes_,
00575                ACE_Timer_Node_T<TYPE>[this->max_size_]);
00576 
00577       // Add it to the set for later deletion
00578       this->preallocated_node_set_.insert (this->preallocated_nodes_);
00579 
00580       // Link new nodes together (as for original list).
00581       for (size_t k = 1; k < this->max_size_; ++k)
00582         this->preallocated_nodes_[k - 1].set_next (&this->preallocated_nodes_[k]);
00583 
00584       // NULL-terminate the new list.
00585       this->preallocated_nodes_[this->max_size_ - 1].set_next (0);
00586 
00587       // Link new array to the end of the existling list.
00588       if (this->preallocated_nodes_freelist_ == 0)
00589         this->preallocated_nodes_freelist_ =
00590           &preallocated_nodes_[0];
00591       else
00592         {
00593           ACE_Timer_Node_T<TYPE> *previous =
00594             this->preallocated_nodes_freelist_;
00595 
00596           for (ACE_Timer_Node_T<TYPE> *current = this->preallocated_nodes_freelist_->get_next ();
00597                current != 0;
00598                current = current->get_next ())
00599             previous = current;
00600 
00601           previous->set_next (&this->preallocated_nodes_[0]);
00602         }
00603     }
00604 
00605   this->max_size_ = new_size;
00606   // Force rescan of list from beginning for a free slot (I think...)
00607   // This fixed Bugzilla #2447.
00608   this->timer_ids_min_free_ = this->max_size_;
00609 }

template<class TYPE, class FUNCTOR, class ACE_LOCK>
void ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::insert ( ACE_Timer_Node_T< TYPE > *  new_node  )  [private]

Insert new_node into the heap and restore the heap property.

Definition at line 506 of file Timer_Heap_T.cpp.

References ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::cur_size_, ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::grow_heap(), and ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::reheap_up().

Referenced by ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::schedule_i().

00508 {
00509   if (this->cur_size_ + this->cur_limbo_ + 2 >= this->max_size_)
00510     this->grow_heap ();
00511 
00512   this->reheap_up (new_node,
00513                    this->cur_size_,
00514                    ACE_HEAP_PARENT (this->cur_size_));
00515   this->cur_size_++;
00516 }

template<class TYPE, class FUNCTOR, class ACE_LOCK>
bool ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::is_empty ( void   )  const [virtual]

True if heap is empty, else false.

Implements ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >.

Definition at line 313 of file Timer_Heap_T.cpp.

References ACE_TRACE, and ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::cur_size_.

00314 {
00315   ACE_TRACE ("ACE_Timer_Heap_T::is_empty");
00316   return this->cur_size_ == 0;
00317 }

template<class TYPE, class FUNCTOR, class ACE_LOCK>
ACE_Timer_Queue_Iterator_T< TYPE, FUNCTOR, ACE_LOCK > & ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::iter ( void   )  [virtual]

Returns a pointer to this ACE_Timer_Queue's iterator.

Implements ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >.

Definition at line 321 of file Timer_Heap_T.cpp.

References ACE_Timer_Heap_Iterator_T< TYPE, FUNCTOR, ACE_LOCK >::first(), and ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::iterator_.

00322 {
00323   this->iterator_->first ();
00324   return *this->iterator_;
00325 }

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

template<class TYPE, class FUNCTOR, class ACE_LOCK>
long ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::pop_freelist ( void   )  [private]

Pops and returns a new timer id from the freelist.

Definition at line 243 of file Timer_Heap_T.cpp.

References ACE_ASSERT, ACE_TRACE, ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::max_size_, ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::timer_ids_curr_, and ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::timer_ids_min_free_.

Referenced by ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::timer_id().

00244 {
00245   ACE_TRACE ("ACE_Timer_Heap_T::pop_freelist");
00246 
00247   // Scan for a free timer ID. Note that since this function is called
00248   // _after_ the check for a full timer heap, we are guaranteed to find
00249   // a free ID, even if we need to wrap around and start reusing freed IDs.
00250   // On entry, the curr_ index is at the previous ID given out; start
00251   // up where we left off last time.
00252   // NOTE - a timer_ids_ slot with -2 is out of the heap, but not freed.
00253   // It must be either freed (free_node) or rescheduled (reschedule).
00254   ++this->timer_ids_curr_;
00255   while (this->timer_ids_curr_ < this->max_size_ &&
00256          (this->timer_ids_[this->timer_ids_curr_] >= 0 ||
00257           this->timer_ids_[this->timer_ids_curr_] == -2  ))
00258     ++this->timer_ids_curr_;
00259   if (this->timer_ids_curr_ == this->max_size_)
00260     {
00261       ACE_ASSERT (this->timer_ids_min_free_ < this->max_size_);
00262       this->timer_ids_curr_ = this->timer_ids_min_free_;
00263       // We restarted the free search at min. Since min won't be
00264       // free anymore, and curr_ will just keep marching up the list
00265       // on each successive need for an ID, reset min_free_ to the
00266       // size of the list until an ID is freed that curr_ has already
00267       // gone past (see push_freelist).
00268       this->timer_ids_min_free_ = this->max_size_;
00269     }
00270 
00271   return static_cast<long> (this->timer_ids_curr_);
00272 }

template<class TYPE, class FUNCTOR, class ACE_LOCK>
void ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::push_freelist ( long  old_id  )  [private]

Pushes old_id onto the freelist.

Definition at line 276 of file Timer_Heap_T.cpp.

References ACE_ASSERT, ACE_TRACE, ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::cur_limbo_, ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::cur_size_, ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::timer_ids_, ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::timer_ids_curr_, and ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::timer_ids_min_free_.

Referenced by ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::free_node().

00277 {
00278   ACE_TRACE ("ACE_Timer_Heap_T::push_freelist");
00279 
00280   // Since this ID has already been checked by one of the public
00281   // functions, it's safe to cast it here.
00282   size_t oldid = static_cast<size_t> (old_id);
00283 
00284   // The freelist values in the <timer_ids_> are negative, so set the
00285   // freed entry back to 'free'. If this is the new lowest value free
00286   // timer ID that curr_ won't see on it's normal march through the list,
00287   // remember it.
00288   ACE_ASSERT (this->timer_ids_[oldid] >= 0 || this->timer_ids_[oldid] == -2);
00289   if (this->timer_ids_[oldid] == -2)
00290     --this->cur_limbo_;
00291   else
00292     --this->cur_size_;
00293   this->timer_ids_[oldid] = -1;
00294   if (oldid < this->timer_ids_min_free_ && oldid <= this->timer_ids_curr_)
00295     this->timer_ids_min_free_ = oldid;
00296   return;
00297 }

template<class TYPE, class FUNCTOR, class ACE_LOCK>
void ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::reheap_down ( ACE_Timer_Node_T< TYPE > *  moved_node,
size_t  slot,
size_t  child 
) [private]

Restore the heap property, starting at slot.

Definition at line 441 of file Timer_Heap_T.cpp.

References ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::copy(), ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::cur_size_, ACE_Timer_Node_T< TYPE >::get_timer_value(), and ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::heap_.

00445 {
00446   // Restore the heap property after a deletion.
00447 
00448   while (child < this->cur_size_)
00449     {
00450       // Choose the smaller of the two children.
00451       if (child + 1 < this->cur_size_
00452           && this->heap_[child + 1]->get_timer_value ()
00453           < this->heap_[child]->get_timer_value ())
00454         child++;
00455 
00456       // Perform a <copy> if the child has a larger timeout value than
00457       // the <moved_node>.
00458       if (this->heap_[child]->get_timer_value ()
00459           < moved_node->get_timer_value ())
00460         {
00461           this->copy (slot,
00462                       this->heap_[child]);
00463           slot = child;
00464           child = ACE_HEAP_LCHILD (child);
00465         }
00466       else
00467         // We've found our location in the heap.
00468         break;
00469     }
00470 
00471   this->copy (slot, moved_node);
00472 }

template<class TYPE, class FUNCTOR, class ACE_LOCK>
void ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::reheap_up ( ACE_Timer_Node_T< TYPE > *  new_node,
size_t  slot,
size_t  parent 
) [private]

Restore the heap property, starting at slot.

Definition at line 476 of file Timer_Heap_T.cpp.

References ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::copy(), ACE_Timer_Node_T< TYPE >::get_timer_value(), and ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::heap_.

Referenced by ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::insert(), and ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::remove().

00480 {
00481   // Restore the heap property after an insertion.
00482 
00483   while (slot > 0)
00484     {
00485       // If the parent node is greater than the <moved_node> we need
00486       // to copy it down.
00487       if (moved_node->get_timer_value ()
00488           < this->heap_[parent]->get_timer_value ())
00489         {
00490           this->copy (slot, this->heap_[parent]);
00491           slot = parent;
00492           parent = ACE_HEAP_PARENT (slot);
00493         }
00494       else
00495         break;
00496     }
00497 
00498   // Insert the new node into its proper resting place in the heap and
00499   // update the corresponding slot in the parallel <timer_ids> array.
00500   this->copy (slot,
00501               moved_node);
00502 }

template<class TYPE, class FUNCTOR, class ACE_LOCK>
ACE_Timer_Node_T< TYPE > * ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::remove ( size_t  slot  )  [private]

Remove and return the sloth ACE_Timer_Node and restore the heap property.

Definition at line 397 of file Timer_Heap_T.cpp.

References ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::copy(), ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::cur_limbo_, ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::cur_size_, ACE_Timer_Node_T< TYPE >::get_timer_id(), ACE_Timer_Node_T< TYPE >::get_timer_value(), ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::heap_, ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::reheap_up(), and ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::timer_ids_.

Referenced by ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::cancel(), and ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::remove_first().

00398 {
00399   ACE_Timer_Node_T<TYPE> *removed_node =
00400     this->heap_[slot];
00401 
00402   // NOTE - the cur_size_ is being decremented since the queue has one
00403   // less active timer in it. However, this ACE_Timer_Node is not being
00404   // freed, and there is still a place for it in timer_ids_ (the timer ID
00405   // is not being relinquished). The node can still be rescheduled, or
00406   // it can be freed via free_node.
00407   --this->cur_size_;
00408 
00409   // Only try to reheapify if we're not deleting the last entry.
00410 
00411   if (slot < this->cur_size_)
00412     {
00413       ACE_Timer_Node_T<TYPE> *moved_node =
00414         this->heap_[this->cur_size_];
00415 
00416       // Move the end node to the location being removed and update
00417       // the corresponding slot in the parallel <timer_ids> array.
00418       this->copy (slot, moved_node);
00419 
00420       // If the <moved_node->time_value_> is great than or equal its
00421       // parent it needs be moved down the heap.
00422       size_t parent = ACE_HEAP_PARENT (slot);
00423 
00424       if (moved_node->get_timer_value ()
00425           >= this->heap_[parent]->get_timer_value ())
00426         this->reheap_down (moved_node,
00427                            slot,
00428                            ACE_HEAP_LCHILD (slot));
00429       else
00430         this->reheap_up (moved_node,
00431                          slot,
00432                          parent);
00433     }
00434 
00435   this->timer_ids_[removed_node->get_timer_id ()] = -2;
00436   ++this->cur_limbo_;
00437   return removed_node;
00438 }

template<class TYPE, class FUNCTOR, class ACE_LOCK>
ACE_Timer_Node_T< TYPE > * ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::remove_first ( void   )  [virtual]

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 reschedule() or free_node() after this function returns. Thus, this function is for support of ACE_Timer_Queue::expire and should not be used unadvisedly in other conditions.

Implements ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >.

Definition at line 868 of file Timer_Heap_T.cpp.

References ACE_TRACE, and ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::remove().

00869 {
00870   ACE_TRACE ("ACE_Timer_Heap_T::remove_first");
00871 
00872   if (this->cur_size_ == 0)
00873     return 0;
00874 
00875   return this->remove (0);
00876 }

template<class TYPE, class FUNCTOR, class ACE_LOCK>
void ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::reschedule ( ACE_Timer_Node_T< TYPE > *   )  [protected, virtual]

Reschedule an "interval" ACE_Timer_Node.

Implements ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >.

Definition at line 616 of file Timer_Heap_T.cpp.

References ACE_TRACE, and ACE_Timer_Node_T< TYPE >::get_timer_id().

00618 {
00619   ACE_TRACE ("ACE_Timer_Heap_T::reschedule");
00620 
00621   // If we are rescheduling, then the most recent call was to
00622   // remove_first (). That called remove () to remove the node from the
00623   // heap, but did not free the timer ID. The ACE_Timer_Node still has
00624   // its assigned ID - just needs to be inserted at the new proper
00625   // place, and the heap restored properly.
00626   if (this->timer_ids_[expired->get_timer_id ()] == -2)
00627     --this->cur_limbo_;
00628   this->insert (expired);
00629 }

template<class TYPE, class FUNCTOR, class ACE_LOCK>
int ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::reset_interval ( long  timer_id,
const ACE_Time_Value interval 
) [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.

Implements ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >.

Definition at line 775 of file Timer_Heap_T.cpp.

References ACE_ASSERT, ACE_GUARD_RETURN, ACE_TRACE, ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::heap_, and ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::timer_ids_.

00777 {
00778   ACE_TRACE ("ACE_Timer_Heap_T::reset_interval");
00779   ACE_MT (ACE_GUARD_RETURN (ACE_LOCK, ace_mon, this->mutex_, -1));
00780 
00781   // Locate the ACE_Timer_Node that corresponds to the timer_id.
00782 
00783   // Check to see if the timer_id is out of range
00784   if (timer_id < 0
00785       || (size_t) timer_id > this->max_size_)
00786     return -1;
00787 
00788   ssize_t timer_node_slot = this->timer_ids_[timer_id];
00789 
00790   // Check to see if timer_id is still valid.
00791   if (timer_node_slot < 0)
00792     return -1;
00793 
00794   if (timer_id != this->heap_[timer_node_slot]->get_timer_id ())
00795     {
00796       ACE_ASSERT (timer_id == this->heap_[timer_node_slot]->get_timer_id ());
00797       return -1;
00798     }
00799   else
00800     {
00801       // Reset the timer interval
00802       this->heap_[timer_node_slot]->set_interval (interval);
00803       return 0;
00804     }
00805 }

template<class TYPE, class FUNCTOR, class ACE_LOCK>
long ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::schedule_i ( const TYPE &  type,
const void *  act,
const ACE_Time_Value future_time,
const ACE_Time_Value interval 
) [protected, virtual]

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< TYPE, FUNCTOR, ACE_LOCK >.

Definition at line 680 of file Timer_Heap_T.cpp.

References ACE_ALLOCATOR_RETURN, ACE_TRACE, ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::insert(), ACE_Timer_Node_T< TYPE >::set(), and ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::timer_id().

00685 {
00686   ACE_TRACE ("ACE_Timer_Heap_T::schedule_i");
00687 
00688   if ((this->cur_size_ + this->cur_limbo_) < this->max_size_)
00689     {
00690       // Obtain the next unique sequence number.
00691       long timer_id = this->timer_id ();
00692 
00693       // Obtain the memory to the new node.
00694       ACE_Timer_Node_T<TYPE> *temp = 0;
00695 
00696       ACE_ALLOCATOR_RETURN (temp,
00697                             this->alloc_node (),
00698                             -1);
00699       temp->set (type,
00700                  act,
00701                  future_time,
00702                  interval,
00703                  0,
00704                  timer_id);
00705 
00706       this->insert (temp);
00707       return timer_id;
00708     }
00709   else
00710     return -1;
00711 }

template<class TYPE, class FUNCTOR, class ACE_LOCK>
long ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::timer_id ( void   )  [private]

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 301 of file Timer_Heap_T.cpp.

References ACE_TRACE, and ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::pop_freelist().

Referenced by ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::schedule_i().

00302 {
00303   ACE_TRACE ("ACE_Timer_Heap_T::timer_id");
00304 
00305   // Return the next item off the freelist and use it as the timer id.
00306   return this->pop_freelist ();
00307 }


Friends And Related Function Documentation

template<class TYPE, class FUNCTOR, class ACE_LOCK>
friend class ACE_Timer_Heap_Iterator_T< TYPE, FUNCTOR, ACE_LOCK > [friend]

Definition at line 90 of file Timer_Heap_T.h.


Member Data Documentation

template<class TYPE, class FUNCTOR, class ACE_LOCK>
size_t ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::cur_limbo_ [private]

Number of heap entries in transition (removed from the queue, but not freed) and may be rescheduled or freed.

Definition at line 272 of file Timer_Heap_T.h.

Referenced by ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::push_freelist(), and ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::remove().

template<class TYPE, class FUNCTOR, class ACE_LOCK>
size_t ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::cur_size_ [private]

Current size of the heap.

Definition at line 268 of file Timer_Heap_T.h.

Referenced by ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::cancel(), ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::dump(), ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::get_first(), ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::insert(), ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::is_empty(), ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::push_freelist(), ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::reheap_down(), ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::remove(), and ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::~ACE_Timer_Heap_T().

template<class TYPE, class FUNCTOR, class ACE_LOCK>
ACE_Timer_Node_T<TYPE>** ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::heap_ [private]

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 283 of file Timer_Heap_T.h.

Referenced by ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::copy(), ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::dump(), ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::earliest_time(), ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::get_first(), ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::grow_heap(), ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::reheap_down(), ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::reheap_up(), ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::remove(), ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::reset_interval(), and ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::~ACE_Timer_Heap_T().

template<class TYPE, class FUNCTOR, class ACE_LOCK>
HEAP_ITERATOR* ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::iterator_ [private]

Iterator used to expire timers.

Definition at line 275 of file Timer_Heap_T.h.

Referenced by ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::ACE_Timer_Heap_T(), ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::iter(), and ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::~ACE_Timer_Heap_T().

template<class TYPE, class FUNCTOR, class ACE_LOCK>
size_t ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::max_size_ [private]

Maximum size of the heap.

Definition at line 265 of file Timer_Heap_T.h.

Referenced by ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::ACE_Timer_Heap_T(), ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::dump(), ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::grow_heap(), and ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::pop_freelist().

template<class TYPE, class FUNCTOR, class ACE_LOCK>
ACE_Unbounded_Set<ACE_Timer_Node_T<TYPE> *> ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::preallocated_node_set_ [private]

Set of pointers to the arrays of preallocated timer nodes. Used to delete the allocated memory when required.

Definition at line 320 of file Timer_Heap_T.h.

Referenced by ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::grow_heap().

template<class TYPE, class FUNCTOR, class ACE_LOCK>
ACE_Timer_Node_T<TYPE>* ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::preallocated_nodes_ [private]

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 312 of file Timer_Heap_T.h.

Referenced by ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::ACE_Timer_Heap_T(), ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::grow_heap(), and ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::~ACE_Timer_Heap_T().

template<class TYPE, class FUNCTOR, class ACE_LOCK>
ACE_Timer_Node_T<TYPE>* ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::preallocated_nodes_freelist_ [private]

This points to the head of the <preallocated_nodes_> freelist, which is organized as a stack.

Definition at line 316 of file Timer_Heap_T.h.

Referenced by ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::ACE_Timer_Heap_T(), ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::alloc_node(), ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::free_node(), and ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::grow_heap().

template<class TYPE, class FUNCTOR, class ACE_LOCK>
ssize_t* ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::timer_ids_ [private]

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 295 of file Timer_Heap_T.h.

Referenced by ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::cancel(), ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::copy(), ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::grow_heap(), ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::push_freelist(), ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::remove(), ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::reset_interval(), and ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::~ACE_Timer_Heap_T().

template<class TYPE, class FUNCTOR, class ACE_LOCK>
size_t ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::timer_ids_curr_ [private]

"Pointer" to the element in the <timer_ids_> array that was last given out as a timer ID.

Definition at line 299 of file Timer_Heap_T.h.

Referenced by ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::pop_freelist(), and ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::push_freelist().

template<class TYPE, class FUNCTOR, class ACE_LOCK>
size_t ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::timer_ids_min_free_ [private]

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 304 of file Timer_Heap_T.h.

Referenced by ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::grow_heap(), ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::pop_freelist(), and ACE_Timer_Heap_T< TYPE, FUNCTOR, ACE_LOCK >::push_freelist().


The documentation for this class was generated from the following files:
Generated on Tue Feb 2 17:35:48 2010 for ACE by  doxygen 1.4.7