summaryrefslogtreecommitdiff
path: root/ace/Timer_Wheel_T.cpp
diff options
context:
space:
mode:
authorirfan <irfan@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1997-05-06 01:14:18 +0000
committerirfan <irfan@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1997-05-06 01:14:18 +0000
commite03e2e91bcd629d3386ea1059a1a893d976dd4e6 (patch)
tree530cecb99e4c89e016a84d14b666f60059f53cb1 /ace/Timer_Wheel_T.cpp
parent385f921ff545baca5e95604326344d0584808ebd (diff)
downloadATCD-e03e2e91bcd629d3386ea1059a1a893d976dd4e6.tar.gz
*** empty log message ***
Diffstat (limited to 'ace/Timer_Wheel_T.cpp')
-rw-r--r--ace/Timer_Wheel_T.cpp344
1 files changed, 170 insertions, 174 deletions
diff --git a/ace/Timer_Wheel_T.cpp b/ace/Timer_Wheel_T.cpp
index a50d534dbf3..61129ada571 100644
--- a/ace/Timer_Wheel_T.cpp
+++ b/ace/Timer_Wheel_T.cpp
@@ -5,29 +5,29 @@
#include "ace/Timer_Wheel_T.h"
-template <class TYPE, class FUNCTOR>
-ACE_Timer_Wheel_Iterator_T<TYPE, FUNCTOR>::ACE_Timer_Wheel_Iterator_T (ACE_Timer_Wheel_T<TYPE, FUNCTOR> &wheel)
+template <class TYPE, class FUNCTOR, class LOCK>
+ACE_Timer_Wheel_Iterator_T<TYPE, FUNCTOR, LOCK>::ACE_Timer_Wheel_Iterator_T (ACE_Timer_Wheel_T<TYPE, FUNCTOR, LOCK> &wheel)
: timer_wheel_ (wheel)
{
}
-template <class TYPE, class FUNCTOR> int
-ACE_Timer_Wheel_Iterator_T<TYPE, FUNCTOR>::next (ACE_Timer_Node_T<TYPE, FUNCTOR> *&node,
- const ACE_Time_Value &cur_time)
+template <class TYPE, class FUNCTOR, class LOCK> int
+ACE_Timer_Wheel_Iterator_T<TYPE, FUNCTOR, LOCK>::next (ACE_Timer_Node_T<TYPE, FUNCTOR, LOCK> *&node,
+ const ACE_Time_Value &cur_time)
{
if (this->timer_wheel_.wheel_[this->pos_]->next_ == this->timer_wheel_.wheel_[this->pos_]
- || this->timer_wheel_.wheel_[this->pos_]->next_->timer_value_ > this->time_)
- {
- ACE_Time_Value et = this->timer_wheel_.earliest_time ();
+ || this->timer_wheel_.wheel_[this->pos_]->next_->timer_value_ > this->time_)
+ {
+ ACE_Time_Value et = this->timer_wheel_.earliest_time ();
- if (this->timer_wheel_.size_ == 0 || et > cur_time)
- return 0;
+ if (this->timer_wheel_.size_ == 0 || et > cur_time)
+ return 0;
- this->pos_ = (et.usec () / this->timer_wheel_.resolution_)
- % this->timer_wheel_.wheel_size_;
- this->time_ = ACE_Time_Value (et.sec (),
- this->pos_ * this->timer_wheel_.resolution_);
- }
+ this->pos_ = (et.usec () / this->timer_wheel_.resolution_)
+ % this->timer_wheel_.wheel_size_;
+ this->time_ = ACE_Time_Value (et.sec (),
+ this->pos_ * this->timer_wheel_.resolution_);
+ }
// Remove the earliest item
@@ -38,8 +38,8 @@ ACE_Timer_Wheel_Iterator_T<TYPE, FUNCTOR>::next (ACE_Timer_Node_T<TYPE, FUNCTOR>
return 1;
}
-template <class TYPE, class FUNCTOR> void
-ACE_Timer_Wheel_Iterator_T<TYPE, FUNCTOR>::reset (void)
+template <class TYPE, class FUNCTOR, class LOCK> void
+ACE_Timer_Wheel_Iterator_T<TYPE, FUNCTOR, LOCK>::reset (void)
{
ACE_Time_Value et = this->timer_wheel_.earliest_time ();
@@ -51,11 +51,11 @@ ACE_Timer_Wheel_Iterator_T<TYPE, FUNCTOR>::reset (void)
ACE_ALLOC_HOOK_DEFINE(ACE_Timer_Wheel_T)
-template <class TYPE, class FUNCTOR>
-ACE_Timer_Wheel_T<TYPE, FUNCTOR>::ACE_Timer_Wheel_T (size_t wheelsize,
- size_t resolution,
- size_t prealloc,
- FUNCTOR *upcall_functor)
+ template <class TYPE, class FUNCTOR, class LOCK>
+ACE_Timer_Wheel_T<TYPE, FUNCTOR, LOCK>::ACE_Timer_Wheel_T (size_t wheelsize,
+ size_t resolution,
+ size_t prealloc,
+ FUNCTOR *upcall_functor)
: INHERITED (upcall_functor),
wheel_size_ (wheelsize),
resolution_ (resolution),
@@ -69,60 +69,60 @@ ACE_Timer_Wheel_T<TYPE, FUNCTOR>::ACE_Timer_Wheel_T (size_t wheelsize,
size_t i;
// Create the timing wheel
- ACE_NEW (this->wheel_, (ACE_Timer_Node_T<TYPE, FUNCTOR> *[wheelsize]));
+ ACE_NEW (this->wheel_, (ACE_Timer_Node_T<TYPE, FUNCTOR, LOCK> *[wheelsize]));
for (i = 0; i < wheelsize; i++)
- {
- // Create the dummy nodes
- ACE_Timer_Node_T<TYPE, FUNCTOR> *tempnode = this->alloc_node ();
- tempnode->next_ = tempnode->prev_ = tempnode;
- this->wheel_[i] = tempnode;
- }
+ {
+ // Create the dummy nodes
+ ACE_Timer_Node_T<TYPE, FUNCTOR, LOCK> *tempnode = this->alloc_node ();
+ tempnode->next_ = tempnode->prev_ = tempnode;
+ this->wheel_[i] = tempnode;
+ }
// Do the preallocation
for (i = 0; i < prealloc; i++)
- {
- ACE_Timer_Node_T<TYPE, FUNCTOR> *temp;
- ACE_NEW (temp, (ACE_Timer_Node_T<TYPE, FUNCTOR>));
- temp->next_ = this->freelist_;
- this->freelist_ = temp;
- }
+ {
+ ACE_Timer_Node_T<TYPE, FUNCTOR, LOCK> *temp;
+ ACE_NEW (temp, (ACE_Timer_Node_T<TYPE, FUNCTOR, LOCK>));
+ temp->next_ = this->freelist_;
+ this->freelist_ = temp;
+ }
}
-template <class TYPE, class FUNCTOR>
-ACE_Timer_Wheel_T<TYPE, FUNCTOR>::~ACE_Timer_Wheel_T (void)
+template <class TYPE, class FUNCTOR, class LOCK>
+ACE_Timer_Wheel_T<TYPE, FUNCTOR, LOCK>::~ACE_Timer_Wheel_T (void)
{
ACE_TRACE ("ACE_Timer_Wheel_T::~ACE_Timer_Wheel_T");
for (size_t i = 0; i < this->wheel_size_; i++)
- {
- // delete nodes until only the dummy node is left
- while (this->wheel_[i]->next_ != this->wheel_[i])
{
- ACE_Timer_Node_T<TYPE, FUNCTOR> *next = this->wheel_[i]->next_;
- this->wheel_[i]->next_ = next->next_;
- next->next_->prev_ = this->wheel_[i];
- this->free_node (next);
+ // delete nodes until only the dummy node is left
+ while (this->wheel_[i]->next_ != this->wheel_[i])
+ {
+ ACE_Timer_Node_T<TYPE, FUNCTOR, LOCK> *next = this->wheel_[i]->next_;
+ this->wheel_[i]->next_ = next->next_;
+ next->next_->prev_ = this->wheel_[i];
+ this->free_node (next);
+ }
+
+ // and now delete the dummy node
+ delete this->wheel_[i];
}
- // and now delete the dummy node
- delete this->wheel_[i];
- }
-
// Get rid of the freelist now
while (this->freelist_ != NULL)
- {
- ACE_Timer_Node_T<TYPE, FUNCTOR> *temp = this->freelist_;
- this->freelist_ = temp->next_;
- delete temp;
- }
+ {
+ ACE_Timer_Node_T<TYPE, FUNCTOR, LOCK> *temp = this->freelist_;
+ this->freelist_ = temp->next_;
+ delete temp;
+ }
delete [] this->wheel_;
}
-template <class TYPE, class FUNCTOR> int
-ACE_Timer_Wheel_T<TYPE, FUNCTOR>::is_empty (void) const
+template <class TYPE, class FUNCTOR, class LOCK> int
+ACE_Timer_Wheel_T<TYPE, FUNCTOR, LOCK>::is_empty (void) const
{
ACE_TRACE ("ACE_Timer_Wheel_T::is_empty");
@@ -130,8 +130,8 @@ ACE_Timer_Wheel_T<TYPE, FUNCTOR>::is_empty (void) const
return this->size_ == 0;
}
-template <class TYPE, class FUNCTOR> const ACE_Time_Value &
-ACE_Timer_Wheel_T<TYPE, FUNCTOR>::earliest_time (void) const
+template <class TYPE, class FUNCTOR, class LOCK> const ACE_Time_Value &
+ACE_Timer_Wheel_T<TYPE, FUNCTOR, LOCK>::earliest_time (void) const
{
ACE_TRACE ("ACE_Timer_Wheel_T::earliest_time");
@@ -140,47 +140,47 @@ ACE_Timer_Wheel_T<TYPE, FUNCTOR>::earliest_time (void) const
// Check every entry in the table
for (size_t i = 0; i < this->wheel_size_; i++)
- {
- // Check for an empty entry
- if (this->wheel_[i]->next_ != this->wheel_[i])
{
- // if initialization or if the time is earlier
- if (earliest_time == ACE_Time_Value::zero
- || this->wheel_[i]->timer_value_ < earliest_time)
- {
- earliest_time = this->wheel_[i]->next_->timer_value_;
- earliest_pos = i;
- }
+ // Check for an empty entry
+ if (this->wheel_[i]->next_ != this->wheel_[i])
+ {
+ // if initialization or if the time is earlier
+ if (earliest_time == ACE_Time_Value::zero
+ || this->wheel_[i]->timer_value_ < earliest_time)
+ {
+ earliest_time = this->wheel_[i]->next_->timer_value_;
+ earliest_pos = i;
+ }
+ }
}
- }
return this->wheel_[earliest_pos]->next_->timer_value_;
}
-template <class TYPE, class FUNCTOR> long
-ACE_Timer_Wheel_T<TYPE, FUNCTOR>::schedule (const TYPE &type,
- const void *act,
- const ACE_Time_Value &delay,
- const ACE_Time_Value &interval)
+template <class TYPE, class FUNCTOR, class LOCK> long
+ACE_Timer_Wheel_T<TYPE, FUNCTOR, LOCK>::schedule (const TYPE &type,
+ const void *act,
+ const ACE_Time_Value &delay,
+ const ACE_Time_Value &interval)
{
ACE_TRACE ("ACE_Timer_Wheel_T::schedule");
- ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon, this->lock_, -1));
+ ACE_MT (ACE_GUARD_RETURN (LOCK, ace_mon, this->lock_, -1));
- ACE_Timer_Node_T<TYPE, FUNCTOR> *tempnode = this->alloc_node ();
+ ACE_Timer_Node_T<TYPE, FUNCTOR, LOCK> *tempnode = this->alloc_node ();
if (tempnode)
{
// Note that the timer_id is actually the pointer to the node
// Use operator placement new.
- new (tempnode) ACE_Timer_Node_T<TYPE, FUNCTOR> (type,
- act,
- delay,
- interval,
- NULL,
- NULL,
- (long) tempnode);
+ new (tempnode) ACE_Timer_Node_T<TYPE, FUNCTOR, LOCK> (type,
+ act,
+ delay,
+ interval,
+ NULL,
+ NULL,
+ (long) tempnode);
this->reschedule (tempnode);
return tempnode->timer_id_;
@@ -191,86 +191,82 @@ ACE_Timer_Wheel_T<TYPE, FUNCTOR>::schedule (const TYPE &type,
return -1;
}
-template <class TYPE, class FUNCTOR> int
-ACE_Timer_Wheel_T<TYPE, FUNCTOR>::cancel (const TYPE &type,
- int dont_call_handle_close)
+template <class TYPE, class FUNCTOR, class LOCK> int
+ACE_Timer_Wheel_T<TYPE, FUNCTOR, LOCK>::cancel (const TYPE &type,
+ int dont_call_handle_close)
{
ACE_TRACE ("ACE_Timer_Wheel_T::cancel");
- ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon, this->lock_, -1));
+ ACE_MT (ACE_GUARD_RETURN (LOCK, ace_mon, this->lock_, -1));
int number_of_cancellations = 0;
for (size_t i = 0; i < this->wheel_size_; i++)
- {
- ACE_Timer_Node_T<TYPE, FUNCTOR> *curr = this->wheel_[i]->next_;
-
- while (curr != this->wheel_[i])
{
- if (curr->type_ == type)
- {
- number_of_cancellations++;
-
- if (dont_call_handle_close == 0
- && number_of_cancellations == 1)
- // This calls the correct operator () on the functor (the one with
- // two args)
- this->upcall_functor_.operator () (*this, curr->type_);
-
- ACE_Timer_Node_T<TYPE, FUNCTOR> *tempnode = curr;
- curr->prev_->next_ = curr->next_;
- curr->next_->prev_ = curr->prev_;
- curr = curr->next_;
-
- this->free_node (tempnode);
- }
- else
- {
- curr = curr->next_;
- }
+ ACE_Timer_Node_T<TYPE, FUNCTOR, LOCK> *curr = this->wheel_[i]->next_;
+
+ while (curr != this->wheel_[i])
+ {
+ if (curr->type_ == type)
+ {
+ number_of_cancellations++;
+
+ if (dont_call_handle_close == 0
+ && number_of_cancellations == 1)
+ this->upcall_functor_.cancellation (*this, curr->type_);
+
+ ACE_Timer_Node_T<TYPE, FUNCTOR, LOCK> *tempnode = curr;
+ curr->prev_->next_ = curr->next_;
+ curr->next_->prev_ = curr->prev_;
+ curr = curr->next_;
+
+ this->free_node (tempnode);
+ }
+ else
+ {
+ curr = curr->next_;
+ }
+ }
}
- }
this->size_ -= number_of_cancellations;
return number_of_cancellations;
}
-template <class TYPE, class FUNCTOR> int
-ACE_Timer_Wheel_T<TYPE, FUNCTOR>::cancel (long timer_id,
- const void **act,
- int dont_call_handle_close)
+template <class TYPE, class FUNCTOR, class LOCK> int
+ACE_Timer_Wheel_T<TYPE, FUNCTOR, LOCK>::cancel (long timer_id,
+ const void **act,
+ int dont_call_handle_close)
{
ACE_TRACE ("ACE_Timer_Wheel_T::cancel");
- ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon, this->lock_, -1));
+ ACE_MT (ACE_GUARD_RETURN (LOCK, ace_mon, this->lock_, -1));
- ACE_Timer_Node_T<TYPE, FUNCTOR> *node = (ACE_Timer_Node_T<TYPE, FUNCTOR> *) timer_id;
+ ACE_Timer_Node_T<TYPE, FUNCTOR, LOCK> *node = (ACE_Timer_Node_T<TYPE, FUNCTOR, LOCK> *) timer_id;
ACE_ASSERT (timer_id == node->timer_id_);
- // Check to see if the node looks like a true ACE_Timer_Node_T<TYPE, FUNCTOR>
+ // Check to see if the node looks like a true ACE_Timer_Node_T<TYPE, FUNCTOR, LOCK>
if (timer_id == node->timer_id_)
- {
- node->next_->prev_ = node->prev_;
- node->prev_->next_ = node->next_;
+ {
+ node->next_->prev_ = node->prev_;
+ node->prev_->next_ = node->next_;
- if (act != 0)
- *act = node->act_;
+ if (act != 0)
+ *act = node->act_;
- if (dont_call_handle_close == 0)
- // This calls the correct operator () on the functor (the one with
- // two args)
- this->upcall_functor_.operator () (*this, node->type_);
+ if (dont_call_handle_close == 0)
+ this->upcall_functor_.cancellation (*this, node->type_);
- this->free_node (node);
- this->size_--;
- return 1;
- }
+ this->free_node (node);
+ this->size_--;
+ return 1;
+ }
// Didn't find it if we are here
return 0;
}
-template <class TYPE, class FUNCTOR> void
-ACE_Timer_Wheel_T<TYPE, FUNCTOR>::dump (void) const
+template <class TYPE, class FUNCTOR, class LOCK> void
+ACE_Timer_Wheel_T<TYPE, FUNCTOR, LOCK>::dump (void) const
{
ACE_TRACE ("ACE_Timer_Wheel_T::dump");
ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
@@ -282,41 +278,41 @@ ACE_Timer_Wheel_T<TYPE, FUNCTOR>::dump (void) const
ACE_DEBUG ((LM_DEBUG, "\nwheel_ = \n"));
for (size_t i = 0; i < this->wheel_size_; i++)
- {
- ACE_DEBUG ((LM_DEBUG, "%d\n", i));
- ACE_Timer_Node_T<TYPE, FUNCTOR> *temp = this->wheel_[i]->next_;
- while (temp != this->wheel_[i])
{
- temp->dump ();
- temp = temp->next_;
+ ACE_DEBUG ((LM_DEBUG, "%d\n", i));
+ ACE_Timer_Node_T<TYPE, FUNCTOR, LOCK> *temp = this->wheel_[i]->next_;
+ while (temp != this->wheel_[i])
+ {
+ temp->dump ();
+ temp = temp->next_;
+ }
}
- }
ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
}
-template <class TYPE, class FUNCTOR> ACE_Timer_Node_T<TYPE, FUNCTOR> *
-ACE_Timer_Wheel_T<TYPE, FUNCTOR>::alloc_node (void)
+template <class TYPE, class FUNCTOR, class LOCK> ACE_Timer_Node_T<TYPE, FUNCTOR, LOCK> *
+ACE_Timer_Wheel_T<TYPE, FUNCTOR, LOCK>::alloc_node (void)
{
- ACE_Timer_Node_T<TYPE, FUNCTOR> *temp;
+ ACE_Timer_Node_T<TYPE, FUNCTOR, LOCK> *temp;
if (this->freelist_ == NULL)
- {
- ACE_NEW_RETURN (temp,
- (ACE_Timer_Node_T<TYPE, FUNCTOR>),
- 0);
- }
+ {
+ ACE_NEW_RETURN (temp,
+ (ACE_Timer_Node_T<TYPE, FUNCTOR, LOCK>),
+ 0);
+ }
else
- {
- temp = this->freelist_;
- this->freelist_ = temp->next_;
- }
+ {
+ temp = this->freelist_;
+ this->freelist_ = temp->next_;
+ }
return temp;
}
-template <class TYPE, class FUNCTOR> void
-ACE_Timer_Wheel_T<TYPE, FUNCTOR>::free_node (ACE_Timer_Node_T<TYPE, FUNCTOR> *node)
+template <class TYPE, class FUNCTOR, class LOCK> void
+ACE_Timer_Wheel_T<TYPE, FUNCTOR, LOCK>::free_node (ACE_Timer_Node_T<TYPE, FUNCTOR, LOCK> *node)
{
// Add to the beginning of the freelist
node->next_ = this->freelist_;
@@ -327,8 +323,8 @@ ACE_Timer_Wheel_T<TYPE, FUNCTOR>::free_node (ACE_Timer_Node_T<TYPE, FUNCTOR> *no
node->timer_id_ = 0;
}
-template <class TYPE, class FUNCTOR> ACE_Timer_Node_T<TYPE, FUNCTOR> *
-ACE_Timer_Wheel_T<TYPE, FUNCTOR>::remove (void)
+template <class TYPE, class FUNCTOR, class LOCK> ACE_Timer_Node_T<TYPE, FUNCTOR, LOCK> *
+ACE_Timer_Wheel_T<TYPE, FUNCTOR, LOCK>::remove (void)
{
ACE_TRACE ("ACE_Timer_Wheel_T::remove");
@@ -337,22 +333,22 @@ ACE_Timer_Wheel_T<TYPE, FUNCTOR>::remove (void)
// Check every entry in the table
for (size_t i = 0; i < this->wheel_size_; i++)
- {
- // Check for an empty entry
- if (this->wheel_[i]->next_ != this->wheel_[i])
{
- // if initialization or if the time is earlier
- if (earliest_time == ACE_Time_Value::zero
- || this->wheel_[i]->timer_value_ < earliest_time)
- {
- earliest_time = this->wheel_[i]->next_->timer_value_;
- earliest_pos = i;
- }
+ // Check for an empty entry
+ if (this->wheel_[i]->next_ != this->wheel_[i])
+ {
+ // if initialization or if the time is earlier
+ if (earliest_time == ACE_Time_Value::zero
+ || this->wheel_[i]->timer_value_ < earliest_time)
+ {
+ earliest_time = this->wheel_[i]->next_->timer_value_;
+ earliest_pos = i;
+ }
+ }
}
- }
// Remove and return
- ACE_Timer_Node_T<TYPE, FUNCTOR> *temp = this->wheel_[earliest_pos]->next_;
+ ACE_Timer_Node_T<TYPE, FUNCTOR, LOCK> *temp = this->wheel_[earliest_pos]->next_;
temp->prev_->next_ = temp->next_;
temp->next_->prev_ = temp->prev_;
@@ -361,8 +357,8 @@ ACE_Timer_Wheel_T<TYPE, FUNCTOR>::remove (void)
return temp;
}
-template <class TYPE, class FUNCTOR> void
-ACE_Timer_Wheel_T<TYPE, FUNCTOR>::reschedule (ACE_Timer_Node_T<TYPE, FUNCTOR> *expired)
+template <class TYPE, class FUNCTOR, class LOCK> void
+ACE_Timer_Wheel_T<TYPE, FUNCTOR, LOCK>::reschedule (ACE_Timer_Node_T<TYPE, FUNCTOR, LOCK> *expired)
{
ACE_TRACE ("ACE_Timer_Wheel_T::reschedule");
@@ -370,7 +366,7 @@ ACE_Timer_Wheel_T<TYPE, FUNCTOR>::reschedule (ACE_Timer_Node_T<TYPE, FUNCTOR> *e
// Insert time into dummy node
this->wheel_[pos]->timer_value_ = expired->timer_value_;
- ACE_Timer_Node_T<TYPE, FUNCTOR> *cursor = this->wheel_[pos]->next_;
+ ACE_Timer_Node_T<TYPE, FUNCTOR, LOCK> *cursor = this->wheel_[pos]->next_;
// Find position to insert
while (cursor->timer_value_ < expired->timer_value_)
@@ -385,8 +381,8 @@ ACE_Timer_Wheel_T<TYPE, FUNCTOR>::reschedule (ACE_Timer_Node_T<TYPE, FUNCTOR> *e
this->size_++;
}
-template <class TYPE, class FUNCTOR> ACE_Timer_Queue_Iterator_T<TYPE, FUNCTOR> &
-ACE_Timer_Wheel_T<TYPE, FUNCTOR>::iter (void)
+template <class TYPE, class FUNCTOR, class LOCK> ACE_Timer_Queue_Iterator_T<TYPE, FUNCTOR, LOCK> &
+ACE_Timer_Wheel_T<TYPE, FUNCTOR, LOCK>::iter (void)
{
this->iterator_.reset ();
return this->iterator_;