#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 int | 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. | |
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" . | |
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. | |
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 160 of file Timer_Hash_T.h.
|
Type of iterator.
Definition at line 165 of file Timer_Hash_T.h. Referenced by ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::ACE_Timer_Hash_T(). |
|
Type inherited from.
Definition at line 171 of file Timer_Hash_T.h. |
|
Default constructor. determines the size of the hash table. is the instance of the FUNCTOR to be used by the buckets. If is 0, a default FUNCTOR will be created. Definition at line 243 of file Timer_Hash_T.cpp. References ACE_NEW, ACE_TRACE, ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >::gettimeofday(), ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::HASH_ITERATOR, and ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::iterator_.
00246 : ACE_Timer_Queue_T<TYPE, FUNCTOR, ACE_LOCK> (upcall_functor, freelist), 00247 size_ (0), 00248 table_size_ (table_size), 00249 table_functor_ (this), 00250 earliest_position_ (0) 00251 #if defined (ACE_WIN64) 00252 , pointer_base_ (0) 00253 #endif /* ACE_WIN64 */ 00254 { 00255 ACE_TRACE ("ACE_Timer_Hash_T::ACE_Timer_Hash_T"); 00256 00257 ACE_NEW (table_, 00258 BUCKET *[table_size]); 00259 00260 this->gettimeofday (ACE_OS::gettimeofday); 00261 00262 for (size_t i = 0; 00263 i < table_size; 00264 ++i) 00265 { 00266 ACE_NEW (this->table_[i], 00267 BUCKET (&this->table_functor_, 00268 this->free_list_)); 00269 this->table_[i]->gettimeofday (ACE_OS::gettimeofday); 00270 } 00271 00272 ACE_NEW (iterator_, 00273 HASH_ITERATOR (*this)); 00274 } |
|
Default constructor. is the instance of the FUNCTOR to be used by the queue. If is 0, Timer Hash will create a default FUNCTOR. 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 278 of file Timer_Hash_T.cpp. References ACE_DEFAULT_TIMER_HASH_TABLE_SIZE, ACE_NEW, ACE_TRACE, ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >::gettimeofday(), ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::HASH_ITERATOR, and ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::iterator_.
00280 : ACE_Timer_Queue_T<TYPE, FUNCTOR, ACE_LOCK> (upcall_functor, freelist), 00281 size_ (0), 00282 table_size_ (ACE_DEFAULT_TIMER_HASH_TABLE_SIZE), 00283 table_functor_ (this), 00284 earliest_position_ (0) 00285 #if defined (ACE_WIN64) 00286 , pointer_base_ (0) 00287 #endif /* ACE_WIN64 */ 00288 { 00289 ACE_TRACE ("ACE_Timer_Hash_T::ACE_Timer_Hash_T"); 00290 00291 ACE_NEW (table_, 00292 BUCKET *[ACE_DEFAULT_TIMER_HASH_TABLE_SIZE]); 00293 00294 00295 this->gettimeofday (ACE_OS::gettimeofday); 00296 00297 for (size_t i = 0; 00298 i < this->table_size_; 00299 ++i) 00300 { 00301 ACE_NEW (this->table_[i], 00302 BUCKET (&this->table_functor_, 00303 this->free_list_)); 00304 this->table_[i]->gettimeofday (ACE_OS::gettimeofday); 00305 } 00306 00307 ACE_NEW (iterator_, 00308 HASH_ITERATOR (*this)); 00309 } |
|
Destructor.
Definition at line 314 of file Timer_Hash_T.cpp. References ACE_GUARD, ACE_TRACE, and ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::iterator_.
00315 { 00316 ACE_TRACE ("ACE_Timer_Hash_T::~ACE_Timer_Hash_T"); 00317 ACE_MT (ACE_GUARD (ACE_LOCK, ace_mon, this->mutex_)); 00318 00319 delete iterator_; 00320 00321 for (size_t i = 0; 00322 i < this->table_size_; 00323 ++i) 00324 delete this->table_[i]; 00325 00326 delete [] this->table_; 00327 } |
|
|
|
Cancel the single timer that matches the value (which was returned from the 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 is 0 then the will be invoked. Returns 1 if cancellation succeeded and 0 if the wasn't found. Implements ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >. Definition at line 496 of file Timer_Hash_T.cpp. References ACE_GUARD_RETURN, ACE_TRACE, Hash_Token< TYPE >::act_, ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::earliest_position_, ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::find_new_earliest(), Hash_Token< TYPE >::orig_id_, Hash_Token< TYPE >::pos_, Hash_Token< TYPE >::type_, and ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >::upcall_functor().
00499 { 00500 ACE_TRACE ("ACE_Timer_Hash_T::cancel"); 00501 ACE_MT (ACE_GUARD_RETURN (ACE_LOCK, ace_mon, this->mutex_, -1)); 00502 00503 // Make sure we are getting a valid <timer_id>, not an error 00504 // returned by <schedule>. 00505 if (timer_id == -1) 00506 return 0; 00507 00508 #if defined (ACE_WIN64) 00509 unsigned long timer_offset = static_cast<unsigned long> (timer_id); 00510 Hash_Token<TYPE> *h = 00511 reinterpret_cast<Hash_Token<TYPE> *> (this->pointer_base_ + timer_offset); 00512 #else 00513 Hash_Token<TYPE> *h = 00514 reinterpret_cast<Hash_Token<TYPE> *> (timer_id); 00515 #endif /* ACE_WIN64 */ 00516 00517 int const result = this->table_[h->pos_]->cancel (h->orig_id_, 00518 0, 00519 dont_call); 00520 00521 if (result == 1) 00522 { 00523 // Call the close hooks. 00524 int cookie = 0; 00525 00526 // cancel_type() called once per <type>. 00527 this->upcall_functor ().cancel_type (*this, 00528 h->type_, 00529 dont_call, 00530 cookie); 00531 00532 // cancel_timer() called once per <timer>. 00533 this->upcall_functor ().cancel_timer (*this, 00534 h->type_, 00535 dont_call, 00536 cookie); 00537 00538 if (h->pos_ == this->earliest_position_) 00539 this->find_new_earliest (); 00540 00541 if (act != 0) 00542 *act = h->act_; 00543 00544 delete h; 00545 00546 --this->size_; 00547 } 00548 00549 return result; 00550 } |
|
Cancel all timer associated with . If is 0 then the will be invoked. Returns number of timers cancelled. Implements ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >. Definition at line 555 of file Timer_Hash_T.cpp. References ACE_ASSERT, ACE_GUARD_RETURN, ACE_NEW_RETURN, ACE_TRACE, 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 >::pos_, and ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >::upcall_functor().
00557 { 00558 ACE_TRACE ("ACE_Timer_Hash_T::cancel"); 00559 00560 ACE_MT (ACE_GUARD_RETURN (ACE_LOCK, ace_mon, this->mutex_, -1)); 00561 00562 size_t i; // loop variable. 00563 00564 Hash_Token<TYPE> **timer_ids = 0; 00565 00566 ACE_NEW_RETURN (timer_ids, 00567 Hash_Token<TYPE> *[this->size_], 00568 -1); 00569 size_t pos = 0; 00570 00571 for (i = 0; 00572 i < this->table_size_; 00573 ++i) 00574 { 00575 ACE_Timer_Queue_Iterator_T<TYPE, 00576 ACE_Timer_Hash_Upcall<TYPE, FUNCTOR, ACE_LOCK>, 00577 ACE_Null_Mutex> &iter = 00578 this->table_[i]->iter (); 00579 00580 for (iter.first (); 00581 !iter.isdone (); 00582 iter.next ()) 00583 if (iter.item ()->get_type () == type) 00584 timer_ids[pos++] = 00585 reinterpret_cast<Hash_Token<TYPE> *> ( 00586 const_cast<void *> (iter.item ()->get_act ())); 00587 } 00588 00589 if (pos > this->size_) 00590 return -1; 00591 00592 for (i = 0; i < pos; ++i) 00593 { 00594 int const result = 00595 this->table_[timer_ids[i]->pos_]->cancel (timer_ids[i]->orig_id_, 00596 0, 00597 dont_call); 00598 ACE_ASSERT (result == 1); 00599 ACE_UNUSED_ARG (result); 00600 00601 delete timer_ids[i]; 00602 00603 --this->size_; 00604 } 00605 00606 delete [] timer_ids; 00607 00608 this->find_new_earliest (); 00609 00610 // Call the close hooks. 00611 int cookie = 0; 00612 00613 // cancel_type() called once per <type>. 00614 this->upcall_functor ().cancel_type (*this, 00615 type, 00616 dont_call, 00617 cookie); 00618 00619 for (i = 0; 00620 i < pos; 00621 ++i) 00622 { 00623 // cancel_timer() called once per <timer>. 00624 this->upcall_functor ().cancel_timer (*this, 00625 type, 00626 dont_call, 00627 cookie); 00628 } 00629 00630 return static_cast<int> (pos); 00631 } |
|
Non-locking version of dispatch_info ().
Reimplemented from ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >. Definition at line 678 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().
00680 { 00681 int const result = 00682 ACE_Timer_Queue_T<TYPE,FUNCTOR,ACE_LOCK>::dispatch_info_i (cur_time, 00683 info); 00684 00685 if (result == 1) 00686 { 00687 Hash_Token<TYPE> *h = 00688 reinterpret_cast<Hash_Token<TYPE> *> (const_cast<void *> (info.act_)); 00689 00690 info.act_ = h->act_; 00691 } 00692 00693 return result; 00694 } |
|
Dump the state of an object.
Reimplemented from ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >. Definition at line 348 of file Timer_Hash_T.cpp. References ACE_BEGIN_DUMP, ACE_DEBUG, ACE_END_DUMP, ACE_LIB_TEXT, ACE_TRACE, and LM_DEBUG.
00349 { 00350 #if defined (ACE_HAS_DUMP) 00351 ACE_TRACE ("ACE_Timer_Hash_T::dump"); 00352 ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this)); 00353 ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\ntable_size_ = %d"), this->table_size_)); 00354 ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\nearliest_position_ = %d"), this->earliest_position_)); 00355 00356 for (size_t i = 0; i < this->table_size_; ++i) 00357 if (!this->table_[i]->is_empty ()) 00358 ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\nBucket %d contains nodes"), i)); 00359 00360 ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\n"))); 00361 ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP)); 00362 #endif /* ACE_HAS_DUMP */ 00363 } |
|
Returns the time of the earlier node in the . Must be called on a non-empty queue. Implements ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >. Definition at line 341 of file Timer_Hash_T.cpp. References ACE_TRACE, and ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::earliest_position_. Referenced by ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::find_new_earliest().
00342 { 00343 ACE_TRACE ("ACE_Timer_Hash_T::earliest_time"); 00344 return this->table_[this->earliest_position_]->earliest_time (); 00345 } |
|
Run the for all timers whose values are <= . This does not account for . Returns the number of timers canceled. Reimplemented from ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >. Definition at line 707 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_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(), and ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >::upcall().
00708 { 00709 ACE_TRACE ("ACE_Timer_Hash_T::expire"); 00710 ACE_MT (ACE_GUARD_RETURN (ACE_LOCK, ace_mon, this->mutex_, -1)); 00711 00712 int number_of_timers_expired = 0; 00713 00714 ACE_Timer_Node_T<TYPE> *expired = 0; 00715 00716 // Go through the table and expire anything that can be expired 00717 00718 for (size_t i = 0; 00719 i < this->table_size_; 00720 ++i) 00721 { 00722 while (!this->table_[i]->is_empty () 00723 && this->table_[i]->earliest_time () <= cur_time) 00724 { 00725 expired = this->table_[i]->remove_first (); 00726 const void *act = expired->get_act (); 00727 int reclaim = 1; 00728 00729 Hash_Token<TYPE> *h = 00730 reinterpret_cast<Hash_Token<TYPE> *> (const_cast<void *> (act)); 00731 00732 ACE_ASSERT (h->pos_ == i); 00733 00734 #if 0 00735 ACE_DEBUG ((LM_DEBUG, "Hash::expire() expiring %d in slot %d where it's id is %d and token is %x\n", 00736 expired->get_timer_value ().msec (), 00737 h->pos_, 00738 h->orig_id_, 00739 h)); 00740 #endif 00741 00742 // Check if this is an interval timer. 00743 if (expired->get_interval () > ACE_Time_Value::zero) 00744 { 00745 // Make sure that we skip past values that have already 00746 // "expired". 00747 do 00748 expired->set_timer_value (expired->get_timer_value () 00749 + expired->get_interval ()); 00750 while (expired->get_timer_value () <= cur_time); 00751 00752 // Since this is an interval timer, we need to 00753 // reschedule it. 00754 this->reschedule (expired); 00755 reclaim = 0; 00756 } 00757 00758 ACE_Timer_Node_Dispatch_Info_T<TYPE> info; 00759 00760 // Get the dispatch info 00761 expired->get_dispatch_info (info); 00762 00763 info.act_ = h->act_; 00764 00765 const void *upcall_act = 0; 00766 00767 this->preinvoke (info, cur_time, upcall_act); 00768 00769 this->upcall (info, cur_time); 00770 00771 this->postinvoke (info, cur_time, upcall_act); 00772 00773 if (reclaim) 00774 { 00775 --this->size_; 00776 delete h; 00777 } 00778 00779 ++number_of_timers_expired; 00780 } 00781 } 00782 00783 if (number_of_timers_expired > 0) 00784 this->find_new_earliest (); 00785 00786 return number_of_timers_expired; 00787 } |
|
Run the for all timers whose values are <= <ACE_OS::gettimeofday>. Also accounts for . Returns the number of timers canceled. Reimplemented from ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >. Definition at line 699 of file Timer_Hash_T.cpp. References ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >::expire().
00700 { 00701 return ACE_Timer_Queue_T<TYPE,FUNCTOR,ACE_LOCK>::expire(); 00702 } |
|
Finds the earliest node.
Definition at line 654 of file Timer_Hash_T.cpp. References ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::earliest_position_, and ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::earliest_time(). 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().
00655 { 00656 for (size_t i = 0; i < this->table_size_; ++i) 00657 if (!this->table_[i]->is_empty ()) 00658 if (this->table_[this->earliest_position_]->is_empty () 00659 || this->earliest_time () == ACE_Time_Value::zero 00660 || this->table_[i]->earliest_time () <= this->earliest_time ()) 00661 this->earliest_position_ = i; 00662 } |
|
Reads the earliest node from the queue and returns it.
Implements ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >. Definition at line 667 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 >::is_empty().
00668 { 00669 ACE_TRACE ("ACE_Timer_Hash_T::get_first"); 00670 00671 if (this->is_empty ()) 00672 return 0; 00673 00674 return this->table_[this->earliest_position_]->get_first (); 00675 } |
|
True if queue is empty, else false.
Implements ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >. Definition at line 332 of file Timer_Hash_T.cpp. References ACE_TRACE, and ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::earliest_position_. Referenced by ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::get_first(), and ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::remove_first().
00333 { 00334 ACE_TRACE ("ACE_Timer_Hash_T::is_empty"); 00335 return this->table_[this->earliest_position_]->is_empty (); 00336 } |
|
Returns a pointer to this ACE_Timer_Queue's iterator.
Implements ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >. Definition at line 234 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().
|
|
|
|
Removes the earliest node from the queue and returns it.
Implements ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >. Definition at line 636 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(), and ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::is_empty().
00637 { 00638 if (this->is_empty ()) 00639 return 0; 00640 00641 ACE_Timer_Node_T<TYPE> *temp = 00642 this->table_[this->earliest_position_]->remove_first (); 00643 00644 this->find_new_earliest (); 00645 00646 --this->size_; 00647 00648 return temp; 00649 } |
|
Reschedule an "interval" .
Implements ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >. Definition at line 369 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_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_, and ACE_Time_Value::sec(). Referenced by ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::expire().
00370 { 00371 ACE_TRACE ("ACE_Timer_Hash_T::reschedule"); 00372 00373 Hash_Token<TYPE> *h = 00374 reinterpret_cast<Hash_Token<TYPE> *> ( 00375 const_cast<void *> (expired->get_act ())); 00376 00377 h->pos_ = 00378 expired->get_timer_value ().sec () % this->table_size_; 00379 00380 h->orig_id_ = 00381 this->table_[h->pos_]->schedule (expired->get_type (), 00382 h, 00383 expired->get_timer_value (), 00384 expired->get_interval ()); 00385 ACE_ASSERT (h->orig_id_ != -1); 00386 00387 #if 0 00388 ACE_DEBUG ((LM_DEBUG, "Hash::reschedule() resets %d in slot %d where it's id is %d and token is %x\n", 00389 expired->get_timer_value ().msec (), 00390 h->pos_, 00391 h->orig_id_, 00392 h)); 00393 #endif 00394 00395 if (this->table_[this->earliest_position_]->is_empty () 00396 || this->table_[h->pos_]->earliest_time () 00397 < this->table_[this->earliest_position_]->earliest_time ()) 00398 this->earliest_position_ = h->pos_; 00399 } |
|
Resets the interval of the timer represented by to , which is specified in relative time to the current . If 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 467 of file Timer_Hash_T.cpp. References ACE_GUARD_RETURN, ACE_TRACE, Hash_Token< TYPE >::orig_id_, and Hash_Token< TYPE >::pos_.
00469 { 00470 ACE_TRACE ("ACE_Timer_Hash_T::reset_interval"); 00471 ACE_MT (ACE_GUARD_RETURN (ACE_LOCK, ace_mon, this->mutex_, -1)); 00472 00473 // Make sure we are getting a valid <timer_id>, not an error 00474 // returned by <schedule>. 00475 if (timer_id == -1) 00476 return -1; 00477 00478 00479 #if defined (ACE_WIN64) 00480 unsigned long timer_offset = static_cast<unsigned long> (timer_id); 00481 Hash_Token<TYPE> *h = 00482 reinterpret_cast<Hash_Token<TYPE> *> (this->pointer_base_ + timer_offset); 00483 #else 00484 Hash_Token<TYPE> *h = 00485 reinterpret_cast<Hash_Token<TYPE> *> (timer_id); 00486 #endif /* ACE_WIN64 */ 00487 00488 return this->table_[h->pos_]->reset_interval (h->orig_id_, 00489 interval); 00490 } |
|
Schedule that will expire at , which is specified in absolute time. If it expires then is passed in as the value to the . If is != to <ACE_Time_Value::zero> then it is used to reschedule the automatically, using relative time to the current . This method returns a that is a pointer to a token which stores information about the event. This 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 405 of file Timer_Hash_T.cpp. References ACE_ASSERT, ACE_DEBUG, ACE_NEW_RETURN, ACE_TRACE, ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::earliest_position_, LM_DEBUG, ACE_Time_Value::msec(), Hash_Token< TYPE >::orig_id_, and ACE_Time_Value::sec().
00409 { 00410 ACE_TRACE ("ACE_Timer_Hash_T::schedule_i"); 00411 00412 size_t position = 00413 future_time.sec () % this->table_size_; 00414 00415 Hash_Token<TYPE> *h = 0; 00416 00417 ACE_NEW_RETURN (h, 00418 Hash_Token<TYPE> (act, 00419 position, 00420 0, 00421 type), 00422 -1); 00423 00424 h->orig_id_ = 00425 this->table_[position]->schedule (type, 00426 h, 00427 future_time, 00428 interval); 00429 ACE_ASSERT (h->orig_id_ != -1); 00430 00431 #if 0 00432 ACE_DEBUG ((LM_DEBUG, "Hash::schedule() placing %d in slot %d where it's id is %d and token is %x\n", 00433 future_time.msec (), 00434 position, 00435 h->orig_id_, 00436 h)); 00437 #endif 00438 00439 if (this->table_[this->earliest_position_]->is_empty () 00440 || this->table_[position]->earliest_time () 00441 < this->table_[this->earliest_position_]->earliest_time ()) 00442 this->earliest_position_ = position; 00443 00444 ++this->size_; 00445 00446 #if defined (ACE_WIN64) 00447 // This is a Win64 hack, necessary because of the original (bad) decision 00448 // to use a pointer as the timer ID. This class doesn't follow the usual 00449 // timer expiration rules (see comments in header file) and is probably 00450 // not used much. The dynamic allocation of Hash_Tokens without 00451 // recording them anywhere is a large problem for Win64 since the 00452 // size of a pointer is 64 bits, but a long is 32. Since this class 00453 // is not much used, I'm hacking this, at least for now. If it becomes 00454 // an issue, I'll look at it again then. 00455 ptrdiff_t hi = reinterpret_cast<ptrdiff_t> (h); 00456 if (this->pointer_base_ == 0) 00457 this->pointer_base_ = hi & 0xffffffff00000000; 00458 return static_cast<long> (hi & 0xffffffff); 00459 #else 00460 return reinterpret_cast<long> (h); 00461 #endif 00462 } |
|
Iterator is a friend.
Definition at line 168 of file Timer_Hash_T.h. |
|
|
Iterator used to expire timers.
Definition at line 304 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(). |
|
Keeps track of the size of the queue.
Definition at line 289 of file Timer_Hash_T.h. |
|
Table of BUCKETS.
Definition at line 292 of file Timer_Hash_T.h. |
|
Functor used for the table's timer queues.
Definition at line 298 of file Timer_Hash_T.h. |
|
Keeps track of the size of table_.
Definition at line 295 of file Timer_Hash_T.h. |