Provides a hash table of BUCKETs as an implementation for a timer queue. More...
#include <Timer_Hash_T.h>
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. |
Provides a hash table of BUCKETs 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 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 |
Type of iterator.
Definition at line 167 of file Timer_Hash_T.h.
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 173 of file Timer_Hash_T.h.
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.
: ACE_Timer_Queue_T<TYPE, FUNCTOR, ACE_LOCK> (upcall_functor, freelist), size_ (0), table_size_ (table_size), table_functor_ (this), earliest_position_ (0) #if defined (ACE_WIN64) , pointer_base_ (0) #endif /* ACE_WIN64 */ , token_list_ () { ACE_TRACE ("ACE_Timer_Hash_T::ACE_Timer_Hash_T"); ACE_NEW (table_, BUCKET *[table_size]); this->gettimeofday (ACE_OS::gettimeofday); for (size_t i = 0; i < table_size; ++i) { ACE_NEW (this->table_[i], BUCKET (&this->table_functor_, this->free_list_)); this->table_[i]->gettimeofday (ACE_OS::gettimeofday); } ACE_NEW (iterator_, HASH_ITERATOR (*this)); }
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.
: ACE_Timer_Queue_T<TYPE, FUNCTOR, ACE_LOCK> (upcall_functor, freelist), size_ (0), table_size_ (ACE_DEFAULT_TIMER_HASH_TABLE_SIZE), table_functor_ (this), earliest_position_ (0) #if defined (ACE_WIN64) , pointer_base_ (0) #endif /* ACE_WIN64 */ , token_list_ () { ACE_TRACE ("ACE_Timer_Hash_T::ACE_Timer_Hash_T"); ACE_NEW (table_, BUCKET *[ACE_DEFAULT_TIMER_HASH_TABLE_SIZE]); this->gettimeofday (ACE_OS::gettimeofday); for (size_t i = 0; i < this->table_size_; ++i) { ACE_NEW (this->table_[i], BUCKET (&this->table_functor_, this->free_list_)); this->table_[i]->gettimeofday (ACE_OS::gettimeofday); } ACE_NEW (iterator_, HASH_ITERATOR (*this)); }
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.
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 | ( | 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.
{ ACE_TRACE ("ACE_Timer_Hash_T::cancel"); size_t i; // loop variable. Hash_Token<TYPE> **timer_ids = 0; size_t pos = 0; ACE_MT (ACE_GUARD_RETURN (ACE_LOCK, ace_mon, this->mutex_, -1)); ACE_NEW_RETURN (timer_ids, Hash_Token<TYPE> *[this->size_], -1); for (i = 0; i < this->table_size_; ++i) { ACE_Timer_Queue_Iterator_T<TYPE, ACE_Timer_Hash_Upcall<TYPE, FUNCTOR, ACE_LOCK>, ACE_Null_Mutex> &iter = this->table_[i]->iter (); for (iter.first (); !iter.isdone (); iter.next ()) if (iter.item ()->get_type () == type) timer_ids[pos++] = reinterpret_cast<Hash_Token<TYPE> *> ( const_cast<void *> (iter.item ()->get_act ())); } if (pos > this->size_) return -1; for (i = 0; i < pos; ++i) { int const result = this->table_[timer_ids[i]->pos_]->cancel (timer_ids[i]->orig_id_, 0, dont_call); ACE_ASSERT (result == 1); ACE_UNUSED_ARG (result); // We could destruct Hash_Token explicitly but we better // schedule it for destruction. this->token_list_.add (timer_ids[i]); --this->size_; } delete [] timer_ids; this->find_new_earliest (); // Call the close hooks. int cookie = 0; // cancel_type() called once per <type>. this->upcall_functor ().cancel_type (*this, type, dont_call, cookie); for (i = 0; i < pos; ++i) { // cancel_timer() called once per <timer>. this->upcall_functor ().cancel_timer (*this, type, dont_call, cookie); } return static_cast<int> (pos); }
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.
{ ACE_TRACE ("ACE_Timer_Hash_T::cancel"); // Make sure we are getting a valid <timer_id>, not an error // returned by <schedule>. if (timer_id == -1) return 0; #if defined (ACE_WIN64) unsigned long const timer_offset = static_cast<unsigned long> (timer_id); ACE_MT (ACE_GUARD_RETURN (ACE_LOCK, ace_mon, this->mutex_, -1)); Hash_Token<TYPE> * const h = reinterpret_cast<Hash_Token<TYPE> *> (this->pointer_base_ + timer_offset); #else Hash_Token<TYPE> * const h = reinterpret_cast<Hash_Token<TYPE> *> (timer_id); // Grab the lock before accessing the table. We don't need to do so // before this point since no members are accessed until now. ACE_MT (ACE_GUARD_RETURN (ACE_LOCK, ace_mon, this->mutex_, -1)); #endif /* ACE_WIN64 */ int const result = this->table_[h->pos_]->cancel (h->orig_id_, 0, dont_call); if (result == 1) { // Call the close hooks. int cookie = 0; // cancel_type() called once per <type>. this->upcall_functor ().cancel_type (*this, h->type_, dont_call, cookie); // cancel_timer() called once per <timer>. this->upcall_functor ().cancel_timer (*this, h->type_, dont_call, cookie); if (h->pos_ == this->earliest_position_) this->find_new_earliest (); if (act != 0) *act = h->act_; // We could destruct Hash_Token explicitly but we better // schedule it for destruction. In this case next // token_list_.remove () will use it. this->token_list_.add (h); --this->size_; } return result; }
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.
{ int const result = ACE_Timer_Queue_T<TYPE,FUNCTOR,ACE_LOCK>::dispatch_info_i (cur_time, info); if (result == 1) { Hash_Token<TYPE> *h = reinterpret_cast<Hash_Token<TYPE> *> (const_cast<void *> (info.act_)); info.act_ = h->act_; } return result; }
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.
{ #if defined (ACE_HAS_DUMP) ACE_TRACE ("ACE_Timer_Hash_T::dump"); ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this)); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\ntable_size_ = %d"), this->table_size_)); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\nearliest_position_ = %d"), this->earliest_position_)); for (size_t i = 0; i < this->table_size_; ++i) if (!this->table_[i]->is_empty ()) ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\nBucket %d contains nodes"), i)); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\n"))); ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP)); #endif /* ACE_HAS_DUMP */ }
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.
{ ACE_TRACE ("ACE_Timer_Hash_T::earliest_time"); return this->table_[this->earliest_position_]->earliest_time (); }
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.
{ return ACE_Timer_Queue_T<TYPE,FUNCTOR,ACE_LOCK>::expire(); }
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.
{ ACE_TRACE ("ACE_Timer_Hash_T::expire"); int number_of_timers_expired = 0; ACE_Timer_Node_T<TYPE> *expired = 0; ACE_MT (ACE_GUARD_RETURN (ACE_LOCK, ace_mon, this->mutex_, -1)); // Go through the table and expire anything that can be expired for (size_t i = 0; i < this->table_size_; ++i) { while (!this->table_[i]->is_empty () && this->table_[i]->earliest_time () <= cur_time) { expired = this->table_[i]->remove_first (); const void *act = expired->get_act (); bool reclaim = true; Hash_Token<TYPE> *h = reinterpret_cast<Hash_Token<TYPE> *> (const_cast<void *> (act)); ACE_ASSERT (h->pos_ == i); #if 0 ACE_DEBUG ((LM_DEBUG, "Hash::expire() expiring %d in slot %d where it's id is %d and token is %x\n", expired->get_timer_value ().msec (), h->pos_, h->orig_id_, h)); #endif // Check if this is an interval timer. if (expired->get_interval () > ACE_Time_Value::zero) { // Make sure that we skip past values that have already // "expired". this->recompute_next_abs_interval_time (expired, cur_time); // Since this is an interval timer, we need to // reschedule it. this->reschedule (expired); reclaim = false; } else { this->free_node (expired); } ACE_Timer_Node_Dispatch_Info_T<TYPE> info; // Get the dispatch info expired->get_dispatch_info (info); info.act_ = h->act_; const void *upcall_act = 0; this->preinvoke (info, cur_time, upcall_act); this->upcall (info, cur_time); this->postinvoke (info, cur_time, upcall_act); if (reclaim) { --this->size_; } ++number_of_timers_expired; } } if (number_of_timers_expired > 0) this->find_new_earliest (); return number_of_timers_expired; }
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.
{ for (size_t i = 0; i < this->table_size_; ++i) if (!this->table_[i]->is_empty ()) if (this->table_[this->earliest_position_]->is_empty () || this->earliest_time () == ACE_Time_Value::zero || this->table_[i]->earliest_time () <= this->earliest_time ()) this->earliest_position_ = i; }
void ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::free_node | ( | ACE_Timer_Node_T< TYPE > * | node | ) | [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.
{ ACE_Timer_Queue_T<TYPE,FUNCTOR,ACE_LOCK>::free_node (node); Hash_Token<TYPE> *h = reinterpret_cast<Hash_Token<TYPE> *> (const_cast<void *> (node->get_act ())); this->token_list_.add (h); }
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.
{ ACE_TRACE ("ACE_Timer_Hash_T::get_first"); if (this->is_empty ()) return 0; return this->table_[this->earliest_position_]->get_first (); }
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.
{ ACE_TRACE ("ACE_Timer_Hash_T::is_empty"); return this->table_[this->earliest_position_]->is_empty (); }
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.
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.
{ if (this->is_empty ()) return 0; ACE_Timer_Node_T<TYPE> *temp = this->table_[this->earliest_position_]->remove_first (); this->find_new_earliest (); --this->size_; return temp; }
void ACE_Timer_Hash_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET >::reschedule | ( | ACE_Timer_Node_T< TYPE > * | expired | ) | [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.
{ ACE_TRACE ("ACE_Timer_Hash_T::reschedule"); Hash_Token<TYPE> *h = reinterpret_cast<Hash_Token<TYPE> *> ( const_cast<void *> (expired->get_act ())); // Don't use ACE_Utils::truncate_cast<> here. A straight // static_cast<> will provide more unique results when the number // of seconds is greater than std::numeric_limits<size_t>::max(). size_t const secs_hash_input = static_cast<size_t> (expired->get_timer_value ().sec ()); h->pos_ = secs_hash_input % this->table_size_; h->orig_id_ = this->table_[h->pos_]->schedule (expired->get_type (), h, expired->get_timer_value (), expired->get_interval ()); ACE_ASSERT (h->orig_id_ != -1); #if 0 ACE_DEBUG ((LM_DEBUG, "Hash::reschedule() resets %d in slot %d where it's id is %d and token is %x\n", expired->get_timer_value ().msec (), h->pos_, h->orig_id_, h)); #endif // Since schedule() above will allocate a new node // then here schedule <expired> for deletion. Don't call // this->free_node() because that will invalidate <h> // and that's what user have as timer_id. ACE_Timer_Queue_T<TYPE,FUNCTOR,ACE_LOCK>::free_node (expired); if (this->table_[this->earliest_position_]->is_empty () || this->table_[h->pos_]->earliest_time () < this->table_[this->earliest_position_]->earliest_time ()) this->earliest_position_ = h->pos_; }
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.
{ ACE_TRACE ("ACE_Timer_Hash_T::reset_interval"); // Make sure we are getting a valid <timer_id>, not an error // returned by <schedule>. if (timer_id == -1) return -1; #if defined (ACE_WIN64) unsigned long const timer_offset = static_cast<unsigned long> (timer_id); ACE_MT (ACE_GUARD_RETURN (ACE_LOCK, ace_mon, this->mutex_, -1)); Hash_Token<TYPE> * const h = reinterpret_cast<Hash_Token<TYPE> *> (this->pointer_base_ + timer_offset); #else Hash_Token<TYPE> * const h = reinterpret_cast<Hash_Token<TYPE> *> (timer_id); // Grab the lock before accessing the table. We don't need to do so // before this point since no members are accessed until now. ACE_MT (ACE_GUARD_RETURN (ACE_LOCK, ace_mon, this->mutex_, -1)); #endif /* ACE_WIN64 */ return this->table_[h->pos_]->reset_interval (h->orig_id_, interval); }
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.
{ ACE_TRACE ("ACE_Timer_Hash_T::schedule_i"); // Don't use ACE_Utils::truncate_cast<> here. A straight // static_cast<> will provide more unique results when the number // of seconds is greater than std::numeric_limits<size_t>::max(). size_t const secs_hash_input = static_cast<size_t> (future_time.sec ()); size_t const position = secs_hash_input % this->table_size_; // Don't create Hash_Token directly. Instead we get one from Free_List // and then set it properly. Hash_Token<TYPE> *h = this->token_list_.remove (); h->set (act, position, 0, type); h->orig_id_ = this->table_[position]->schedule (type, h, future_time, interval); ACE_ASSERT (h->orig_id_ != -1); #if 0 ACE_DEBUG ((LM_DEBUG, "Hash::schedule() placing %d in slot %d where it's id is %d and token is %x\n", future_time.msec (), position, h->orig_id_, h)); #endif if (this->table_[this->earliest_position_]->is_empty () || this->table_[position]->earliest_time () < this->table_[this->earliest_position_]->earliest_time ()) this->earliest_position_ = position; ++this->size_; #if defined (ACE_WIN64) // This is a Win64 hack, necessary because of the original (bad) decision // to use a pointer as the timer ID. This class doesn't follow the usual // timer expiration rules (see comments in header file) and is probably // not used much. The dynamic allocation of Hash_Tokens without // recording them anywhere is a large problem for Win64 since the // size of a pointer is 64 bits, but a long is 32. Since this class // is not much used, I'm hacking this, at least for now. If it becomes // an issue, I'll look at it again then. intptr_t hi = reinterpret_cast<intptr_t> (h); if (this->pointer_base_ == 0) this->pointer_base_ = hi & 0xffffffff00000000; return static_cast<long> (hi & 0xffffffff); #else return reinterpret_cast<long> (h); #endif }
friend class ACE_Timer_Hash_Iterator_T< TYPE, FUNCTOR, ACE_LOCK, BUCKET > [friend] |
Iterator is a friend.
Definition at line 170 of file Timer_Hash_T.h.
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.
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.
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.
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.
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 308 of file Timer_Hash_T.h.
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.
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.