#include <Timer_Hash_T.h>
Inheritance diagram for ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >:
Public Types | |
typedef ACE_Timer_Hash_Iterator_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET > | HASH_ITERATOR |
Type of iterator. | |
typedef ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK > | INHERITED |
Type inherited from. | |
Public Member Functions | |
ACE_Timer_Hash_T (size_t table_size, FUNCTOR *upcall_functor=0, ACE_Free_List< ACE_Timer_Node_T< TYPE > > *freelist=0) | |
ACE_Timer_Hash_T (FUNCTOR *upcall_functor=0, ACE_Free_List< ACE_Timer_Node_T< TYPE > > *freelist=0) | |
virtual | ~ACE_Timer_Hash_T (void) |
Destructor. | |
virtual bool | is_empty (void) const |
True if queue is empty, else false. | |
virtual const ACE_Time_Value & | earliest_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 int | expire (void) |
virtual int | expire (const ACE_Time_Value ¤t_time) |
virtual ACE_Timer_Queue_Iterator_T< TYPE, FUNCTOR, ACE_LOCK > & | iter (void) |
Returns a pointer to this ACE_Timer_Queue's iterator. | |
virtual ACE_Timer_Node_T< TYPE > * | remove_first (void) |
Removes the earliest node from the queue and returns it. | |
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 void | free_node (ACE_Timer_Node_T< TYPE > *) |
Factory method that frees a previously allocated node. | |
Private Member Functions | |
virtual long | schedule_i (const TYPE &type, const void *act, const ACE_Time_Value &future_time, const ACE_Time_Value &interval) |
virtual int | dispatch_info_i (const ACE_Time_Value ¤t_time, ACE_Timer_Node_Dispatch_Info_T< TYPE > &info) |
Non-locking version of dispatch_info (). | |
virtual void | reschedule (ACE_Timer_Node_T< TYPE > *) |
Reschedule an "interval" ACE_Timer_Node. | |
void | find_new_earliest (void) |
Finds the earliest node. | |
ACE_Timer_Hash_T (const ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET > &) | |
void | operator= (const ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET > &) |
Private Attributes | |
size_t | size_ |
Keeps track of the size of the queue. | |
BUCKET ** | table_ |
Table of BUCKETS. | |
size_t | table_size_ |
Keeps track of the size of table_. | |
ACE_Timer_Hash_Upcall< TYPE, FUNCTOR, ACE_LOCK > | table_functor_ |
Functor used for the table's timer queues. | |
size_t | earliest_position_ |
Index to the position with the earliest entry. | |
HASH_ITERATOR * | iterator_ |
Iterator used to expire timers. | |
ACE_Locked_Free_List< Hash_Token< TYPE >, ACE_Null_Mutex > | token_list_ |
Friends | |
class | ACE_Timer_Hash_Iterator_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET > |
Iterator is a friend. |
This implementation uses a hash table of BUCKETs. The hash is based on the time_value of the event. Unlike other Timer Queues, ACE_Timer_Hash does not expire events in order.
Definition at line 162 of file Timer_Hash_T.h.
typedef ACE_Timer_Hash_Iterator_T<TYPE, FUNCTOR, ACE_LOCK, BUCKET> ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::HASH_ITERATOR |
typedef ACE_Timer_Queue_T<TYPE, FUNCTOR, ACE_LOCK> ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::INHERITED |
ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::ACE_Timer_Hash_T | ( | size_t | table_size, | |
FUNCTOR * | upcall_functor = 0 , |
|||
ACE_Free_List< ACE_Timer_Node_T< TYPE > > * | freelist = 0 | |||
) |
Default constructor. table_size determines the size of the hash table. upcall_functor is the instance of the FUNCTOR to be used by the buckets. If upcall_functor is 0, a default FUNCTOR will be created.
Definition at line 271 of file Timer_Hash_T.cpp.
References ACE_NEW, ACE_TRACE, ACE_OS::gettimeofday(), ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >::gettimeofday(), ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::iterator_, and ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::table_.
00275 : ACE_Timer_Queue_T<TYPE, FUNCTOR, ACE_LOCK> (upcall_functor, freelist), 00276 size_ (0), 00277 table_size_ (table_size), 00278 table_functor_ (this), 00279 earliest_position_ (0) 00280 #if defined (ACE_WIN64) 00281 , pointer_base_ (0) 00282 #endif /* ACE_WIN64 */ 00283 , token_list_ () 00284 { 00285 ACE_TRACE ("ACE_Timer_Hash_T::ACE_Timer_Hash_T"); 00286 00287 ACE_NEW (table_, 00288 BUCKET *[table_size]); 00289 00290 this->gettimeofday (ACE_OS::gettimeofday); 00291 00292 for (size_t i = 0; 00293 i < table_size; 00294 ++i) 00295 { 00296 ACE_NEW (this->table_[i], 00297 BUCKET (&this->table_functor_, 00298 this->free_list_)); 00299 this->table_[i]->gettimeofday (ACE_OS::gettimeofday); 00300 } 00301 00302 ACE_NEW (iterator_, 00303 HASH_ITERATOR (*this)); 00304 }
ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::ACE_Timer_Hash_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 Hash will create a default FUNCTOR. freelist 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 308 of file Timer_Hash_T.cpp.
References ACE_DEFAULT_TIMER_HASH_TABLE_SIZE, ACE_NEW, ACE_TRACE, ACE_OS::gettimeofday(), ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >::gettimeofday(), ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::iterator_, ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::table_, and ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::table_size_.
00311 : ACE_Timer_Queue_T<TYPE, FUNCTOR, ACE_LOCK> (upcall_functor, freelist), 00312 size_ (0), 00313 table_size_ (ACE_DEFAULT_TIMER_HASH_TABLE_SIZE), 00314 table_functor_ (this), 00315 earliest_position_ (0) 00316 #if defined (ACE_WIN64) 00317 , pointer_base_ (0) 00318 #endif /* ACE_WIN64 */ 00319 , token_list_ () 00320 { 00321 ACE_TRACE ("ACE_Timer_Hash_T::ACE_Timer_Hash_T"); 00322 00323 ACE_NEW (table_, 00324 BUCKET *[ACE_DEFAULT_TIMER_HASH_TABLE_SIZE]); 00325 00326 00327 this->gettimeofday (ACE_OS::gettimeofday); 00328 00329 for (size_t i = 0; 00330 i < this->table_size_; 00331 ++i) 00332 { 00333 ACE_NEW (this->table_[i], 00334 BUCKET (&this->table_functor_, 00335 this->free_list_)); 00336 this->table_[i]->gettimeofday (ACE_OS::gettimeofday); 00337 } 00338 00339 ACE_NEW (iterator_, 00340 HASH_ITERATOR (*this)); 00341 }
ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::~ACE_Timer_Hash_T | ( | void | ) | [virtual] |
Destructor.
Definition at line 346 of file Timer_Hash_T.cpp.
References ACE_GUARD, ACE_TRACE, ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::iterator_, and ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::table_size_.
00347 { 00348 ACE_TRACE ("ACE_Timer_Hash_T::~ACE_Timer_Hash_T"); 00349 ACE_MT (ACE_GUARD (ACE_LOCK, ace_mon, this->mutex_)); 00350 00351 delete iterator_; 00352 00353 for (size_t i = 0; 00354 i < this->table_size_; 00355 ++i) 00356 delete this->table_[i]; 00357 00358 delete [] this->table_; 00359 }
ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::ACE_Timer_Hash_T | ( | const ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET > & | ) | [private] |
int ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::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> is 0 then the <functor> will be invoked. Returns 1 if cancellation succeeded and 0 if the timer_id wasn't found. If any valid timer is not cancelled before destruction of this instance of ACE_Timer_Hash_T then user will get a memory leak.
Implements ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >.
Definition at line 551 of file Timer_Hash_T.cpp.
References ACE_GUARD_RETURN, ACE_TRACE, ACE_Locked_Free_List< T, ACE_LOCK >::add(), ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::find_new_earliest(), ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::size_, ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::table_, ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::token_list_, and ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >::upcall_functor().
00554 { 00555 ACE_TRACE ("ACE_Timer_Hash_T::cancel"); 00556 00557 // Make sure we are getting a valid <timer_id>, not an error 00558 // returned by <schedule>. 00559 if (timer_id == -1) 00560 return 0; 00561 00562 #if defined (ACE_WIN64) 00563 unsigned long const timer_offset = 00564 static_cast<unsigned long> (timer_id); 00565 00566 ACE_MT (ACE_GUARD_RETURN (ACE_LOCK, ace_mon, this->mutex_, -1)); 00567 00568 Hash_Token<TYPE> * const h = 00569 reinterpret_cast<Hash_Token<TYPE> *> (this->pointer_base_ + timer_offset); 00570 #else 00571 Hash_Token<TYPE> * const h = 00572 reinterpret_cast<Hash_Token<TYPE> *> (timer_id); 00573 00574 // Grab the lock before accessing the table. We don't need to do so 00575 // before this point since no members are accessed until now. 00576 ACE_MT (ACE_GUARD_RETURN (ACE_LOCK, ace_mon, this->mutex_, -1)); 00577 #endif /* ACE_WIN64 */ 00578 00579 int const result = this->table_[h->pos_]->cancel (h->orig_id_, 00580 0, 00581 dont_call); 00582 00583 if (result == 1) 00584 { 00585 // Call the close hooks. 00586 int cookie = 0; 00587 00588 // cancel_type() called once per <type>. 00589 this->upcall_functor ().cancel_type (*this, 00590 h->type_, 00591 dont_call, 00592 cookie); 00593 00594 // cancel_timer() called once per <timer>. 00595 this->upcall_functor ().cancel_timer (*this, 00596 h->type_, 00597 dont_call, 00598 cookie); 00599 00600 if (h->pos_ == this->earliest_position_) 00601 this->find_new_earliest (); 00602 00603 if (act != 0) 00604 *act = h->act_; 00605 00606 // We could destruct Hash_Token explicitly but we better 00607 // schedule it for destruction. In this case next 00608 // token_list_.remove () will use it. 00609 this->token_list_.add (h); 00610 00611 --this->size_; 00612 } 00613 00614 return result; 00615 }
int ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::cancel | ( | const TYPE & | type, | |
int | dont_call_handle_close = 1 | |||
) | [virtual] |
Cancel all timer associated with type. If <dont_call> is 0 then the <functor> will be invoked. Returns number of timers cancelled. If any valid timer is not cancelled before destruction of this instance of ACE_Timer_Hash_T then user will get a memory leak.
Implements ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >.
Definition at line 621 of file Timer_Hash_T.cpp.
References ACE_ASSERT, ACE_GUARD_RETURN, ACE_NEW_RETURN, ACE_TRACE, ACE_Locked_Free_List< T, ACE_LOCK >::add(), ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::find_new_earliest(), ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::iter(), Hash_Token< TYPE >::orig_id_, Hash_Token< TYPE >::pos_, ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::size_, ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::table_size_, ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::token_list_, and ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >::upcall_functor().
00623 { 00624 ACE_TRACE ("ACE_Timer_Hash_T::cancel"); 00625 00626 size_t i; // loop variable. 00627 00628 Hash_Token<TYPE> **timer_ids = 0; 00629 size_t pos = 0; 00630 00631 ACE_MT (ACE_GUARD_RETURN (ACE_LOCK, ace_mon, this->mutex_, -1)); 00632 00633 ACE_NEW_RETURN (timer_ids, 00634 Hash_Token<TYPE> *[this->size_], 00635 -1); 00636 00637 for (i = 0; 00638 i < this->table_size_; 00639 ++i) 00640 { 00641 ACE_Timer_Queue_Iterator_T<TYPE, 00642 ACE_Timer_Hash_Upcall<TYPE, FUNCTOR, ACE_LOCK>, 00643 ACE_Null_Mutex> &iter = 00644 this->table_[i]->iter (); 00645 00646 for (iter.first (); 00647 !iter.isdone (); 00648 iter.next ()) 00649 if (iter.item ()->get_type () == type) 00650 timer_ids[pos++] = 00651 reinterpret_cast<Hash_Token<TYPE> *> ( 00652 const_cast<void *> (iter.item ()->get_act ())); 00653 } 00654 00655 if (pos > this->size_) 00656 return -1; 00657 00658 for (i = 0; i < pos; ++i) 00659 { 00660 int const result = 00661 this->table_[timer_ids[i]->pos_]->cancel (timer_ids[i]->orig_id_, 00662 0, 00663 dont_call); 00664 ACE_ASSERT (result == 1); 00665 ACE_UNUSED_ARG (result); 00666 00667 // We could destruct Hash_Token explicitly but we better 00668 // schedule it for destruction. 00669 this->token_list_.add (timer_ids[i]); 00670 00671 --this->size_; 00672 } 00673 00674 delete [] timer_ids; 00675 00676 this->find_new_earliest (); 00677 00678 // Call the close hooks. 00679 int cookie = 0; 00680 00681 // cancel_type() called once per <type>. 00682 this->upcall_functor ().cancel_type (*this, 00683 type, 00684 dont_call, 00685 cookie); 00686 00687 for (i = 0; 00688 i < pos; 00689 ++i) 00690 { 00691 // cancel_timer() called once per <timer>. 00692 this->upcall_functor ().cancel_timer (*this, 00693 type, 00694 dont_call, 00695 cookie); 00696 } 00697 00698 return static_cast<int> (pos); 00699 }
int ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::dispatch_info_i | ( | const ACE_Time_Value & | current_time, | |
ACE_Timer_Node_Dispatch_Info_T< TYPE > & | info | |||
) | [private, virtual] |
Non-locking version of dispatch_info ().
Reimplemented from ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >.
Definition at line 756 of file Timer_Hash_T.cpp.
References Hash_Token< TYPE >::act_, ACE_Timer_Node_Dispatch_Info_T< TYPE >::act_, and ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >::dispatch_info_i().
00758 { 00759 int const result = 00760 ACE_Timer_Queue_T<TYPE,FUNCTOR,ACE_LOCK>::dispatch_info_i (cur_time, 00761 info); 00762 00763 if (result == 1) 00764 { 00765 Hash_Token<TYPE> *h = 00766 reinterpret_cast<Hash_Token<TYPE> *> (const_cast<void *> (info.act_)); 00767 00768 info.act_ = h->act_; 00769 } 00770 00771 return result; 00772 }
void ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::dump | ( | void | ) | const [virtual] |
Dump the state of an object.
Reimplemented from ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >.
Definition at line 381 of file Timer_Hash_T.cpp.
References ACE_BEGIN_DUMP, ACE_DEBUG, ACE_END_DUMP, ACE_TEXT, ACE_TRACE, LM_DEBUG, and ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::table_size_.
00382 { 00383 #if defined (ACE_HAS_DUMP) 00384 ACE_TRACE ("ACE_Timer_Hash_T::dump"); 00385 ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this)); 00386 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\ntable_size_ = %d"), this->table_size_)); 00387 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\nearliest_position_ = %d"), this->earliest_position_)); 00388 00389 for (size_t i = 0; i < this->table_size_; ++i) 00390 if (!this->table_[i]->is_empty ()) 00391 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\nBucket %d contains nodes"), i)); 00392 00393 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\n"))); 00394 ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP)); 00395 #endif /* ACE_HAS_DUMP */ 00396 }
const ACE_Time_Value & ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::earliest_time | ( | void | ) | const [virtual] |
Returns the time of the earlier node in the <ACE_Timer_Hash>. Must be called on a non-empty queue.
Implements ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >.
Definition at line 374 of file Timer_Hash_T.cpp.
References ACE_TRACE, ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::earliest_position_, and ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::table_.
Referenced by ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::find_new_earliest().
00375 { 00376 ACE_TRACE ("ACE_Timer_Hash_T::earliest_time"); 00377 return this->table_[this->earliest_position_]->earliest_time (); 00378 }
int ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::expire | ( | const ACE_Time_Value & | current_time | ) | [virtual] |
Run the <functor> for all timers whose values are <= current_time. This does not account for <timer_skew>. Returns the number of timers canceled.
Reimplemented from ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >.
Definition at line 785 of file Timer_Hash_T.cpp.
References ACE_ASSERT, ACE_DEBUG, ACE_GUARD_RETURN, ACE_TRACE, Hash_Token< TYPE >::act_, ACE_Timer_Node_Dispatch_Info_T< TYPE >::act_, ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::find_new_earliest(), ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::free_node(), ACE_Timer_Node_T< TYPE >::get_act(), ACE_Timer_Node_T< TYPE >::get_dispatch_info(), ACE_Timer_Node_T< TYPE >::get_interval(), ACE_Timer_Node_T< TYPE >::get_timer_value(), LM_DEBUG, ACE_Time_Value::msec(), Hash_Token< TYPE >::orig_id_, Hash_Token< TYPE >::pos_, ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >::postinvoke(), ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >::preinvoke(), ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::reschedule(), ACE_Timer_Node_T< TYPE >::set_timer_value(), ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::size_, ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::table_, ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::table_size_, ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >::upcall(), and ACE_Time_Value::zero.
00786 { 00787 ACE_TRACE ("ACE_Timer_Hash_T::expire"); 00788 00789 int number_of_timers_expired = 0; 00790 00791 ACE_Timer_Node_T<TYPE> *expired = 0; 00792 00793 ACE_MT (ACE_GUARD_RETURN (ACE_LOCK, ace_mon, this->mutex_, -1)); 00794 00795 // Go through the table and expire anything that can be expired 00796 00797 for (size_t i = 0; 00798 i < this->table_size_; 00799 ++i) 00800 { 00801 while (!this->table_[i]->is_empty () 00802 && this->table_[i]->earliest_time () <= cur_time) 00803 { 00804 expired = this->table_[i]->remove_first (); 00805 const void *act = expired->get_act (); 00806 bool reclaim = true; 00807 00808 Hash_Token<TYPE> *h = 00809 reinterpret_cast<Hash_Token<TYPE> *> (const_cast<void *> (act)); 00810 00811 ACE_ASSERT (h->pos_ == i); 00812 00813 #if 0 00814 ACE_DEBUG ((LM_DEBUG, "Hash::expire() expiring %d in slot %d where it's id is %d and token is %x\n", 00815 expired->get_timer_value ().msec (), 00816 h->pos_, 00817 h->orig_id_, 00818 h)); 00819 #endif 00820 00821 // Check if this is an interval timer. 00822 if (expired->get_interval () > ACE_Time_Value::zero) 00823 { 00824 // Make sure that we skip past values that have already 00825 // "expired". 00826 do 00827 expired->set_timer_value (expired->get_timer_value () 00828 + expired->get_interval ()); 00829 while (expired->get_timer_value () <= cur_time); 00830 00831 // Since this is an interval timer, we need to 00832 // reschedule it. 00833 this->reschedule (expired); 00834 reclaim = false; 00835 } 00836 else 00837 { 00838 this->free_node (expired); 00839 } 00840 00841 ACE_Timer_Node_Dispatch_Info_T<TYPE> info; 00842 00843 // Get the dispatch info 00844 expired->get_dispatch_info (info); 00845 00846 info.act_ = h->act_; 00847 00848 const void *upcall_act = 0; 00849 00850 this->preinvoke (info, cur_time, upcall_act); 00851 00852 this->upcall (info, cur_time); 00853 00854 this->postinvoke (info, cur_time, upcall_act); 00855 00856 if (reclaim) 00857 { 00858 --this->size_; 00859 } 00860 00861 ++number_of_timers_expired; 00862 } 00863 } 00864 00865 if (number_of_timers_expired > 0) 00866 this->find_new_earliest (); 00867 00868 return number_of_timers_expired; 00869 }
int ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::expire | ( | void | ) | [virtual] |
Run the <functor> for all timers whose values are <= <ACE_OS::gettimeofday>. Also accounts for <timer_skew>. Returns the number of timers canceled.
Reimplemented from ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >.
Definition at line 777 of file Timer_Hash_T.cpp.
References ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >::expire().
00778 { 00779 return ACE_Timer_Queue_T<TYPE,FUNCTOR,ACE_LOCK>::expire(); 00780 }
void ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::find_new_earliest | ( | void | ) | [private] |
Finds the earliest node.
Definition at line 722 of file Timer_Hash_T.cpp.
References ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::earliest_time(), ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::table_, ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::table_size_, and ACE_Time_Value::zero.
Referenced by ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::cancel(), ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::expire(), and ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::remove_first().
00723 { 00724 for (size_t i = 0; i < this->table_size_; ++i) 00725 if (!this->table_[i]->is_empty ()) 00726 if (this->table_[this->earliest_position_]->is_empty () 00727 || this->earliest_time () == ACE_Time_Value::zero 00728 || this->table_[i]->earliest_time () <= this->earliest_time ()) 00729 this->earliest_position_ = i; 00730 }
void ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::free_node | ( | ACE_Timer_Node_T< TYPE > * | ) | [protected, virtual] |
Factory method that frees a previously allocated node.
Reimplemented from ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >.
Definition at line 746 of file Timer_Hash_T.cpp.
References ACE_Locked_Free_List< T, ACE_LOCK >::add(), ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >::free_node(), ACE_Timer_Node_T< TYPE >::get_act(), and ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::token_list_.
Referenced by ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::expire().
00747 { 00748 ACE_Timer_Queue_T<TYPE,FUNCTOR,ACE_LOCK>::free_node (node); 00749 00750 Hash_Token<TYPE> *h = 00751 reinterpret_cast<Hash_Token<TYPE> *> (const_cast<void *> (node->get_act ())); 00752 this->token_list_.add (h); 00753 }
ACE_Timer_Node_T< TYPE > * ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::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 735 of file Timer_Hash_T.cpp.
References ACE_TRACE, ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::earliest_position_, and ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::table_.
00736 { 00737 ACE_TRACE ("ACE_Timer_Hash_T::get_first"); 00738 00739 if (this->is_empty ()) 00740 return 0; 00741 00742 return this->table_[this->earliest_position_]->get_first (); 00743 }
bool ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::is_empty | ( | void | ) | const [virtual] |
True if queue is empty, else false.
Implements ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >.
Definition at line 364 of file Timer_Hash_T.cpp.
References ACE_TRACE, ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::earliest_position_, and ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::table_.
00365 { 00366 ACE_TRACE ("ACE_Timer_Hash_T::is_empty"); 00367 return this->table_[this->earliest_position_]->is_empty (); 00368 }
ACE_Timer_Queue_Iterator_T< TYPE, FUNCTOR, ACE_LOCK > & ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::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 262 of file Timer_Hash_T.cpp.
References ACE_Timer_Hash_Iterator_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::first(), and ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::iterator_.
Referenced by ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::cancel().
void ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::operator= | ( | const ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET > & | ) | [private] |
ACE_Timer_Node_T< TYPE > * ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::remove_first | ( | void | ) | [virtual] |
Removes the earliest node from the queue and returns it.
Implements ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >.
Definition at line 704 of file Timer_Hash_T.cpp.
References ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::earliest_position_, ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::find_new_earliest(), ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::size_, and ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::table_.
00705 { 00706 if (this->is_empty ()) 00707 return 0; 00708 00709 ACE_Timer_Node_T<TYPE> *temp = 00710 this->table_[this->earliest_position_]->remove_first (); 00711 00712 this->find_new_earliest (); 00713 00714 --this->size_; 00715 00716 return temp; 00717 }
void ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::reschedule | ( | ACE_Timer_Node_T< TYPE > * | ) | [private, virtual] |
Reschedule an "interval" ACE_Timer_Node.
Implements ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >.
Definition at line 403 of file Timer_Hash_T.cpp.
References ACE_ASSERT, ACE_DEBUG, ACE_TRACE, ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::earliest_position_, ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >::free_node(), ACE_Timer_Node_T< TYPE >::get_act(), ACE_Timer_Node_T< TYPE >::get_interval(), ACE_Timer_Node_T< TYPE >::get_timer_value(), ACE_Timer_Node_T< TYPE >::get_type(), LM_DEBUG, ACE_Time_Value::msec(), Hash_Token< TYPE >::orig_id_, Hash_Token< TYPE >::pos_, ACE_Time_Value::sec(), ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::table_, and ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::table_size_.
Referenced by ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::expire().
00405 { 00406 ACE_TRACE ("ACE_Timer_Hash_T::reschedule"); 00407 00408 Hash_Token<TYPE> *h = 00409 reinterpret_cast<Hash_Token<TYPE> *> ( 00410 const_cast<void *> (expired->get_act ())); 00411 00412 // Don't use ACE_Utils::truncate_cast<> here. A straight 00413 // static_cast<> will provide more unique results when the number 00414 // of seconds is greater than std::numeric_limits<size_t>::max(). 00415 size_t const secs_hash_input = 00416 static_cast<size_t> (expired->get_timer_value ().sec ()); 00417 h->pos_ = secs_hash_input % this->table_size_; 00418 00419 h->orig_id_ = 00420 this->table_[h->pos_]->schedule (expired->get_type (), 00421 h, 00422 expired->get_timer_value (), 00423 expired->get_interval ()); 00424 ACE_ASSERT (h->orig_id_ != -1); 00425 00426 #if 0 00427 ACE_DEBUG ((LM_DEBUG, "Hash::reschedule() resets %d in slot %d where it's id is %d and token is %x\n", 00428 expired->get_timer_value ().msec (), 00429 h->pos_, 00430 h->orig_id_, 00431 h)); 00432 #endif 00433 00434 // Since schedule() above will allocate a new node 00435 // then here schedule <expired> for deletion. Don't call 00436 // this->free_node() because that will invalidate <h> 00437 // and that's what user have as timer_id. 00438 ACE_Timer_Queue_T<TYPE,FUNCTOR,ACE_LOCK>::free_node (expired); 00439 00440 if (this->table_[this->earliest_position_]->is_empty () 00441 || this->table_[h->pos_]->earliest_time () 00442 < this->table_[this->earliest_position_]->earliest_time ()) 00443 this->earliest_position_ = h->pos_; 00444 }
int ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::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 514 of file Timer_Hash_T.cpp.
References ACE_GUARD_RETURN, ACE_TRACE, and ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::table_.
00517 { 00518 ACE_TRACE ("ACE_Timer_Hash_T::reset_interval"); 00519 00520 // Make sure we are getting a valid <timer_id>, not an error 00521 // returned by <schedule>. 00522 if (timer_id == -1) 00523 return -1; 00524 00525 #if defined (ACE_WIN64) 00526 unsigned long const timer_offset = 00527 static_cast<unsigned long> (timer_id); 00528 00529 ACE_MT (ACE_GUARD_RETURN (ACE_LOCK, ace_mon, this->mutex_, -1)); 00530 00531 Hash_Token<TYPE> * const h = 00532 reinterpret_cast<Hash_Token<TYPE> *> (this->pointer_base_ + timer_offset); 00533 #else 00534 Hash_Token<TYPE> * const h = 00535 reinterpret_cast<Hash_Token<TYPE> *> (timer_id); 00536 00537 // Grab the lock before accessing the table. We don't need to do so 00538 // before this point since no members are accessed until now. 00539 ACE_MT (ACE_GUARD_RETURN (ACE_LOCK, ace_mon, this->mutex_, -1)); 00540 #endif /* ACE_WIN64 */ 00541 00542 return this->table_[h->pos_]->reset_interval (h->orig_id_, 00543 interval); 00544 }
long ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::schedule_i | ( | const TYPE & | type, | |
const void * | act, | |||
const ACE_Time_Value & | future_time, | |||
const ACE_Time_Value & | interval | |||
) | [private, virtual] |
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 is a pointer to a token which stores information about the event. This <timer_id> can be used to cancel the timer before it expires. Returns -1 on failure.
Implements ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >.
Definition at line 451 of file Timer_Hash_T.cpp.
References ACE_ASSERT, ACE_DEBUG, ACE_TRACE, ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::earliest_position_, LM_DEBUG, ACE_Time_Value::msec(), Hash_Token< TYPE >::orig_id_, ACE_Locked_Free_List< T, ACE_LOCK >::remove(), ACE_Time_Value::sec(), Hash_Token< TYPE >::set(), ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::table_, ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::table_size_, and ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::token_list_.
00456 { 00457 ACE_TRACE ("ACE_Timer_Hash_T::schedule_i"); 00458 00459 // Don't use ACE_Utils::truncate_cast<> here. A straight 00460 // static_cast<> will provide more unique results when the number 00461 // of seconds is greater than std::numeric_limits<size_t>::max(). 00462 size_t const secs_hash_input = static_cast<size_t> (future_time.sec ()); 00463 size_t const position = secs_hash_input % this->table_size_; 00464 00465 // Don't create Hash_Token directly. Instead we get one from Free_List 00466 // and then set it properly. 00467 Hash_Token<TYPE> *h = this->token_list_.remove (); 00468 h->set (act, position, 0, type); 00469 00470 h->orig_id_ = 00471 this->table_[position]->schedule (type, 00472 h, 00473 future_time, 00474 interval); 00475 ACE_ASSERT (h->orig_id_ != -1); 00476 00477 #if 0 00478 ACE_DEBUG ((LM_DEBUG, "Hash::schedule() placing %d in slot %d where it's id is %d and token is %x\n", 00479 future_time.msec (), 00480 position, 00481 h->orig_id_, 00482 h)); 00483 #endif 00484 00485 if (this->table_[this->earliest_position_]->is_empty () 00486 || this->table_[position]->earliest_time () 00487 < this->table_[this->earliest_position_]->earliest_time ()) 00488 this->earliest_position_ = position; 00489 00490 ++this->size_; 00491 00492 #if defined (ACE_WIN64) 00493 // This is a Win64 hack, necessary because of the original (bad) decision 00494 // to use a pointer as the timer ID. This class doesn't follow the usual 00495 // timer expiration rules (see comments in header file) and is probably 00496 // not used much. The dynamic allocation of Hash_Tokens without 00497 // recording them anywhere is a large problem for Win64 since the 00498 // size of a pointer is 64 bits, but a long is 32. Since this class 00499 // is not much used, I'm hacking this, at least for now. If it becomes 00500 // an issue, I'll look at it again then. 00501 intptr_t hi = reinterpret_cast<intptr_t> (h); 00502 if (this->pointer_base_ == 0) 00503 this->pointer_base_ = hi & 0xffffffff00000000; 00504 return static_cast<long> (hi & 0xffffffff); 00505 #else 00506 return reinterpret_cast<long> (h); 00507 #endif 00508 }
friend class ACE_Timer_Hash_Iterator_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET > [friend] |
size_t ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::earliest_position_ [private] |
Index to the position with the earliest entry.
Definition at line 311 of file Timer_Hash_T.h.
Referenced by ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::earliest_time(), ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::get_first(), ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::is_empty(), ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::remove_first(), ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::reschedule(), and ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::schedule_i().
HASH_ITERATOR* ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::iterator_ [private] |
Iterator used to expire timers.
Definition at line 314 of file Timer_Hash_T.h.
Referenced by ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::ACE_Timer_Hash_T(), ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::iter(), and ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::~ACE_Timer_Hash_T().
size_t ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::size_ [private] |
Keeps track of the size of the queue.
Definition at line 299 of file Timer_Hash_T.h.
Referenced by ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::cancel(), ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::expire(), and ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::remove_first().
BUCKET** ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::table_ [private] |
Table of BUCKETS.
Definition at line 302 of file Timer_Hash_T.h.
Referenced by ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::ACE_Timer_Hash_T(), ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::cancel(), ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::earliest_time(), ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::expire(), ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::find_new_earliest(), ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::get_first(), ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::is_empty(), ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::remove_first(), ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::reschedule(), ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::reset_interval(), and ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::schedule_i().
ACE_Timer_Hash_Upcall<TYPE, FUNCTOR, ACE_LOCK> ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::table_functor_ [private] |
size_t ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::table_size_ [private] |
Keeps track of the size of table_.
Definition at line 305 of file Timer_Hash_T.h.
Referenced by ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::ACE_Timer_Hash_T(), ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::cancel(), ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::dump(), ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::expire(), ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::find_new_earliest(), ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::reschedule(), ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::schedule_i(), and ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::~ACE_Timer_Hash_T().
ACE_Locked_Free_List<Hash_Token<TYPE>, ACE_Null_Mutex> ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::token_list_ [private] |
Hash_Token is usually allocated in schedule but its deallocation is problematic and token_list_ helps with this.
Definition at line 324 of file Timer_Hash_T.h.
Referenced by ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::cancel(), ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::free_node(), and ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::schedule_i().