summaryrefslogtreecommitdiff
path: root/ace/Timer_List.cpp
diff options
context:
space:
mode:
authorirfan <irfan@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1997-04-25 07:20:29 +0000
committerirfan <irfan@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1997-04-25 07:20:29 +0000
commit34a82afb8e57608987736008005af93b310a1417 (patch)
tree41ccfddad8934584cad94f13585c733126e6cd8c /ace/Timer_List.cpp
parent42e14ecec9e6734bfacf497fc8ee9205bcd48b74 (diff)
downloadATCD-34a82afb8e57608987736008005af93b310a1417.tar.gz
*** empty log message ***
Diffstat (limited to 'ace/Timer_List.cpp')
-rw-r--r--ace/Timer_List.cpp209
1 files changed, 110 insertions, 99 deletions
diff --git a/ace/Timer_List.cpp b/ace/Timer_List.cpp
index 75d107d7173..f8c0a5ba17e 100644
--- a/ace/Timer_List.cpp
+++ b/ace/Timer_List.cpp
@@ -1,18 +1,22 @@
// $Id$
+#if !defined (ACE_TIMER_LIST_C)
+#define ACE_TIMER_LIST_C
+
#define ACE_BUILD_DLL
#include "ace/Timer_List.h"
-#include "ace/Strategies.h"
-ACE_Timer_List_Iterator::ACE_Timer_List_Iterator (ACE_Timer_List &list)
+template <class TYPE, class FUNCTOR>
+ACE_Timer_List_Iterator_T<TYPE, FUNCTOR>::ACE_Timer_List_Iterator_T (ACE_Timer_List_T<TYPE, FUNCTOR> &list)
: timer_list_ (list)
{
}
-int
-ACE_Timer_List_Iterator::next (ACE_Timer_Node *&node,
- const ACE_Time_Value &cur_time)
+
+template <class TYPE, class FUNCTOR> int
+ACE_Timer_List_Iterator_T<TYPE, FUNCTOR>::next (NODE *&node,
+ const ACE_Time_Value &cur_time)
{
if (this->timer_list_.head_ == 0
|| this->timer_list_.head_->timer_value_ > cur_time)
@@ -25,18 +29,19 @@ ACE_Timer_List_Iterator::next (ACE_Timer_Node *&node,
}
}
-ACE_ALLOC_HOOK_DEFINE(ACE_Timer_List)
+ACE_ALLOC_HOOK_DEFINE(ACE_Timer_List_T)
-ACE_Timer_Queue_Iterator &
-ACE_Timer_List::iter (void)
+ template <class TYPE, class FUNCTOR> ACE_Timer_Queue_T<TYPE, FUNCTOR>::ITERATOR &
+ACE_Timer_List_T<TYPE, FUNCTOR>::iter (void)
{
return this->iterator_;
}
// Create an empty list.
-ACE_Timer_List::ACE_Timer_List (ACE_Upcall_Strategy *upcall_strategy)
- : ACE_Timer_Queue (upcall_strategy),
+template <class TYPE, class FUNCTOR>
+ACE_Timer_List_T<TYPE, FUNCTOR>::ACE_Timer_List_T (FUNCTOR *upcall_functor)
+ : INHERITED (upcall_functor),
head_ (0),
iterator_ (*this),
timer_id_ (0)
@@ -46,29 +51,33 @@ ACE_Timer_List::ACE_Timer_List (ACE_Upcall_Strategy *upcall_strategy)
// Checks if list is empty.
-int
-ACE_Timer_List::is_empty (void) const
+
+template <class TYPE, class FUNCTOR> int
+ACE_Timer_List_T<TYPE, FUNCTOR>::is_empty (void) const
{
ACE_TRACE ("ACE_Timer_List::is_empty");
return this->head_ == 0;
}
-ACE_Timer_Node *
-ACE_Timer_List::alloc_node (void)
+
+template <class TYPE, class FUNCTOR> ACE_Timer_Queue_T<TYPE, FUNCTOR>::NODE *
+ACE_Timer_List_T<TYPE, FUNCTOR>::alloc_node (void)
{
- return new ACE_Timer_Node;
+ return new NODE;
}
-void
-ACE_Timer_List::free_node (ACE_Timer_Node *node)
+
+template <class TYPE, class FUNCTOR> void
+ACE_Timer_List_T<TYPE, FUNCTOR>::free_node (NODE *node)
{
delete node;
}
// Returns earliest time in a non-empty list.
-const ACE_Time_Value &
-ACE_Timer_List::earliest_time (void) const
+
+template <class TYPE, class FUNCTOR> const ACE_Time_Value &
+ACE_Timer_List_T<TYPE, FUNCTOR>::earliest_time (void) const
{
ACE_TRACE ("ACE_Timer_List::earliest_time");
return this->head_->timer_value_;
@@ -76,23 +85,25 @@ ACE_Timer_List::earliest_time (void) const
// Remove all remaining items in the list.
-ACE_Timer_List::~ACE_Timer_List (void)
+template <class TYPE, class FUNCTOR>
+ACE_Timer_List_T<TYPE, FUNCTOR>::~ACE_Timer_List_T (void)
{
ACE_TRACE ("ACE_Timer_List::~ACE_Timer_List");
ACE_MT (ACE_GUARD (ACE_Recursive_Thread_Mutex, ace_mon, this->lock_));
- ACE_Timer_Node *curr = this->head_;
+ NODE *curr = this->head_;
while (curr != 0)
{
- ACE_Timer_Node *next = curr->next_;
+ NODE *next = curr->next_;
this->free_node (curr);
curr = next;
}
}
-void
-ACE_Timer_List::dump (void) const
+
+template <class TYPE, class FUNCTOR> void
+ACE_Timer_List_T<TYPE, FUNCTOR>::dump (void) const
{
ACE_TRACE ("ACE_Timer_List::dump");
ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
@@ -104,8 +115,9 @@ ACE_Timer_List::dump (void) const
// Reschedule a periodic timer. This function must be called with the
// mutex lock held.
-void
-ACE_Timer_List::reschedule (ACE_Timer_Node *expired)
+
+template <class TYPE, class FUNCTOR> void
+ACE_Timer_List_T<TYPE, FUNCTOR>::reschedule (NODE *expired)
{
ACE_TRACE ("ACE_Timer_List::reschedule");
if (this->is_empty ()
@@ -116,8 +128,8 @@ ACE_Timer_List::reschedule (ACE_Timer_Node *expired)
}
else
{
- ACE_Timer_Node *prev = this->head_;
- ACE_Timer_Node *after = this->head_->next_;
+ NODE *prev = this->head_;
+ NODE *after = this->head_->next_;
// Locate the proper position in the queue.
@@ -136,69 +148,63 @@ ACE_Timer_List::reschedule (ACE_Timer_Node *expired)
// Insert a new handler that expires at time future_time; if interval
// is > 0, the handler will be reinvoked periodically.
-int
-ACE_Timer_List::schedule (ACE_Event_Handler *handler,
- const void *arg,
- const ACE_Time_Value &future_time,
- const ACE_Time_Value &interval)
+
+template <class TYPE, class FUNCTOR> int
+ACE_Timer_List_T<TYPE, FUNCTOR>::schedule (const TYPE &type,
+ const void *act,
+ const ACE_Time_Value &future_time,
+ const ACE_Time_Value &interval)
{
ACE_TRACE ("ACE_Timer_List::schedule");
ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon, this->lock_, -1));
- if (handler == 0)
+ // Increment the sequence number (it will wrap around).
+ int timer_id = this->timer_id ();
+
+ if (this->is_empty () || future_time < this->earliest_time ())
{
- errno = EINVAL;
- return -1;
+ // Place at the beginning of the list.
+ NODE *temp = this->alloc_node ();
+
+ // Use operator placement new.
+ this->head_ = new (temp) NODE (type,
+ act,
+ future_time,
+ interval,
+ this->head_,
+ timer_id);
+ return timer_id;
}
- else
+
+ // Place in the middle of the list where it belongs (i.e., sorted in
+ // ascending order of absolute time to expire).
+ else
{
- // Increment the sequence number (it will wrap around).
- int timer_id = this->timer_id ();
-
- if (this->is_empty () || future_time < this->earliest_time ())
+ NODE *prev = this->head_;
+ NODE *after = this->head_->next_;
+
+ while (after != 0 && future_time > after->timer_value_)
{
- // Place at the beginning of the list.
- ACE_Timer_Node *temp = this->alloc_node ();
-
- // Use operator placement new.
- this->head_ = new (temp) ACE_Timer_Node (handler,
- arg,
- future_time,
- interval,
- this->head_,
- timer_id);
- return timer_id;
+ prev = after;
+ after = after->next_;
}
- // Place in the middle of the list where it belongs (i.e., sorted in
- // ascending order of absolute time to expire).
- else
- {
- ACE_Timer_Node *prev = this->head_;
- ACE_Timer_Node *after = this->head_->next_;
-
- while (after != 0 && future_time > after->timer_value_)
- {
- prev = after;
- after = after->next_;
- }
-
- ACE_Timer_Node *temp = this->alloc_node ();
+ NODE *temp = this->alloc_node ();
- // Use operator placement new.
- prev->next_ = new (temp) ACE_Timer_Node (handler,
- arg,
- future_time,
- interval,
- after,
- timer_id);
- return timer_id;
- }
+ // Use operator placement new.
+ prev->next_ = new (temp) NODE (type,
+ act,
+ future_time,
+ interval,
+ after,
+ timer_id);
+ return timer_id;
}
}
-int
-ACE_Timer_List::timer_id (void)
+
+template <class TYPE, class FUNCTOR> int
+ACE_Timer_List_T<TYPE, FUNCTOR>::timer_id (void)
{
this->timer_id_++;
@@ -212,16 +218,17 @@ ACE_Timer_List::timer_id (void)
// Locate and remove the single <ACE_Event_Handler> with a value of
// <timer_id> from the timer queue.
-int
-ACE_Timer_List::cancel (int timer_id,
- const void **arg,
- int dont_call_handle_close)
+
+template <class TYPE, class FUNCTOR> int
+ACE_Timer_List_T<TYPE, FUNCTOR>::cancel (int timer_id,
+ const void **act,
+ int dont_call)
{
ACE_TRACE ("ACE_Timer_List::cancel");
ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon, this->lock_, -1));
- ACE_Timer_Node *prev = 0;
- ACE_Timer_Node *curr = 0;
+ NODE *prev = 0;
+ NODE *curr = 0;
// Try to locate the ACE_Timer_Node that matches the timer_id.
@@ -237,13 +244,13 @@ ACE_Timer_List::cancel (int timer_id,
else
prev->next_ = curr->next_;
- if (arg != 0)
- *arg = curr->arg_;
+ if (act != 0)
+ *act = curr->act_;
- if (dont_call_handle_close == 0)
- // Call the close hook.
- curr->handler_->handle_close (ACE_INVALID_HANDLE,
- ACE_Event_Handler::TIMER_MASK);
+ if (dont_call == 0)
+ // This calls the correct operator () on the functor (the one with
+ // two args)
+ this->upcall_functor_ (*this, curr->type_);
this->free_node (curr);
return 1;
}
@@ -253,29 +260,30 @@ ACE_Timer_List::cancel (int timer_id,
// Locate and remove all values of <handler> from the timer queue.
-int
-ACE_Timer_List::cancel (ACE_Event_Handler *handler,
- int dont_call_handle_close)
+
+template <class TYPE, class FUNCTOR> int
+ACE_Timer_List_T<TYPE, FUNCTOR>::cancel (const TYPE &type,
+ int dont_call)
{
ACE_TRACE ("ACE_Timer_List::cancel");
ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon, this->lock_, -1));
- ACE_Timer_Node *prev = 0;
- ACE_Timer_Node *curr = this->head_;
+ NODE *prev = 0;
+ NODE *curr = this->head_;
int number_of_cancellations = 0;
while (curr != 0)
{
- if (curr->handler_ == handler)
+ if (curr->type_ == type)
{
number_of_cancellations++;
- if (dont_call_handle_close == 0
+ if (dont_call == 0
&& number_of_cancellations == 1)
- // Call the close hook.
- curr->handler_->handle_close (ACE_INVALID_HANDLE,
- ACE_Event_Handler::TIMER_MASK);
+ // This calls the correct operator () on the functor (the one with
+ // two args)
+ this->upcall_functor_ (*this, curr->type_);
if (prev == 0)
{
this->head_ = curr->next_;
@@ -298,3 +306,6 @@ ACE_Timer_List::cancel (ACE_Event_Handler *handler,
return number_of_cancellations;
}
+
+#endif /* ACE_TIMER_LIST_C */
+