Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

ACE_Timer_Hash_T Class Template Reference

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

#include <Timer_Hash_T.h>

Inheritance diagram for ACE_Timer_Hash_T:

Inheritance graph
[legend]
Collaboration diagram for ACE_Timer_Hash_T:

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. More...

typedef ACE_Timer_Queue_T<
TYPE, FUNCTOR, ACE_LOCK > 
INHERITED
 Type inherited from. More...


Public Methods

 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. More...

virtual int is_empty (void) const
 True if queue is empty, else false. More...

virtual const ACE_Time_Valueearliest_time (void) const
 Returns the time of the earlier node in the <ACE_Timer_Hash>. Must be called on a non-empty queue. More...

virtual long schedule (const TYPE &type, const void *act, const ACE_Time_Value &future_time, const ACE_Time_Value &interval=ACE_Time_Value::zero)
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. More...

virtual ACE_Timer_Node_T<
TYPE > * 
remove_first (void)
 Removes the earliest node from the queue and returns it. More...

virtual void dump (void) const
 Dump the state of an object. More...

virtual ACE_Timer_Node_T<
TYPE > * 
get_first (void)
 Reads the earliest node from the queue and returns it. More...


Private Methods

virtual void reschedule (ACE_Timer_Node_T< TYPE > *)
 Reschedule an "interval" <ACE_Timer_Node>. More...

void find_new_earliest (void)
 Finds the earliest node. More...

 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. More...

BUCKET ** table_
 Table of BUCKETS. More...

size_t table_size_
 Keeps track of the size of table_. More...

ACE_Timer_Hash_Upcall< TYPE,
FUNCTOR, ACE_LOCK > 
table_functor_
 Functor used for the table's timer queues. More...

size_t earliest_position_
 Index to the position with the earliest entry. More...

HASH_ITERATORiterator_
 Iterator used to expire timers. More...


Friends

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


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 <BUCKET>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 128 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::HASH_ITERATOR
 

Type of iterator.

Definition at line 133 of file Timer_Hash_T.h.

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

Type inherited from.

Definition at line 139 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. <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 200 of file Timer_Hash_T.cpp.

References ACE_NEW, ACE_TRACE, ACE_OS::gettimeofday, ACE_Timer_Queue_T::gettimeofday, iterator_, and table_.

00203   : ACE_Timer_Queue_T<TYPE, FUNCTOR, ACE_LOCK> (upcall_functor, freelist),
00204     size_ (0),
00205     table_size_ (table_size),
00206     table_functor_ (this),
00207     earliest_position_ (0)
00208 #if defined (ACE_WIN64)
00209   , pointer_base_ (0)
00210 #endif /* ACE_WIN64 */
00211 {
00212   ACE_TRACE ("ACE_Timer_Hash_T::ACE_Timer_Hash_T");
00213 
00214   ACE_NEW (table_,
00215            BUCKET *[table_size]);
00216 
00217   this->gettimeofday (ACE_OS::gettimeofday);
00218 
00219   for (size_t i = 0;
00220        i < table_size;
00221        i++)
00222     {
00223       ACE_NEW (this->table_[i],
00224                BUCKET (&this->table_functor_,
00225                        this->free_list_));
00226       this->table_[i]->gettimeofday (ACE_OS::gettimeofday);
00227     }
00228 
00229   ACE_NEW (iterator_,
00230            HASH_ITERATOR (*this));
00231 }

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

References ACE_DEFAULT_TIMER_HASH_TABLE_SIZE, ACE_NEW, ACE_TRACE, ACE_OS::gettimeofday, ACE_Timer_Queue_T::gettimeofday, iterator_, table_, and table_size_.

00237   : ACE_Timer_Queue_T<TYPE, FUNCTOR, ACE_LOCK> (upcall_functor, freelist),
00238     size_ (0),
00239     table_size_ (ACE_DEFAULT_TIMER_HASH_TABLE_SIZE),
00240     table_functor_ (this),
00241     earliest_position_ (0)
00242 #if defined (ACE_WIN64)
00243   , pointer_base_ (0)
00244 #endif /* ACE_WIN64 */
00245 {
00246   ACE_TRACE ("ACE_Timer_Hash_T::ACE_Timer_Hash_T");
00247 
00248   ACE_NEW (table_,
00249            BUCKET *[ACE_DEFAULT_TIMER_HASH_TABLE_SIZE]);
00250 
00251 
00252   this->gettimeofday (ACE_OS::gettimeofday);
00253 
00254   for (size_t i = 0;
00255        i < this->table_size_;
00256        i++)
00257     {
00258       ACE_NEW (this->table_[i],
00259                BUCKET (&this->table_functor_,
00260                        this->free_list_));
00261       this->table_[i]->gettimeofday (ACE_OS::gettimeofday);
00262     }
00263 
00264   ACE_NEW (iterator_,
00265            HASH_ITERATOR (*this));
00266 }

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

References ACE_GUARD, ACE_MT, ACE_TRACE, iterator_, table_, and table_size_.

00272 {
00273   ACE_TRACE ("ACE_Timer_Hash_T::~ACE_Timer_Hash_T");
00274   ACE_MT (ACE_GUARD (ACE_LOCK, ace_mon, this->mutex_));
00275 
00276   delete iterator_;
00277 
00278   for (size_t i = 0;
00279        i < this->table_size_;
00280        i++)
00281     delete this->table_[i];
00282 
00283   delete [] this->table_;
00284 }

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

Implements ACE_Timer_Queue_T.

Definition at line 431 of file Timer_Hash_T.cpp.

References ACE_GUARD_RETURN, ACE_MT, ACE_TRACE, Hash_Token::act_, earliest_position_, find_new_earliest, Hash_Token::orig_id_, Hash_Token::pos_, size_, and table_.

00434 {
00435   ACE_TRACE ("ACE_Timer_Hash_T::cancel");
00436   ACE_MT (ACE_GUARD_RETURN (ACE_LOCK, ace_mon, this->mutex_, -1));
00437 
00438   // Make sure we are getting a valid <timer_id>, not an error
00439   // returned by <schedule>.
00440   if (timer_id == -1)
00441     return 0;
00442 
00443 #if defined (ACE_WIN64)
00444   unsigned long timer_offset = ACE_static_cast (unsigned long, timer_id);
00445   Hash_Token *h = ACE_reinterpret_cast (Hash_Token *,
00446                                         (this->pointer_base_ + timer_offset));
00447 #else
00448   Hash_Token *h = ACE_reinterpret_cast (Hash_Token *,
00449                                         timer_id);
00450 #endif /* ACE_WIN64 */
00451 
00452   int result = this->table_[h->pos_]->cancel (h->orig_id_,
00453                                               act,
00454                                               dont_call);
00455 
00456   if (h->pos_ == this->earliest_position_)
00457     this->find_new_earliest ();
00458 
00459   if (act != 0)
00460     *act = h->act_;
00461 
00462   delete h;
00463 
00464   --this->size_;
00465 
00466   return result;
00467 }

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 <type>. If <dont_call> is 0 then the <functor> will be invoked. Returns number of timers cancelled.

Implements ACE_Timer_Queue_T.

Definition at line 472 of file Timer_Hash_T.cpp.

References ACE_GUARD_RETURN, ACE_MT, ACE_NEW_RETURN, ACE_TRACE, find_new_earliest, iter, Hash_Token::pos_, size_, table_, table_size_, and ACE_Timer_Queue_T::upcall_functor.

00474 {
00475   ACE_TRACE ("ACE_Timer_Hash_T::cancel");
00476 
00477   ACE_MT (ACE_GUARD_RETURN (ACE_LOCK, ace_mon, this->mutex_, -1));
00478 
00479   size_t i; // loop variable.
00480 
00481   Hash_Token **timer_ids;
00482 
00483   ACE_NEW_RETURN (timer_ids,
00484                   Hash_Token *[this->size_],
00485                   -1);
00486   size_t pos = 0;
00487 
00488   for (i = 0;
00489        i < this->table_size_;
00490        i++)
00491     {
00492       ACE_Timer_Queue_Iterator_T<TYPE,
00493                                  ACE_Timer_Hash_Upcall<TYPE, FUNCTOR, ACE_LOCK>,
00494                                  ACE_Null_Mutex> &iter =
00495         this->table_[i]->iter ();
00496 
00497       for (iter.first ();
00498            !iter.isdone ();
00499            iter.next ())
00500         if (iter.item ()->get_type () == type)
00501           timer_ids[pos++] =
00502             ACE_reinterpret_cast (Hash_Token *,
00503                                   ACE_const_cast (void *,
00504                                                   iter.item ()->get_act ()));
00505     }
00506 
00507   if (pos > this->size_)
00508     return -1;
00509 
00510   for (i = 0; i < pos; i++)
00511     {
00512       this->table_[timer_ids[i]->pos_]->cancel (timer_ids[i]->orig_id_,
00513                                                 0,
00514                                                 1);
00515       delete timer_ids[i];
00516       --this->size_;
00517     }
00518 
00519   delete [] timer_ids;
00520 
00521   if (dont_call == 0)
00522     this->upcall_functor ().cancellation (*this,
00523                                           type);
00524   this->find_new_earliest ();
00525 
00526   return ACE_static_cast (int, pos);
00527 }

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.

Definition at line 305 of file Timer_Hash_T.cpp.

References ACE_BEGIN_DUMP, ACE_DEBUG, ACE_END_DUMP, ACE_LIB_TEXT, ACE_TRACE, LM_DEBUG, table_, and table_size_.

00306 {
00307   ACE_TRACE ("ACE_Timer_Hash_T::dump");
00308   ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
00309   ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\ntable_size_ = %d"), this->table_size_));
00310   ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\nearliest_position_ = %d"), this->earliest_position_));
00311 
00312   for (size_t i = 0; i < this->table_size_; i++)
00313     if (!this->table_[i]->is_empty ())
00314       ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\nBucket %d contains nodes"), i));
00315 
00316   ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\n")));
00317   ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00318 }

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 <ACE_Timer_Hash>. Must be called on a non-empty queue.

Implements ACE_Timer_Queue_T.

Definition at line 298 of file Timer_Hash_T.cpp.

References ACE_TRACE, earliest_position_, and table_.

Referenced by find_new_earliest.

00299 {
00300   ACE_TRACE ("ACE_Timer_Hash_T::earliest_time");
00301   return this->table_[this->earliest_position_]->earliest_time ();
00302 }

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 <functor> for all timers whose values are <= <cur_time>. This does not account for <timer_skew>. Returns the number of timers canceled.

Reimplemented from ACE_Timer_Queue_T.

Definition at line 584 of file Timer_Hash_T.cpp.

References ACE_GUARD_RETURN, ACE_MT, ACE_TRACE, Hash_Token::act_, ACE_Timer_Node_T::get_act, ACE_Timer_Node_T::get_interval, ACE_Timer_Node_T::get_timer_id, ACE_Timer_Node_T::get_timer_value, ACE_Timer_Node_T::get_type, reschedule, ACE_Timer_Node_T::set_timer_value, size_, table_, table_size_, ACE_Timer_Queue_T::upcall, and ACE_Time_Value::zero.

00585 {
00586   ACE_TRACE ("ACE_Timer_Hash_T::expire");
00587   ACE_MT (ACE_GUARD_RETURN (ACE_LOCK, ace_mon, this->mutex_, -1));
00588 
00589   int number_of_timers_expired = 0;
00590 
00591   ACE_Timer_Node_T<TYPE> *expired;
00592 
00593   // Go through the table and expire anything that can be expired
00594 
00595   for (size_t i = 0;
00596        i < this->table_size_;
00597        i++)
00598     {
00599       while (!this->table_[i]->is_empty () 
00600              && this->table_[i]->earliest_time () <= cur_time)
00601         {
00602           expired = this->table_[i]->get_first ();
00603           TYPE type = expired->get_type ();
00604           const void *act = expired->get_act ();
00605           int reclaim = 1;
00606 
00607           // Check if this is an interval timer.
00608           if (expired->get_interval () > ACE_Time_Value::zero)
00609             {
00610               // Make sure that we skip past values that have already
00611               // "expired".
00612               do
00613                 expired->set_timer_value (expired->get_timer_value () 
00614                                           + expired->get_interval ());
00615               while (expired->get_timer_value () <= cur_time);
00616 
00617               // Since this is an interval timer, we need to
00618               // reschedule it.
00619               this->reschedule (expired);
00620               reclaim = 0;
00621             }
00622 
00623           // Now remove the timer from the original table... if
00624           // it's a simple, non-recurring timer, it's got to be
00625           // removed anyway. If it was rescheduled, it's been
00626           // scheduled into the correct table (regardless of whether
00627           // it's the same one or not) already.
00628           this->table_[i]->cancel (expired->get_timer_id ());
00629 
00630           Hash_Token *h = ACE_reinterpret_cast (Hash_Token *, 
00631                                                 ACE_const_cast (void *,
00632                                                                 act));
00633           // Call the functor.
00634           this->upcall (type,
00635                         h->act_,
00636                         cur_time);
00637           if (reclaim)
00638             {
00639               --this->size_;
00640               delete h;
00641             }
00642           number_of_timers_expired++;
00643         }
00644     }
00645 
00646   return number_of_timers_expired;
00647 }

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

Definition at line 576 of file Timer_Hash_T.cpp.

References ACE_Timer_Queue_T::expire.

00577 {
00578   return ACE_Timer_Queue_T<TYPE,FUNCTOR,ACE_LOCK>::expire();
00579 }

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

References earliest_position_, earliest_time, table_, table_size_, and ACE_Time_Value::zero.

Referenced by cancel, and remove_first.

00551 {
00552   for (size_t i = 0; i < this->table_size_; i++)
00553     if (!this->table_[i]->is_empty ())
00554       if (this->table_[this->earliest_position_]->is_empty ()
00555           || this->earliest_time () == ACE_Time_Value::zero
00556           || this->table_[i]->earliest_time () <= this->earliest_time ())
00557           this->earliest_position_ = i;
00558 }

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.

Definition at line 563 of file Timer_Hash_T.cpp.

References ACE_TRACE, earliest_position_, is_empty, and table_.

00564 {
00565   ACE_TRACE ("ACE_Timer_Hash_T::get_first");
00566 
00567   if (this->is_empty ())
00568     return 0;
00569 
00570   return this->table_[this->earliest_position_]->get_first ();
00571 }

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.

Definition at line 289 of file Timer_Hash_T.cpp.

References ACE_TRACE, earliest_position_, and table_.

Referenced by get_first, and remove_first.

00290 {
00291   ACE_TRACE ("ACE_Timer_Hash_T::is_empty");
00292   return this->table_[this->earliest_position_]->is_empty ();
00293 }

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.

Definition at line 191 of file Timer_Hash_T.cpp.

References ACE_Timer_Hash_Iterator_T::first, and iterator_.

Referenced by cancel.

00192 {
00193   this->iterator_->first ();
00194   return *this->iterator_;
00195 }

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.

Definition at line 532 of file Timer_Hash_T.cpp.

References earliest_position_, find_new_earliest, is_empty, size_, and table_.

00533 {
00534   if (this->is_empty ())
00535     return 0;
00536 
00537   ACE_Timer_Node_T<TYPE> *temp =
00538     this->table_[this->earliest_position_]->remove_first ();
00539 
00540   this->find_new_earliest ();
00541 
00542   --this->size_;
00543 
00544   return temp;
00545 }

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.

Definition at line 324 of file Timer_Hash_T.cpp.

References ACE_TRACE, earliest_position_, ACE_Timer_Node_T::get_act, ACE_Timer_Node_T::get_interval, ACE_Timer_Node_T::get_timer_value, ACE_Timer_Node_T::get_type, Hash_Token::orig_id_, ACE_Time_Value::sec, table_, and table_size_.

Referenced by expire.

00325 {
00326   ACE_TRACE ("ACE_Timer_Hash_T::reschedule");
00327 
00328   size_t position =
00329     expired->get_timer_value ().sec () % this->table_size_;
00330 
00331   Hash_Token *h = ACE_reinterpret_cast (Hash_Token *,
00332                                         ACE_const_cast (void *,
00333                                                         expired->get_act ()));
00334 
00335   h->orig_id_ = this->table_[position]->schedule (expired->get_type (),
00336                                                   h,
00337                                                   expired->get_timer_value (),
00338                                                   expired->get_interval ());
00339 
00340   if (this->table_[this->earliest_position_]->is_empty ()
00341       || this->table_[position]->earliest_time ()
00342       < this->table_[this->earliest_position_]->earliest_time ())
00343     this->earliest_position_ = position;
00344 }

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

Definition at line 402 of file Timer_Hash_T.cpp.

References ACE_GUARD_RETURN, ACE_MT, ACE_TRACE, Hash_Token::orig_id_, Hash_Token::pos_, and table_.

00404 {
00405   ACE_TRACE ("ACE_Timer_Hash_T::reset_interval");
00406   ACE_MT (ACE_GUARD_RETURN (ACE_LOCK, ace_mon, this->mutex_, -1));
00407 
00408   // Make sure we are getting a valid <timer_id>, not an error
00409   // returned by <schedule>.
00410   if (timer_id == -1)
00411     return -1;
00412 
00413 
00414 #if defined (ACE_WIN64)
00415   unsigned long timer_offset = ACE_static_cast (unsigned long, timer_id);
00416   Hash_Token *h = ACE_reinterpret_cast (Hash_Token *,
00417                                         (this->pointer_base_ + timer_offset));
00418 #else
00419   Hash_Token *h = ACE_reinterpret_cast (Hash_Token *,
00420                                         timer_id);
00421 #endif /* ACE_WIN64 */
00422 
00423   return this->table_[h->pos_]->reset_interval (h->orig_id_,
00424                                                 interval);
00425 }

template<class TYPE, class FUNCTOR, class ACE_LOCK, class BUCKET>
long ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::schedule const TYPE &    type,
const void *    act,
const ACE_Time_Value   future_time,
const ACE_Time_Value   interval = ACE_Time_Value::zero
[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.

Definition at line 350 of file Timer_Hash_T.cpp.

References ACE_GUARD_RETURN, ACE_MT, ACE_NEW_RETURN, ACE_TRACE, earliest_position_, Hash_Token::orig_id_, ACE_Time_Value::sec, size_, table_, and table_size_.

00354 {
00355   ACE_TRACE ("ACE_Timer_Hash_T::schedule");
00356   ACE_MT (ACE_GUARD_RETURN (ACE_LOCK, ace_mon, this->mutex_, -1));
00357 
00358   size_t position =
00359     future_time.sec () % this->table_size_;
00360 
00361   Hash_Token *h;
00362 
00363   ACE_NEW_RETURN (h,
00364                   Hash_Token (act,
00365                               position,
00366                               0),
00367                   -1);
00368 
00369   h->orig_id_ = this->table_[position]->schedule (type,
00370                                                   h,
00371                                                   future_time,
00372                                                   interval);
00373 
00374   if (this->table_[this->earliest_position_]->is_empty ()
00375       || this->table_[position]->earliest_time ()
00376       < this->table_[this->earliest_position_]->earliest_time ())
00377     this->earliest_position_ = position;
00378 
00379   ++this->size_;
00380 
00381 #if defined (ACE_WIN64)
00382   // This is a Win64 hack, necessary because of the original (bad) decision
00383   // to use a pointer as the timer ID. This class doesn't follow the usual
00384   // timer expiration rules (see comments in header file) and is probably
00385   // not used much. The dynamic allocation of Hash_Tokens without
00386   // recording them anywhere is a large problem for Win64 since the
00387   // size of a pointer is 64 bits, but a long is 32. Since this class
00388   // is not much used, I'm hacking this, at least for now. If it becomes
00389   // an issue, I'll look at it again then.
00390   ptrdiff_t hi = ACE_reinterpret_cast (ptrdiff_t, h);
00391   if (this->pointer_base_ == 0)
00392     this->pointer_base_ = hi & 0xffffffff00000000;
00393   return ACE_reinterpret_cast (long, hi & 0xffffffff);
00394 #else
00395   return ACE_reinterpret_cast (long, h);
00396 #endif
00397 }


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 136 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::earliest_position_ [private]
 

Index to the position with the earliest entry.

Definition at line 264 of file Timer_Hash_T.h.

Referenced by cancel, earliest_time, find_new_earliest, get_first, is_empty, remove_first, reschedule, and schedule.

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

Iterator used to expire timers.

Definition at line 267 of file Timer_Hash_T.h.

Referenced by ACE_Timer_Hash_T, iter, and ~ACE_Timer_Hash_T.

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

Keeps track of the size of the queue.

Definition at line 252 of file Timer_Hash_T.h.

Referenced by cancel, expire, remove_first, and schedule.

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

Table of BUCKETS.

Definition at line 255 of file Timer_Hash_T.h.

Referenced by ACE_Timer_Hash_T, cancel, dump, earliest_time, expire, find_new_earliest, get_first, is_empty, remove_first, reschedule, reset_interval, schedule, and ~ACE_Timer_Hash_T.

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

Functor used for the table's timer queues.

Definition at line 261 of file Timer_Hash_T.h.

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

Keeps track of the size of table_.

Definition at line 258 of file Timer_Hash_T.h.

Referenced by ACE_Timer_Hash_T, cancel, dump, expire, find_new_earliest, reschedule, schedule, and ~ACE_Timer_Hash_T.


The documentation for this class was generated from the following files:
Generated on Mon Jun 16 12:57:55 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002