summaryrefslogtreecommitdiff
path: root/ace/Timer_Queue.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'ace/Timer_Queue.cpp')
-rw-r--r--ace/Timer_Queue.cpp128
1 files changed, 71 insertions, 57 deletions
diff --git a/ace/Timer_Queue.cpp b/ace/Timer_Queue.cpp
index f6bf551df5e..77a0b274f02 100644
--- a/ace/Timer_Queue.cpp
+++ b/ace/Timer_Queue.cpp
@@ -1,23 +1,25 @@
// Timer_Queue.cpp
// $Id$
+#if !defined (ACE_TIMER_QUEUE_C)
+#define ACE_TIMER_QUEUE_C
+
#define ACE_BUILD_DLL
#include "ace/Timer_Queue.h"
-#include "ace/Strategies.h"
#if !defined (__ACE_INLINE__)
#include "ace/Timer_Queue.i"
#endif /* __ACE_INLINE__ */
-ACE_ALLOC_HOOK_DEFINE(ACE_Timer_Node)
+ACE_ALLOC_HOOK_DEFINE(ACE_Timer_Node_T)
-void
-ACE_Timer_Node::dump (void) const
+template <class TYPE, class FUNCTOR> void
+ACE_Timer_Node_T<TYPE, FUNCTOR>::dump (void) const
{
ACE_TRACE ("ACE_Timer_Node::dump");
ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
- ACE_DEBUG ((LM_DEBUG, "\nhandler_ = %x", this->handler_));
- ACE_DEBUG ((LM_DEBUG, "\narg_ = %x", this->arg_));
+ // ACE_DEBUG ((LM_DEBUG, "\type_ = %x", this->type_));
+ ACE_DEBUG ((LM_DEBUG, "\nact_ = %x", this->act_));
this->timer_value_.dump ();
this->interval_.dump ();
ACE_DEBUG ((LM_DEBUG, "\nnext_ = %x", this->next_));
@@ -25,19 +27,21 @@ ACE_Timer_Node::dump (void) const
ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
}
-ACE_Timer_Node::ACE_Timer_Node (void)
+template <class TYPE, class FUNCTOR>
+ACE_Timer_Node_T<TYPE, FUNCTOR>::ACE_Timer_Node_T (void)
{
ACE_TRACE ("ACE_Timer_Node::ACE_Timer_Node");
}
-ACE_Timer_Node::ACE_Timer_Node (ACE_Event_Handler *h,
- const void *a,
- const ACE_Time_Value &t,
- const ACE_Time_Value &i,
- ACE_Timer_Node *n,
- int timer_id)
- : handler_ (h),
- arg_ (a),
+template <class TYPE, class FUNCTOR>
+ACE_Timer_Node_T<TYPE, FUNCTOR>::ACE_Timer_Node_T (const TYPE &type,
+ const void *a,
+ const ACE_Time_Value &t,
+ const ACE_Time_Value &i,
+ NODE *n,
+ int timer_id)
+ : type_ (type),
+ act_ (a),
timer_value_ (t),
interval_ (i),
next_ (n),
@@ -46,11 +50,13 @@ ACE_Timer_Node::ACE_Timer_Node (ACE_Event_Handler *h,
ACE_TRACE ("ACE_Timer_Node::ACE_Timer_Node");
}
-ACE_Timer_Queue_Iterator::ACE_Timer_Queue_Iterator (void)
+template <class TYPE, class FUNCTOR>
+ACE_Timer_Queue_Iterator_T<TYPE, FUNCTOR>::ACE_Timer_Queue_Iterator_T (void)
{
}
-ACE_Timer_Queue_Iterator::~ACE_Timer_Queue_Iterator (void)
+template <class TYPE, class FUNCTOR>
+ACE_Timer_Queue_Iterator_T<TYPE, FUNCTOR>::~ACE_Timer_Queue_Iterator_T (void)
{
}
@@ -59,15 +65,15 @@ ACE_Timer_Queue_Iterator::~ACE_Timer_Queue_Iterator (void)
// amount the caller requested when calling handle_events() and (2)
// the earliest time registered in the Timer Queue (if any). Must be
// called with an external lock held since it returns a pointer to a
-// Time_Value object stored in the Timer_Queue object itself. If some
+// Time_Value type stored in the Timer_Queue type itself. If some
// external lock isn't held we'll have reentrancy problems!
-ACE_Time_Value *
-ACE_Timer_Queue::calculate_timeout (ACE_Time_Value *max_wait_time)
+template <class TYPE, class FUNCTOR> ACE_Time_Value *
+ACE_Timer_Queue_T<TYPE, FUNCTOR>::calculate_timeout (ACE_Time_Value *max_wait_time)
{
ACE_TRACE ("ACE_Timer_List::calculate_timeout");
ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon, this->lock_, max_wait_time));
-
+
if (this->is_empty ())
// Nothing on the Timer_Queue, so use whatever the caller gave us.
return max_wait_time;
@@ -99,8 +105,8 @@ ACE_Timer_Queue::calculate_timeout (ACE_Time_Value *max_wait_time)
}
}
-void
-ACE_Timer_Queue::dump (void) const
+template <class TYPE, class FUNCTOR> void
+ACE_Timer_Queue_T<TYPE, FUNCTOR>::dump (void) const
{
ACE_TRACE ("ACE_Timer_Queue::dump");
ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
@@ -109,42 +115,48 @@ ACE_Timer_Queue::dump (void) const
ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
}
-ACE_Timer_Queue::ACE_Timer_Queue (ACE_Upcall_Strategy *upcall_strategy)
+template <class TYPE, class FUNCTOR>
+ACE_Timer_Queue_T<TYPE, FUNCTOR>::ACE_Timer_Queue_T (FUNCTOR *upcall_functor)
: gettimeofday_ (ACE_OS::gettimeofday),
- upcall_strategy_ (upcall_strategy),
- timer_skew_ (0, ACE_TIMER_SKEW)
+ timer_skew_ (0, ACE_TIMER_SKEW),
+ upcall_functor_ (upcall_functor == 0 ? *(new FUNCTOR) : *upcall_functor),
+ delete_upcall_functor_ (upcall_functor == 0)
{
ACE_TRACE ("ACE_Timer_Queue::ACE_Timer_Queue");
}
-ACE_Timer_Queue::~ACE_Timer_Queue (void)
+template <class TYPE, class FUNCTOR>
+ACE_Timer_Queue_T<TYPE, FUNCTOR>::~ACE_Timer_Queue_T (void)
{
+ // Cleanup the functor on the way out
+ if (delete_upcall_functor_)
+ delete &this->upcall_functor_;
+
ACE_TRACE ("ACE_Timer_Queue::~ACE_Timer_Queue");
}
// Run the <handle_timeout> method for all Timers whose values are <=
// <cur_time>.
-int
-ACE_Timer_Queue::expire (const ACE_Time_Value &cur_time)
+template <class TYPE, class FUNCTOR> int
+ACE_Timer_Queue_T<TYPE, FUNCTOR>::expire (const ACE_Time_Value &cur_time)
{
ACE_TRACE ("ACE_Timer_List::expire");
ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon, this->lock_, -1));
int number_of_timers_expired = 0;
- ACE_Timer_Queue_Iterator &iter = this->iter ();
+ ITERATOR &iter = this->iter ();
// Keep looping while there are timers remaining and the earliest
// timer is <= the <cur_time> passed in to the method.
- for (ACE_Timer_Node *expired;
+ for (NODE *expired;
iter.next (expired, cur_time) != 0;
)
{
- ACE_Event_Handler *handler =
- (ACE_Event_Handler *) expired->handler_;
- const void *arg = expired->arg_;
+ TYPE &type = expired->type_;
+ const void *act = expired->act_;
int reclaim = 1;
// Check if this is an interval timer.
@@ -161,56 +173,58 @@ ACE_Timer_Queue::expire (const ACE_Time_Value &cur_time)
this->reschedule (expired);
reclaim = 0;
}
-
- this->upcall (handler, arg, cur_time);
-
+
+ // call the functor
+ this->upcall (type, act, cur_time);
+
if (reclaim)
// Call the factory method to free up the node.
this->free_node (expired);
-
+
number_of_timers_expired++;
}
return number_of_timers_expired;
}
-void
-ACE_Timer_Queue::upcall (ACE_Event_Handler *handler,
- const void *arg,
- const ACE_Time_Value &cur_time)
+template <class TYPE, class FUNCTOR> void
+ACE_Timer_Queue_T<TYPE, FUNCTOR>::upcall (TYPE &type,
+ const void *act,
+ const ACE_Time_Value &cur_time)
{
- if (this->upcall_strategy_ == 0)
- {
- // Perform the callback.
- if (handler->handle_timeout (cur_time, arg) == -1)
- this->cancel (handler, 0); // 0 means "call handle_close()".
- }
- else
- // Pass the information along to the strategy
- this->upcall_strategy_->upcall (handler, arg, cur_time);
+ // This calls the correct operator () on the functor (the one with
+ // four args)
+ this->upcall_functor_ (*this, type, act, cur_time);
}
-ACE_Time_Value
-ACE_Timer_Queue::gettimeofday (void)
+template <class TYPE, class FUNCTOR> ACE_Time_Value
+ACE_Timer_Queue_T<TYPE, FUNCTOR>::gettimeofday (void)
{
// Invoke gettimeofday via pointer to function.
return gettimeofday_ ();
}
-void
-ACE_Timer_Queue::gettimeofday (ACE_Time_Value (*gettimeofday)(void))
+template <class TYPE, class FUNCTOR> void
+ACE_Timer_Queue_T<TYPE, FUNCTOR>::gettimeofday (ACE_Time_Value (*gettimeofday)(void))
{
gettimeofday_ = gettimeofday;
}
#if defined (ACE_MT_SAFE)
-ACE_Recursive_Thread_Mutex &
-ACE_Timer_Queue::lock (void)
+template <class TYPE, class FUNCTOR> ACE_Recursive_Thread_Mutex &
+ACE_Timer_Queue_T<TYPE, FUNCTOR>::lock (void)
{
return this->lock_;
}
#endif /* ACE_MT_SAFE */
+template <class TYPE, class FUNCTOR> FUNCTOR &
+ACE_Timer_Queue_T<TYPE, FUNCTOR>::upcall_functor (void)
+{
+ return this->upcall_functor_;
+}
+
+#endif /* ACE_TIMER_QUEUE_C */