summaryrefslogtreecommitdiff
path: root/ace/Timer_Wheel_T.cpp
diff options
context:
space:
mode:
authormichel_j <michel_j@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>2002-08-30 22:46:31 +0000
committermichel_j <michel_j@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>2002-08-30 22:46:31 +0000
commit19858ca542d42306f9d099d67e419c9fa5715d34 (patch)
treecd72d0cda949d57b11cd49c6fb433ae941581c58 /ace/Timer_Wheel_T.cpp
parente021cbc0026b063d335a69e7f86dd1ea37baa752 (diff)
downloadATCD-19858ca542d42306f9d099d67e419c9fa5715d34.tar.gz
Fri Aug 30 17:34:00 2002 Justin Michel <michel_j@ociweb.com>
Diffstat (limited to 'ace/Timer_Wheel_T.cpp')
-rw-r--r--ace/Timer_Wheel_T.cpp40
1 files changed, 18 insertions, 22 deletions
diff --git a/ace/Timer_Wheel_T.cpp b/ace/Timer_Wheel_T.cpp
index 65013a5c4a1..b3f251a4604 100644
--- a/ace/Timer_Wheel_T.cpp
+++ b/ace/Timer_Wheel_T.cpp
@@ -168,14 +168,12 @@ ACE_Timer_Wheel_T<TYPE, FUNCTOR, ACE_LOCK>::~ACE_Timer_Wheel_T (void)
{
// Free all the nodes starting at the root
ACE_Timer_Node_T<TYPE>* root = this->spokes_[i];
- for (ACE_Timer_Node_T<TYPE>* a = root->get_next(); a != root;)
+ for (ACE_Timer_Node_T<TYPE>* n = root->get_next(); n != root;)
{
- ACE_Timer_Node_T<TYPE>* b = a->get_next();
- this->upcall_functor().deletion(*this, a->get_type(), a->get_act());
- a->set_prev(0);
- a->set_next(0);
- this->free_node (a);
- a = b->get_next();
+ ACE_Timer_Node_T<TYPE>* next = n->get_next();
+ this->upcall_functor().deletion(*this, n->get_type(), n->get_act());
+ this->free_node (n);
+ n = next;
}
delete root;
}
@@ -412,21 +410,19 @@ ACE_Timer_Wheel_T<TYPE, FUNCTOR, ACE_LOCK>::schedule_i (ACE_Timer_Node_T<TYPE>*
root->set_next(n);
return;
}
- // Note : It might be beneficial in the real world to check to see
- // if the new timer belongs on the end of the spoke, but in testing
- // it made no difference, so we just skip it.
-
- // We use <= here so that the timers with equal values will
- // be scheduled in the right order
- ACE_Timer_Node_T<TYPE>* next = root->get_next();
- while (next != root && next->get_timer_value() <= expire)
- next = next->get_next();
-
- // insert before
- n->set_prev(next->get_prev());
- n->set_next(next);
- next->get_prev()->set_next(n);
- next->set_prev(n);
+
+ // We always want to search backwards from the tail of the list, because
+ // this minimizes the search in the extreme case when lots of timers are
+ // scheduled for exactly the same time
+ ACE_Timer_Node_T<TYPE>* p = root->get_prev();
+ while (p != root && p->get_timer_value() > expire)
+ p = p->get_prev();
+
+ // insert after
+ n->set_prev(p);
+ n->set_next(p->get_next());
+ p->get_next()->set_prev(n);
+ p->set_next(n);
}