diff options
author | irfan <irfan@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1997-05-06 01:14:18 +0000 |
---|---|---|
committer | irfan <irfan@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1997-05-06 01:14:18 +0000 |
commit | e03e2e91bcd629d3386ea1059a1a893d976dd4e6 (patch) | |
tree | 530cecb99e4c89e016a84d14b666f60059f53cb1 /ace/Timer_Heap_T.cpp | |
parent | 385f921ff545baca5e95604326344d0584808ebd (diff) | |
download | ATCD-e03e2e91bcd629d3386ea1059a1a893d976dd4e6.tar.gz |
*** empty log message ***
Diffstat (limited to 'ace/Timer_Heap_T.cpp')
-rw-r--r-- | ace/Timer_Heap_T.cpp | 172 |
1 files changed, 86 insertions, 86 deletions
diff --git a/ace/Timer_Heap_T.cpp b/ace/Timer_Heap_T.cpp index b0f4df74a0c..3273741b2a7 100644 --- a/ace/Timer_Heap_T.cpp +++ b/ace/Timer_Heap_T.cpp @@ -11,17 +11,17 @@ #define ACE_HEAP_PARENT(X) (X == 0 ? 0 : (((X) - 1) / 2)) #define ACE_HEAP_LCHILD(X) (((X)+(X))+1) -template <class TYPE, class FUNCTOR> -ACE_Timer_Heap_Iterator_T<TYPE, FUNCTOR>::ACE_Timer_Heap_Iterator_T (ACE_Timer_Heap_T<TYPE, FUNCTOR> &heap) +template <class TYPE, class FUNCTOR, class LOCK> +ACE_Timer_Heap_Iterator_T<TYPE, FUNCTOR, LOCK>::ACE_Timer_Heap_Iterator_T (ACE_Timer_Heap_T<TYPE, FUNCTOR, LOCK> &heap) : timer_heap_ (heap) { ACE_TRACE ("ACE_Timer_Heap_Iterator::ACE_Timer_Heap_Iterator"); } -template <class TYPE, class FUNCTOR> int -ACE_Timer_Heap_Iterator_T<TYPE, FUNCTOR>::next (ACE_Timer_Node_T<TYPE, FUNCTOR> *&node, - const ACE_Time_Value &cur_time) +template <class TYPE, class FUNCTOR, class LOCK> int +ACE_Timer_Heap_Iterator_T<TYPE, FUNCTOR, LOCK>::next (ACE_Timer_Node_T<TYPE, FUNCTOR, LOCK> *&node, + const ACE_Time_Value &cur_time) { ACE_TRACE ("ACE_Timer_Heap_Iterator::next"); @@ -37,10 +37,10 @@ ACE_Timer_Heap_Iterator_T<TYPE, FUNCTOR>::next (ACE_Timer_Node_T<TYPE, FUNCTOR> } } -template <class TYPE, class FUNCTOR> -ACE_Timer_Heap_T<TYPE, FUNCTOR>::ACE_Timer_Heap_T (size_t size, - int preallocate, - FUNCTOR *upcall_functor) +template <class TYPE, class FUNCTOR, class LOCK> +ACE_Timer_Heap_T<TYPE, FUNCTOR, LOCK>::ACE_Timer_Heap_T (size_t size, + int preallocate, + FUNCTOR *upcall_functor) : INHERITED (upcall_functor), max_size_ (size), cur_size_ (0), @@ -52,7 +52,7 @@ ACE_Timer_Heap_T<TYPE, FUNCTOR>::ACE_Timer_Heap_T (size_t size, ACE_TRACE ("ACE_Timer_Heap::ACE_Timer_Heap"); // Create the heap array. - ACE_NEW (this->heap_, (ACE_Timer_Node_T<TYPE, FUNCTOR> *[size])); + ACE_NEW (this->heap_, (ACE_Timer_Node_T<TYPE, FUNCTOR, LOCK> *[size])); // Create the parallel ACE_NEW (this->timer_ids_, long[size]); @@ -66,7 +66,7 @@ ACE_Timer_Heap_T<TYPE, FUNCTOR>::ACE_Timer_Heap_T (size_t size, if (preallocate) { ACE_NEW (this->preallocated_nodes_, - (ACE_Timer_Node_T<TYPE, FUNCTOR>[size])); + (ACE_Timer_Node_T<TYPE, FUNCTOR, LOCK>[size])); // Add allocated array to set of such arrays for deletion // on cleanup. @@ -86,8 +86,8 @@ ACE_Timer_Heap_T<TYPE, FUNCTOR>::ACE_Timer_Heap_T (size_t size, } } -template <class TYPE, class FUNCTOR> -ACE_Timer_Heap_T<TYPE, FUNCTOR>::~ACE_Timer_Heap_T (void) +template <class TYPE, class FUNCTOR, class LOCK> +ACE_Timer_Heap_T<TYPE, FUNCTOR, LOCK>::~ACE_Timer_Heap_T (void) { ACE_TRACE ("ACE_Timer_Heap::~ACE_Timer_Heap"); delete [] this->heap_; @@ -96,10 +96,10 @@ ACE_Timer_Heap_T<TYPE, FUNCTOR>::~ACE_Timer_Heap_T (void) // clean up any preallocated timer nodes if (preallocated_nodes_ != 0) { - ACE_Unbounded_Set_Iterator<ACE_Timer_Node_T<TYPE, FUNCTOR> *> + ACE_Unbounded_Set_Iterator<ACE_Timer_Node_T<TYPE, FUNCTOR, LOCK> *> set_iterator (this->preallocated_node_set_); - for (ACE_Timer_Node_T<TYPE, FUNCTOR> **entry = 0; + for (ACE_Timer_Node_T<TYPE, FUNCTOR, LOCK> **entry = 0; set_iterator.next (entry) !=0; set_iterator.advance ()) delete [] *entry; @@ -107,8 +107,8 @@ ACE_Timer_Heap_T<TYPE, FUNCTOR>::~ACE_Timer_Heap_T (void) } -template <class TYPE, class FUNCTOR> int -ACE_Timer_Heap_T<TYPE, FUNCTOR>::pop_freelist (void) +template <class TYPE, class FUNCTOR, class LOCK> int +ACE_Timer_Heap_T<TYPE, FUNCTOR, LOCK>::pop_freelist (void) { ACE_TRACE ("ACE_Timer_Heap::pop_freelist"); @@ -120,8 +120,8 @@ ACE_Timer_Heap_T<TYPE, FUNCTOR>::pop_freelist (void) } -template <class TYPE, class FUNCTOR> void -ACE_Timer_Heap_T<TYPE, FUNCTOR>::push_freelist (int old_id) +template <class TYPE, class FUNCTOR, class LOCK> void +ACE_Timer_Heap_T<TYPE, FUNCTOR, LOCK>::push_freelist (int old_id) { ACE_TRACE ("ACE_Timer_Heap::push_freelist"); @@ -132,8 +132,8 @@ ACE_Timer_Heap_T<TYPE, FUNCTOR>::push_freelist (int old_id) } -template <class TYPE, class FUNCTOR> int -ACE_Timer_Heap_T<TYPE, FUNCTOR>::timer_id (void) +template <class TYPE, class FUNCTOR, class LOCK> int +ACE_Timer_Heap_T<TYPE, FUNCTOR, LOCK>::timer_id (void) { ACE_TRACE ("ACE_Timer_Heap::timer_id"); @@ -144,16 +144,16 @@ ACE_Timer_Heap_T<TYPE, FUNCTOR>::timer_id (void) // Checks if queue is empty. -template <class TYPE, class FUNCTOR> int -ACE_Timer_Heap_T<TYPE, FUNCTOR>::is_empty (void) const +template <class TYPE, class FUNCTOR, class LOCK> int +ACE_Timer_Heap_T<TYPE, FUNCTOR, LOCK>::is_empty (void) const { ACE_TRACE ("ACE_Timer_Heap::is_empty"); return this->cur_size_ == 0; } -template <class TYPE, class FUNCTOR> ACE_Timer_Queue_Iterator_T<TYPE, FUNCTOR> & -ACE_Timer_Heap_T<TYPE, FUNCTOR>::iter (void) +template <class TYPE, class FUNCTOR, class LOCK> ACE_Timer_Queue_Iterator_T<TYPE, FUNCTOR, LOCK> & +ACE_Timer_Heap_T<TYPE, FUNCTOR, LOCK>::iter (void) { return this->iterator_; } @@ -161,16 +161,16 @@ ACE_Timer_Heap_T<TYPE, FUNCTOR>::iter (void) // Returns earliest time in a non-empty queue. -template <class TYPE, class FUNCTOR> const ACE_Time_Value & -ACE_Timer_Heap_T<TYPE, FUNCTOR>::earliest_time (void) const +template <class TYPE, class FUNCTOR, class LOCK> const ACE_Time_Value & +ACE_Timer_Heap_T<TYPE, FUNCTOR, LOCK>::earliest_time (void) const { ACE_TRACE ("ACE_Timer_Heap::earliest_time"); return this->heap_[0]->timer_value_; } -template <class TYPE, class FUNCTOR> void -ACE_Timer_Heap_T<TYPE, FUNCTOR>::dump (void) const +template <class TYPE, class FUNCTOR, class LOCK> void +ACE_Timer_Heap_T<TYPE, FUNCTOR, LOCK>::dump (void) const { ACE_TRACE ("ACE_Timer_Heap::dump"); ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this)); @@ -193,8 +193,8 @@ ACE_Timer_Heap_T<TYPE, FUNCTOR>::dump (void) const ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP)); } -template <class TYPE, class FUNCTOR> void -ACE_Timer_Heap_T<TYPE, FUNCTOR>::copy (int index, ACE_Timer_Node_T<TYPE, FUNCTOR> *moved_node) +template <class TYPE, class FUNCTOR, class LOCK> void +ACE_Timer_Heap_T<TYPE, FUNCTOR, LOCK>::copy (int index, ACE_Timer_Node_T<TYPE, FUNCTOR, LOCK> *moved_node) { // Insert <moved_node> into its new location in the heap. this->heap_[index] = moved_node; @@ -205,10 +205,10 @@ ACE_Timer_Heap_T<TYPE, FUNCTOR>::copy (int index, ACE_Timer_Node_T<TYPE, FUNCTOR this->timer_ids_[moved_node->timer_id_] = index; } -template <class TYPE, class FUNCTOR> ACE_Timer_Node_T<TYPE, FUNCTOR> * -ACE_Timer_Heap_T<TYPE, FUNCTOR>::remove (size_t index) +template <class TYPE, class FUNCTOR, class LOCK> ACE_Timer_Node_T<TYPE, FUNCTOR, LOCK> * +ACE_Timer_Heap_T<TYPE, FUNCTOR, LOCK>::remove (size_t index) { - ACE_Timer_Node_T<TYPE, FUNCTOR> *removed_node = this->heap_[index]; + ACE_Timer_Node_T<TYPE, FUNCTOR, LOCK> *removed_node = this->heap_[index]; // Return this timer id to the freelist. this->push_freelist (removed_node->timer_id_); @@ -221,7 +221,7 @@ ACE_Timer_Heap_T<TYPE, FUNCTOR>::remove (size_t index) if (index < this->cur_size_) { - ACE_Timer_Node_T<TYPE, FUNCTOR> *moved_node = this->heap_[this->cur_size_]; + ACE_Timer_Node_T<TYPE, FUNCTOR, LOCK> *moved_node = this->heap_[this->cur_size_]; // Move the end node to the location being removed and update // the corresponding slot in the parallel <timer_ids> array. @@ -240,10 +240,10 @@ ACE_Timer_Heap_T<TYPE, FUNCTOR>::remove (size_t index) return removed_node; } -template <class TYPE, class FUNCTOR> void -ACE_Timer_Heap_T<TYPE, FUNCTOR>::reheap_down (ACE_Timer_Node_T<TYPE, FUNCTOR> *moved_node, - size_t index, - size_t child) +template <class TYPE, class FUNCTOR, class LOCK> void +ACE_Timer_Heap_T<TYPE, FUNCTOR, LOCK>::reheap_down (ACE_Timer_Node_T<TYPE, FUNCTOR, LOCK> *moved_node, + size_t index, + size_t child) { // Restore the heap property after a deletion. @@ -270,10 +270,10 @@ ACE_Timer_Heap_T<TYPE, FUNCTOR>::reheap_down (ACE_Timer_Node_T<TYPE, FUNCTOR> *m this->copy (index, moved_node); } -template <class TYPE, class FUNCTOR> void -ACE_Timer_Heap_T<TYPE, FUNCTOR>::reheap_up (ACE_Timer_Node_T<TYPE, FUNCTOR> *moved_node, - size_t index, - size_t parent) +template <class TYPE, class FUNCTOR, class LOCK> void +ACE_Timer_Heap_T<TYPE, FUNCTOR, LOCK>::reheap_up (ACE_Timer_Node_T<TYPE, FUNCTOR, LOCK> *moved_node, + size_t index, + size_t parent) { // Restore the heap property after an insertion. @@ -296,8 +296,8 @@ ACE_Timer_Heap_T<TYPE, FUNCTOR>::reheap_up (ACE_Timer_Node_T<TYPE, FUNCTOR> *mov this->copy (index, moved_node); } -template <class TYPE, class FUNCTOR> void -ACE_Timer_Heap_T<TYPE, FUNCTOR>::insert (ACE_Timer_Node_T<TYPE, FUNCTOR> *new_node) +template <class TYPE, class FUNCTOR, class LOCK> void +ACE_Timer_Heap_T<TYPE, FUNCTOR, LOCK>::insert (ACE_Timer_Node_T<TYPE, FUNCTOR, LOCK> *new_node) { if (this->cur_size_ + 1 >= max_size_) this->grow_heap (); @@ -309,16 +309,16 @@ ACE_Timer_Heap_T<TYPE, FUNCTOR>::insert (ACE_Timer_Node_T<TYPE, FUNCTOR> *new_no } -template <class TYPE, class FUNCTOR> void -ACE_Timer_Heap_T<TYPE, FUNCTOR>::grow_heap (void) +template <class TYPE, class FUNCTOR, class LOCK> void +ACE_Timer_Heap_T<TYPE, FUNCTOR, LOCK>::grow_heap (void) { // All the containers will double in size from max_size_ size_t new_size = max_size_ * 2; // First grow the heap itself. - ACE_Timer_Node_T<TYPE, FUNCTOR> **new_heap = 0; - ACE_NEW (new_heap, (ACE_Timer_Node_T<TYPE, FUNCTOR> *[new_size])); + ACE_Timer_Node_T<TYPE, FUNCTOR, LOCK> **new_heap = 0; + ACE_NEW (new_heap, (ACE_Timer_Node_T<TYPE, FUNCTOR, LOCK> *[new_size])); ACE_OS::memcpy (new_heap, this->heap_, max_size_ * sizeof *new_heap); delete [] this->heap_; @@ -347,7 +347,7 @@ ACE_Timer_Heap_T<TYPE, FUNCTOR>::grow_heap (void) // Create a new array with max_size elements to link in // to existing list. ACE_NEW (this->preallocated_nodes_, - (ACE_Timer_Node_T<TYPE, FUNCTOR>[this->max_size_])); + (ACE_Timer_Node_T<TYPE, FUNCTOR, LOCK>[this->max_size_])); // Add it to the set for later deletion this->preallocated_node_set_.insert (this->preallocated_nodes_); @@ -365,9 +365,9 @@ ACE_Timer_Heap_T<TYPE, FUNCTOR>::grow_heap (void) this->preallocated_nodes_freelist_ = &preallocated_nodes_[0]; else { - ACE_Timer_Node_T<TYPE, FUNCTOR> *previous = this->preallocated_nodes_freelist_; + ACE_Timer_Node_T<TYPE, FUNCTOR, LOCK> *previous = this->preallocated_nodes_freelist_; - for (ACE_Timer_Node_T<TYPE, FUNCTOR> *current = this->preallocated_nodes_freelist_->next_; + for (ACE_Timer_Node_T<TYPE, FUNCTOR, LOCK> *current = this->preallocated_nodes_freelist_->next_; current != 0; current = current->next_) previous = current; @@ -382,8 +382,8 @@ ACE_Timer_Heap_T<TYPE, FUNCTOR>::grow_heap (void) // Reschedule a periodic timer. This function must be called with the // mutex lock held. -template <class TYPE, class FUNCTOR> void -ACE_Timer_Heap_T<TYPE, FUNCTOR>::reschedule (ACE_Timer_Node_T<TYPE, FUNCTOR> *expired) +template <class TYPE, class FUNCTOR, class LOCK> void +ACE_Timer_Heap_T<TYPE, FUNCTOR, LOCK>::reschedule (ACE_Timer_Node_T<TYPE, FUNCTOR, LOCK> *expired) { ACE_TRACE ("ACE_Timer_Heap::reschedule"); @@ -392,15 +392,15 @@ ACE_Timer_Heap_T<TYPE, FUNCTOR>::reschedule (ACE_Timer_Node_T<TYPE, FUNCTOR> *ex } -template <class TYPE, class FUNCTOR> ACE_Timer_Node_T<TYPE, FUNCTOR> * -ACE_Timer_Heap_T<TYPE, FUNCTOR>::alloc_node (void) +template <class TYPE, class FUNCTOR, class LOCK> ACE_Timer_Node_T<TYPE, FUNCTOR, LOCK> * +ACE_Timer_Heap_T<TYPE, FUNCTOR, LOCK>::alloc_node (void) { ACE_Timer_Node *temp; // Only allocate a node if we are *not* using the preallocated heap. if (this->preallocated_nodes_ == 0) ACE_NEW_RETURN (temp, - (ACE_Timer_Node_T<TYPE, FUNCTOR>), + (ACE_Timer_Node_T<TYPE, FUNCTOR, LOCK>), 0); else { @@ -418,8 +418,8 @@ ACE_Timer_Heap_T<TYPE, FUNCTOR>::alloc_node (void) } -template <class TYPE, class FUNCTOR> void -ACE_Timer_Heap_T<TYPE, FUNCTOR>::free_node (ACE_Timer_Node_T<TYPE, FUNCTOR> *node) +template <class TYPE, class FUNCTOR, class LOCK> void +ACE_Timer_Heap_T<TYPE, FUNCTOR, LOCK>::free_node (ACE_Timer_Node_T<TYPE, FUNCTOR, LOCK> *node) { // Only free up a node if we are *not* using the preallocated heap. if (this->preallocated_nodes_ == 0) @@ -435,15 +435,15 @@ ACE_Timer_Heap_T<TYPE, FUNCTOR>::free_node (ACE_Timer_Node_T<TYPE, FUNCTOR> *nod // > 0, the handler will be reinvoked periodically. -template <class TYPE, class FUNCTOR> long -ACE_Timer_Heap_T<TYPE, FUNCTOR>::schedule (const TYPE &type, - const void *act, - const ACE_Time_Value &future_time, - const ACE_Time_Value &interval) +template <class TYPE, class FUNCTOR, class LOCK> long +ACE_Timer_Heap_T<TYPE, FUNCTOR, LOCK>::schedule (const TYPE &type, + const void *act, + const ACE_Time_Value &future_time, + const ACE_Time_Value &interval) { ACE_TRACE ("ACE_Timer_Heap::schedule"); - ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon, this->lock_, -1)); + ACE_MT (ACE_GUARD_RETURN (LOCK, ace_mon, this->lock_, -1)); if (this->cur_size_ < this->max_size_) { @@ -451,17 +451,17 @@ ACE_Timer_Heap_T<TYPE, FUNCTOR>::schedule (const TYPE &type, int timer_id = this->timer_id (); // Obtain the memory to the new node. - ACE_Timer_Node_T<TYPE, FUNCTOR> *temp = this->alloc_node (); + ACE_Timer_Node_T<TYPE, FUNCTOR, LOCK> *temp = this->alloc_node (); if (temp) { // Use operator placement new. - new (temp) ACE_Timer_Node_T<TYPE, FUNCTOR> (type, - act, - future_time, - interval, - 0, - timer_id); + new (temp) ACE_Timer_Node_T<TYPE, FUNCTOR, LOCK> (type, + act, + future_time, + interval, + 0, + timer_id); this->insert (temp); return timer_id; } @@ -474,13 +474,13 @@ ACE_Timer_Heap_T<TYPE, FUNCTOR>::schedule (const TYPE &type, // Locate and remove the single timer with a value of <timer_id> from // the timer queue. -template <class TYPE, class FUNCTOR> int -ACE_Timer_Heap_T<TYPE, FUNCTOR>::cancel (long timer_id, - const void **act, - int dont_call) +template <class TYPE, class FUNCTOR, class LOCK> int +ACE_Timer_Heap_T<TYPE, FUNCTOR, LOCK>::cancel (long timer_id, + const void **act, + int dont_call) { ACE_TRACE ("ACE_Timer_Heap::cancel"); - ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon, this->lock_, -1)); + ACE_MT (ACE_GUARD_RETURN (LOCK, ace_mon, this->lock_, -1)); // Locate the ACE_Timer_Node that corresponds to the timer_id. @@ -493,11 +493,11 @@ ACE_Timer_Heap_T<TYPE, FUNCTOR>::cancel (long timer_id, } else { - ACE_Timer_Node_T<TYPE, FUNCTOR> *temp = this->remove (timer_node_slot); + ACE_Timer_Node_T<TYPE, FUNCTOR, LOCK> *temp = this->remove (timer_node_slot); if (dont_call == 0) // Call the close hook. - this->upcall_functor_.operator () (*this, temp->type_); + this->upcall_functor_.cancellation (*this, temp->type_); if (act != 0) *act = temp->act_; @@ -509,12 +509,12 @@ ACE_Timer_Heap_T<TYPE, FUNCTOR>::cancel (long timer_id, // Locate and remove all values of <type> from the timer queue. -template <class TYPE, class FUNCTOR> int -ACE_Timer_Heap_T<TYPE, FUNCTOR>::cancel (const TYPE &type, - int dont_call) +template <class TYPE, class FUNCTOR, class LOCK> int +ACE_Timer_Heap_T<TYPE, FUNCTOR, LOCK>::cancel (const TYPE &type, + int dont_call) { ACE_TRACE ("ACE_Timer_Heap::cancel"); - ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon, this->lock_, -1)); + ACE_MT (ACE_GUARD_RETURN (LOCK, ace_mon, this->lock_, -1)); int number_of_cancellations = 0; @@ -524,15 +524,15 @@ ACE_Timer_Heap_T<TYPE, FUNCTOR>::cancel (const TYPE &type, { if (this->heap_[i]->type_ == type) { - ACE_Timer_Node_T<TYPE, FUNCTOR> *temp = this->remove (i); + ACE_Timer_Node_T<TYPE, FUNCTOR, LOCK> *temp = this->remove (i); number_of_cancellations++; if (dont_call == 0 && number_of_cancellations == 1) // Call the close hook. - this->upcall_functor_.operator () (*this, temp->type_); - + this->upcall_functor_.cancellation (*this, temp->type_); + this->free_node (temp); } else |