ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET > Class Template Reference

Provides a hash table of s as an implementation for a timer queue. More...

#include <Timer_Hash_T.h>

Inheritance diagram for ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >:

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

Collaboration graph
[legend]
List of all members.

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_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 int expire (void)
virtual int expire (const ACE_Time_Value &current_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 &current_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_ITERATORiterator_
 Iterator used to expire timers.


Friends

class ACE_Timer_Hash_Iterator_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >
 Iterator is a friend.


Detailed Description

template<class TYPE, class FUNCTOR, class ACE_LOCK, class BUCKET>
class ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >

Provides a hash table of s as an implementation for a timer queue.

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.


Member Typedef Documentation

template<class TYPE, class FUNCTOR, class ACE_LOCK, class BUCKET>
typedef ACE_Timer_Hash_Iterator_T<TYPE, FUNCTOR, ACE_LOCK, BUCKET> ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::HASH_ITERATOR
 

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

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

Type inherited from.

Definition at line 171 of file Timer_Hash_T.h.


Constructor & Destructor Documentation

template<class TYPE, class FUNCTOR, class ACE_LOCK, class BUCKET>
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. 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 244 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_.

00247   : ACE_Timer_Queue_T<TYPE, FUNCTOR, ACE_LOCK> (upcall_functor, freelist),
00248     size_ (0),
00249     table_size_ (table_size),
00250     table_functor_ (this),
00251     earliest_position_ (0)
00252 #if defined (ACE_WIN64)
00253   , pointer_base_ (0)
00254 #endif /* ACE_WIN64 */
00255 {
00256   ACE_TRACE ("ACE_Timer_Hash_T::ACE_Timer_Hash_T");
00257 
00258   ACE_NEW (table_,
00259            BUCKET *[table_size]);
00260 
00261   this->gettimeofday (ACE_OS::gettimeofday);
00262 
00263   for (size_t i = 0;
00264        i < table_size;
00265        ++i)
00266     {
00267       ACE_NEW (this->table_[i],
00268                BUCKET (&this->table_functor_,
00269                        this->free_list_));
00270       this->table_[i]->gettimeofday (ACE_OS::gettimeofday);
00271     }
00272 
00273   ACE_NEW (iterator_,
00274            HASH_ITERATOR (*this));
00275 }

template<class TYPE, class FUNCTOR, class ACE_LOCK, class BUCKET>
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. 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 279 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, ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::iterator_, and ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::table_size_.

00281   : ACE_Timer_Queue_T<TYPE, FUNCTOR, ACE_LOCK> (upcall_functor, freelist),
00282     size_ (0),
00283     table_size_ (ACE_DEFAULT_TIMER_HASH_TABLE_SIZE),
00284     table_functor_ (this),
00285     earliest_position_ (0)
00286 #if defined (ACE_WIN64)
00287   , pointer_base_ (0)
00288 #endif /* ACE_WIN64 */
00289 {
00290   ACE_TRACE ("ACE_Timer_Hash_T::ACE_Timer_Hash_T");
00291 
00292   ACE_NEW (table_,
00293            BUCKET *[ACE_DEFAULT_TIMER_HASH_TABLE_SIZE]);
00294 
00295 
00296   this->gettimeofday (ACE_OS::gettimeofday);
00297 
00298   for (size_t i = 0;
00299        i < this->table_size_;
00300        ++i)
00301     {
00302       ACE_NEW (this->table_[i],
00303                BUCKET (&this->table_functor_,
00304                        this->free_list_));
00305       this->table_[i]->gettimeofday (ACE_OS::gettimeofday);
00306     }
00307 
00308   ACE_NEW (iterator_,
00309            HASH_ITERATOR (*this));
00310 }

template<class TYPE, class FUNCTOR, class ACE_LOCK, class BUCKET>
ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::~ACE_Timer_Hash_T void   )  [virtual]
 

Destructor.

Definition at line 315 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_.

00316 {
00317   ACE_TRACE ("ACE_Timer_Hash_T::~ACE_Timer_Hash_T");
00318   ACE_MT (ACE_GUARD (ACE_LOCK, ace_mon, this->mutex_));
00319 
00320   delete iterator_;
00321 
00322   for (size_t i = 0;
00323        i < this->table_size_;
00324        ++i)
00325     delete this->table_[i];
00326 
00327   delete [] this->table_;
00328 }

template<class TYPE, class FUNCTOR, class ACE_LOCK, class BUCKET>
ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::ACE_Timer_Hash_T const ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET > &   )  [private]
 


Member Function Documentation

template<class TYPE, class FUNCTOR, class ACE_LOCK, class BUCKET>
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 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 498 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().

00501 {
00502   ACE_TRACE ("ACE_Timer_Hash_T::cancel");
00503   ACE_MT (ACE_GUARD_RETURN (ACE_LOCK, ace_mon, this->mutex_, -1));
00504 
00505   // Make sure we are getting a valid <timer_id>, not an error
00506   // returned by <schedule>.
00507   if (timer_id == -1)
00508     return 0;
00509 
00510 #if defined (ACE_WIN64)
00511   unsigned long timer_offset = static_cast<unsigned long> (timer_id);
00512   Hash_Token<TYPE> *h =
00513     reinterpret_cast<Hash_Token<TYPE> *> (this->pointer_base_ + timer_offset);
00514 #else
00515   Hash_Token<TYPE> *h =
00516     reinterpret_cast<Hash_Token<TYPE> *> (timer_id);
00517 #endif /* ACE_WIN64 */
00518 
00519   int const result = this->table_[h->pos_]->cancel (h->orig_id_,
00520                                                     0,
00521                                                     dont_call);
00522 
00523   if (result == 1)
00524     {
00525       // Call the close hooks.
00526       int cookie = 0;
00527 
00528       // cancel_type() called once per <type>.
00529       this->upcall_functor ().cancel_type (*this,
00530                                            h->type_,
00531                                            dont_call,
00532                                            cookie);
00533 
00534       // cancel_timer() called once per <timer>.
00535       this->upcall_functor ().cancel_timer (*this,
00536                                             h->type_,
00537                                             dont_call,
00538                                             cookie);
00539 
00540       if (h->pos_ == this->earliest_position_)
00541         this->find_new_earliest ();
00542 
00543       if (act != 0)
00544         *act = h->act_;
00545 
00546       delete h;
00547 
00548       --this->size_;
00549     }
00550 
00551   return result;
00552 }

template<class TYPE, class FUNCTOR, class ACE_LOCK, class BUCKET>
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 . 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 557 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_, ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::table_size_, and ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >::upcall_functor().

00559 {
00560   ACE_TRACE ("ACE_Timer_Hash_T::cancel");
00561 
00562   ACE_MT (ACE_GUARD_RETURN (ACE_LOCK, ace_mon, this->mutex_, -1));
00563 
00564   size_t i; // loop variable.
00565 
00566   Hash_Token<TYPE> **timer_ids = 0;
00567 
00568   ACE_NEW_RETURN (timer_ids,
00569                   Hash_Token<TYPE> *[this->size_],
00570                   -1);
00571   size_t pos = 0;
00572 
00573   for (i = 0;
00574        i < this->table_size_;
00575        ++i)
00576     {
00577       ACE_Timer_Queue_Iterator_T<TYPE,
00578                                  ACE_Timer_Hash_Upcall<TYPE, FUNCTOR, ACE_LOCK>,
00579                                  ACE_Null_Mutex> &iter =
00580         this->table_[i]->iter ();
00581 
00582       for (iter.first ();
00583            !iter.isdone ();
00584            iter.next ())
00585         if (iter.item ()->get_type () == type)
00586           timer_ids[pos++] =
00587             reinterpret_cast<Hash_Token<TYPE> *> (
00588               const_cast<void *> (iter.item ()->get_act ()));
00589     }
00590 
00591   if (pos > this->size_)
00592     return -1;
00593 
00594   for (i = 0; i < pos; ++i)
00595     {
00596       int const result =
00597         this->table_[timer_ids[i]->pos_]->cancel (timer_ids[i]->orig_id_,
00598                                                   0,
00599                                                   dont_call);
00600       ACE_ASSERT (result == 1);
00601       ACE_UNUSED_ARG (result);
00602 
00603       delete timer_ids[i];
00604 
00605       --this->size_;
00606     }
00607 
00608   delete [] timer_ids;
00609 
00610   this->find_new_earliest ();
00611 
00612   // Call the close hooks.
00613   int cookie = 0;
00614 
00615   // cancel_type() called once per <type>.
00616   this->upcall_functor ().cancel_type (*this,
00617                                        type,
00618                                        dont_call,
00619                                        cookie);
00620 
00621   for (i = 0;
00622        i < pos;
00623        ++i)
00624     {
00625       // cancel_timer() called once per <timer>.
00626       this->upcall_functor ().cancel_timer (*this,
00627                                             type,
00628                                             dont_call,
00629                                             cookie);
00630     }
00631 
00632   return static_cast<int> (pos);
00633 }

template<class TYPE, class FUNCTOR, class ACE_LOCK, class BUCKET>
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 680 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().

00682 {
00683   int const result =
00684     ACE_Timer_Queue_T<TYPE,FUNCTOR,ACE_LOCK>::dispatch_info_i (cur_time,
00685                                                                info);
00686 
00687   if (result == 1)
00688     {
00689       Hash_Token<TYPE> *h =
00690         reinterpret_cast<Hash_Token<TYPE> *> (const_cast<void *> (info.act_));
00691 
00692       info.act_ = h->act_;
00693     }
00694 
00695   return result;
00696 }

template<class TYPE, class FUNCTOR, class ACE_LOCK, class BUCKET>
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 349 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_.

00350 {
00351 #if defined (ACE_HAS_DUMP)
00352   ACE_TRACE ("ACE_Timer_Hash_T::dump");
00353   ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
00354   ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\ntable_size_ = %d"), this->table_size_));
00355   ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\nearliest_position_ = %d"), this->earliest_position_));
00356 
00357   for (size_t i = 0; i < this->table_size_; ++i)
00358     if (!this->table_[i]->is_empty ())
00359       ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\nBucket %d contains nodes"), i));
00360 
00361   ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\n")));
00362   ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00363 #endif /* ACE_HAS_DUMP */
00364 }

template<class TYPE, class FUNCTOR, class ACE_LOCK, class BUCKET>
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 . Must be called on a non-empty queue.

Implements ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >.

Definition at line 342 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().

00343 {
00344   ACE_TRACE ("ACE_Timer_Hash_T::earliest_time");
00345   return this->table_[this->earliest_position_]->earliest_time ();
00346 }

template<class TYPE, class FUNCTOR, class ACE_LOCK, class BUCKET>
int ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::expire const ACE_Time_Value current_time  )  [virtual]
 

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 709 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(), ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::table_size_, and ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >::upcall().

00710 {
00711   ACE_TRACE ("ACE_Timer_Hash_T::expire");
00712   ACE_MT (ACE_GUARD_RETURN (ACE_LOCK, ace_mon, this->mutex_, -1));
00713 
00714   int number_of_timers_expired = 0;
00715 
00716   ACE_Timer_Node_T<TYPE> *expired = 0;
00717 
00718   // Go through the table and expire anything that can be expired
00719 
00720   for (size_t i = 0;
00721        i < this->table_size_;
00722        ++i)
00723     {
00724       while (!this->table_[i]->is_empty ()
00725              && this->table_[i]->earliest_time () <= cur_time)
00726         {
00727           expired = this->table_[i]->remove_first ();
00728           const void *act = expired->get_act ();
00729           int reclaim = 1;
00730 
00731           Hash_Token<TYPE> *h =
00732             reinterpret_cast<Hash_Token<TYPE> *> (const_cast<void *> (act));
00733 
00734           ACE_ASSERT (h->pos_ == i);
00735 
00736 #if 0
00737           ACE_DEBUG ((LM_DEBUG, "Hash::expire() expiring %d in slot %d where it's id is %d and token is %x\n",
00738                       expired->get_timer_value ().msec (),
00739                       h->pos_,
00740                       h->orig_id_,
00741                       h));
00742 #endif
00743 
00744           // Check if this is an interval timer.
00745           if (expired->get_interval () > ACE_Time_Value::zero)
00746             {
00747               // Make sure that we skip past values that have already
00748               // "expired".
00749               do
00750                 expired->set_timer_value (expired->get_timer_value ()
00751                                           + expired->get_interval ());
00752               while (expired->get_timer_value () <= cur_time);
00753 
00754               // Since this is an interval timer, we need to
00755               // reschedule it.
00756               this->reschedule (expired);
00757               reclaim = 0;
00758             }
00759 
00760           ACE_Timer_Node_Dispatch_Info_T<TYPE> info;
00761 
00762           // Get the dispatch info
00763           expired->get_dispatch_info (info);
00764 
00765           info.act_ = h->act_;
00766 
00767           const void *upcall_act = 0;
00768 
00769           this->preinvoke (info, cur_time, upcall_act);
00770 
00771           this->upcall (info, cur_time);
00772 
00773           this->postinvoke (info, cur_time, upcall_act);
00774 
00775           if (reclaim)
00776             {
00777               --this->size_;
00778               delete h;
00779             }
00780 
00781           ++number_of_timers_expired;
00782          }
00783     }
00784 
00785   if (number_of_timers_expired > 0)
00786     this->find_new_earliest ();
00787 
00788   return number_of_timers_expired;
00789 }

template<class TYPE, class FUNCTOR, class ACE_LOCK, class BUCKET>
int ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::expire void   )  [virtual]
 

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 701 of file Timer_Hash_T.cpp.

References ACE_Timer_Queue_T< TYPE, FUNCTOR, ACE_LOCK >::expire().

00702 {
00703   return ACE_Timer_Queue_T<TYPE,FUNCTOR,ACE_LOCK>::expire();
00704 }

template<class TYPE, class FUNCTOR, class ACE_LOCK, class BUCKET>
void ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::find_new_earliest void   )  [private]
 

Finds the earliest node.

Definition at line 656 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 >::earliest_time(), and ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::table_size_.

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

00657 {
00658   for (size_t i = 0; i < this->table_size_; ++i)
00659     if (!this->table_[i]->is_empty ())
00660       if (this->table_[this->earliest_position_]->is_empty ()
00661           || this->earliest_time () == ACE_Time_Value::zero
00662           || this->table_[i]->earliest_time () <= this->earliest_time ())
00663           this->earliest_position_ = i;
00664 }

template<class TYPE, class FUNCTOR, class ACE_LOCK, class BUCKET>
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 669 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().

00670 {
00671   ACE_TRACE ("ACE_Timer_Hash_T::get_first");
00672 
00673   if (this->is_empty ())
00674     return 0;
00675 
00676   return this->table_[this->earliest_position_]->get_first ();
00677 }

template<class TYPE, class FUNCTOR, class ACE_LOCK, class BUCKET>
int 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 333 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().

00334 {
00335   ACE_TRACE ("ACE_Timer_Hash_T::is_empty");
00336   return this->table_[this->earliest_position_]->is_empty ();
00337 }

template<class TYPE, class FUNCTOR, class ACE_LOCK, class BUCKET>
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 235 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().

00236 {
00237   this->iterator_->first ();
00238   return *this->iterator_;
00239 }

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

template<class TYPE, class FUNCTOR, class ACE_LOCK, class BUCKET>
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 638 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().

00639 {
00640   if (this->is_empty ())
00641     return 0;
00642 
00643   ACE_Timer_Node_T<TYPE> *temp =
00644     this->table_[this->earliest_position_]->remove_first ();
00645 
00646   this->find_new_earliest ();
00647 
00648   --this->size_;
00649 
00650   return temp;
00651 }

template<class TYPE, class FUNCTOR, class ACE_LOCK, class BUCKET>
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 370 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_, ACE_Time_Value::sec(), and ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::table_size_.

Referenced by ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::expire().

00371 {
00372   ACE_TRACE ("ACE_Timer_Hash_T::reschedule");
00373 
00374   Hash_Token<TYPE> *h =
00375     reinterpret_cast<Hash_Token<TYPE> *> (
00376       const_cast<void *> (expired->get_act ()));
00377 
00378   size_t secs_hash_input =
00379     ACE_Utils::truncate_cast<size_t> (expired->get_timer_value ().sec ());
00380   h->pos_ = secs_hash_input % this->table_size_;
00381 
00382   h->orig_id_ =
00383     this->table_[h->pos_]->schedule (expired->get_type (),
00384                                      h,
00385                                      expired->get_timer_value (),
00386                                      expired->get_interval ());
00387   ACE_ASSERT (h->orig_id_ != -1);
00388 
00389 #if 0
00390   ACE_DEBUG ((LM_DEBUG, "Hash::reschedule() resets %d in slot %d where it's id is %d and token is %x\n",
00391               expired->get_timer_value ().msec (),
00392               h->pos_,
00393               h->orig_id_,
00394               h));
00395 #endif
00396 
00397   if (this->table_[this->earliest_position_]->is_empty ()
00398       || this->table_[h->pos_]->earliest_time ()
00399       < this->table_[this->earliest_position_]->earliest_time ())
00400     this->earliest_position_ = h->pos_;
00401 }

template<class TYPE, class FUNCTOR, class ACE_LOCK, class BUCKET>
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 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 469 of file Timer_Hash_T.cpp.

References ACE_GUARD_RETURN, ACE_TRACE, Hash_Token< TYPE >::orig_id_, and Hash_Token< TYPE >::pos_.

00471 {
00472   ACE_TRACE ("ACE_Timer_Hash_T::reset_interval");
00473   ACE_MT (ACE_GUARD_RETURN (ACE_LOCK, ace_mon, this->mutex_, -1));
00474 
00475   // Make sure we are getting a valid <timer_id>, not an error
00476   // returned by <schedule>.
00477   if (timer_id == -1)
00478     return -1;
00479 
00480 
00481 #if defined (ACE_WIN64)
00482   unsigned long timer_offset = static_cast<unsigned long> (timer_id);
00483   Hash_Token<TYPE> *h =
00484     reinterpret_cast<Hash_Token<TYPE> *> (this->pointer_base_ + timer_offset);
00485 #else
00486   Hash_Token<TYPE> *h =
00487     reinterpret_cast<Hash_Token<TYPE> *> (timer_id);
00488 #endif /* ACE_WIN64 */
00489 
00490   return this->table_[h->pos_]->reset_interval (h->orig_id_,
00491                                                 interval);
00492 }

template<class TYPE, class FUNCTOR, class ACE_LOCK, class BUCKET>
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 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 407 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_, ACE_Time_Value::sec(), and ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::table_size_.

00411 {
00412   ACE_TRACE ("ACE_Timer_Hash_T::schedule_i");
00413 
00414   size_t secs_hash_input = ACE_Utils::truncate_cast<size_t> (future_time.sec ());
00415   size_t position = secs_hash_input % this->table_size_;
00416 
00417   Hash_Token<TYPE> *h = 0;
00418 
00419   ACE_NEW_RETURN (h,
00420                   Hash_Token<TYPE> (act,
00421                                     position,
00422                                     0,
00423                                     type),
00424                   -1);
00425 
00426   h->orig_id_ =
00427     this->table_[position]->schedule (type,
00428                                       h,
00429                                       future_time,
00430                                       interval);
00431   ACE_ASSERT (h->orig_id_ != -1);
00432 
00433 #if 0
00434   ACE_DEBUG ((LM_DEBUG, "Hash::schedule() placing %d in slot %d where it's id is %d and token is %x\n",
00435               future_time.msec (),
00436               position,
00437               h->orig_id_,
00438               h));
00439 #endif
00440 
00441   if (this->table_[this->earliest_position_]->is_empty ()
00442       || this->table_[position]->earliest_time ()
00443       < this->table_[this->earliest_position_]->earliest_time ())
00444     this->earliest_position_ = position;
00445 
00446   ++this->size_;
00447 
00448 #if defined (ACE_WIN64)
00449   // This is a Win64 hack, necessary because of the original (bad) decision
00450   // to use a pointer as the timer ID. This class doesn't follow the usual
00451   // timer expiration rules (see comments in header file) and is probably
00452   // not used much. The dynamic allocation of Hash_Tokens without
00453   // recording them anywhere is a large problem for Win64 since the
00454   // size of a pointer is 64 bits, but a long is 32. Since this class
00455   // is not much used, I'm hacking this, at least for now. If it becomes
00456   // an issue, I'll look at it again then.
00457   intptr_t hi = reinterpret_cast<intptr_t> (h);
00458   if (this->pointer_base_ == 0)
00459     this->pointer_base_ = hi & 0xffffffff00000000;
00460   return static_cast<long> (hi & 0xffffffff);
00461 #else
00462   return reinterpret_cast<long> (h);
00463 #endif
00464 }


Friends And Related Function Documentation

template<class TYPE, class FUNCTOR, class ACE_LOCK, class BUCKET>
friend class ACE_Timer_Hash_Iterator_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET > [friend]
 

Iterator is a friend.

Definition at line 168 of file Timer_Hash_T.h.


Member Data Documentation

template<class TYPE, class FUNCTOR, class ACE_LOCK, class BUCKET>
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 301 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 >::earliest_time(), 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(), and ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::schedule_i().

template<class TYPE, class FUNCTOR, class ACE_LOCK, class BUCKET>
HASH_ITERATOR* ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::iterator_ [private]
 

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

template<class TYPE, class FUNCTOR, class ACE_LOCK, class BUCKET>
size_t ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::size_ [private]
 

Keeps track of the size of the queue.

Definition at line 289 of file Timer_Hash_T.h.

template<class TYPE, class FUNCTOR, class ACE_LOCK, class BUCKET>
BUCKET** ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::table_ [private]
 

Table of BUCKETS.

Definition at line 292 of file Timer_Hash_T.h.

template<class TYPE, class FUNCTOR, class ACE_LOCK, class BUCKET>
ACE_Timer_Hash_Upcall<TYPE, FUNCTOR, ACE_LOCK> ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::table_functor_ [private]
 

Functor used for the table's timer queues.

Definition at line 298 of file Timer_Hash_T.h.

template<class TYPE, class FUNCTOR, class ACE_LOCK, class BUCKET>
size_t ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::table_size_ [private]
 

Keeps track of the size of table_.

Definition at line 295 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().


The documentation for this class was generated from the following files:
Generated on Sun Jan 27 12:58:49 2008 for ACE by doxygen 1.3.6