diff options
-rw-r--r-- | ace/Timer_Hash_T.cpp | 27 | ||||
-rw-r--r-- | ace/Timer_Hash_T.h | 3 |
2 files changed, 24 insertions, 6 deletions
diff --git a/ace/Timer_Hash_T.cpp b/ace/Timer_Hash_T.cpp index 89c77d408bb..df955999a52 100644 --- a/ace/Timer_Hash_T.cpp +++ b/ace/Timer_Hash_T.cpp @@ -281,6 +281,7 @@ ACE_Timer_Hash_T<TYPE, FUNCTOR, ACE_LOCK, BUCKET>::dump (void) const for (size_t i = 0; i < this->table_size_; i++) if (!this->table_[i]->is_empty ()) ACE_DEBUG ((LM_DEBUG, "\nBucket %d contains nodes", i)); + ACE_DEBUG ((LM_DEBUG, "\n")); ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP)); } @@ -358,6 +359,9 @@ ACE_Timer_Hash_T<TYPE, FUNCTOR, ACE_LOCK, BUCKET>::cancel (long timer_id, int ret = this->table_[h->pos_]->cancel (h->orig_id_, act, dont_call); + if (h->pos_ == this->earliest_position_) + this->find_new_earliest (); + if (act != 0) *act = h->act_; @@ -379,7 +383,7 @@ ACE_Timer_Hash_T<TYPE, FUNCTOR, ACE_LOCK, BUCKET>::cancel (const TYPE &type, ACE_MT (ACE_GUARD_RETURN (ACE_LOCK, ace_mon, this->mutex_, -1)); - size_t i; // loop variable + size_t i; // loop variable Hash_Token **timer_ids = new Hash_Token *[this->size_]; size_t pos = 0; @@ -408,6 +412,8 @@ ACE_Timer_Hash_T<TYPE, FUNCTOR, ACE_LOCK, BUCKET>::cancel (const TYPE &type, if (dont_call == 0) this->upcall_functor ().cancellation (*this, type); + this->find_new_earliest (); + return pos; } @@ -422,17 +428,26 @@ ACE_Timer_Hash_T<TYPE, FUNCTOR, ACE_LOCK, BUCKET>::remove_first (void) ACE_Timer_Node_T<TYPE> *temp = this->table_[this->earliest_position_]->remove_first (); - for (size_t i = 0; i < this->table_size_; i++) - if (!this->table_[i]->is_empty ()) - if (this->earliest_time () == ACE_Time_Value::zero - || this->table_[i]->earliest_time () < this->earliest_time ()) - this->earliest_position_ = i; + this->find_new_earliest (); --this->size_; return temp; } +// Finds a new earliest position + +template <class TYPE, class FUNCTOR, class ACE_LOCK, class BUCKET> void +ACE_Timer_Hash_T<TYPE, FUNCTOR, ACE_LOCK, BUCKET>::find_new_earliest (void) +{ + for (size_t i = 0; i < this->table_size_; i++) + if (!this->table_[i]->is_empty ()) + if (this->table_[this->earliest_position_]->is_empty() + || this->earliest_time () == ACE_Time_Value::zero + || this->table_[i]->earliest_time () <= this->earliest_time ()) + this->earliest_position_ = i; +} + // Returns the earliest node without removing it diff --git a/ace/Timer_Hash_T.h b/ace/Timer_Hash_T.h index ab93fe99ddd..73ef74b9809 100644 --- a/ace/Timer_Hash_T.h +++ b/ace/Timer_Hash_T.h @@ -212,6 +212,9 @@ private: virtual void reschedule (ACE_Timer_Node_T<TYPE> *); // Reschedule an "interval" <ACE_Timer_Node>. + void find_new_earliest (void); + // Finds the earliest node + size_t size_; // Keeps track of the size of the queue |