summaryrefslogtreecommitdiff
path: root/ace/Timer_Queue_T.cpp
diff options
context:
space:
mode:
authorcoryan <coryan@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1997-09-20 00:05:52 +0000
committercoryan <coryan@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1997-09-20 00:05:52 +0000
commit573e9c61b65ebf7a9e273470104aa25881136dfd (patch)
treecd23b24636356f773efb2f504a66be50779e160f /ace/Timer_Queue_T.cpp
parent70504f146a02b904f5e790cd540a8352bf36bb40 (diff)
downloadATCD-573e9c61b65ebf7a9e273470104aa25881136dfd.tar.gz
ChangeLogTag:Fri Sep 19 14:13:07 1997 Carlos O'Ryan <coryan@macarena.cs.wustl.edu>
Diffstat (limited to 'ace/Timer_Queue_T.cpp')
-rw-r--r--ace/Timer_Queue_T.cpp192
1 files changed, 98 insertions, 94 deletions
diff --git a/ace/Timer_Queue_T.cpp b/ace/Timer_Queue_T.cpp
index 5ba383def39..a3bf1455c58 100644
--- a/ace/Timer_Queue_T.cpp
+++ b/ace/Timer_Queue_T.cpp
@@ -65,31 +65,31 @@ ACE_Timer_Queue_T<TYPE, FUNCTOR, ACE_LOCK>::calculate_timeout (ACE_Time_Value *m
if (this->earliest_time () > cur_time)
{
- // The earliest item on the Timer_Queue is still in the
- // future. Therefore, use the smaller of (1) caller's wait
- // time or (2) the delta time between now and the earliest
- // time on the Timer_Queue.
+ // The earliest item on the Timer_Queue is still in the
+ // future. Therefore, use the smaller of (1) caller's wait
+ // time or (2) the delta time between now and the earliest
+ // time on the Timer_Queue.
this->timeout_ = this->earliest_time () - cur_time;
if (max_wait_time == 0 || *max_wait_time > timeout_)
return &this->timeout_;
- else
- return max_wait_time;
+ else
+ return max_wait_time;
}
- else
+ else
{
- // The earliest item on the Timer_Queue is now in the past.
- // Therefore, we've got to "poll" the Reactor, i.e., it must
- // just check the descriptors and then dispatch timers, etc.
+ // The earliest item on the Timer_Queue is now in the past.
+ // Therefore, we've got to "poll" the Reactor, i.e., it must
+ // just check the descriptors and then dispatch timers, etc.
this->timeout_ = ACE_Time_Value::zero;
- return &this->timeout_;
+ return &this->timeout_;
}
}
}
template <class TYPE, class FUNCTOR, class ACE_LOCK> ACE_Time_Value *
ACE_Timer_Queue_T<TYPE, FUNCTOR, ACE_LOCK>::calculate_timeout (ACE_Time_Value *max_wait_time,
- ACE_Time_Value *the_timeout)
+ ACE_Time_Value *the_timeout)
{
ACE_TRACE ("ACE_Timer_Queue_T::calculate_timeout");
@@ -110,21 +110,21 @@ ACE_Timer_Queue_T<TYPE, FUNCTOR, ACE_LOCK>::calculate_timeout (ACE_Time_Value *m
if (this->earliest_time () > cur_time)
{
- // The earliest item on the Timer_Queue is still in the
- // future. Therefore, use the smaller of (1) caller's wait
- // time or (2) the delta time between now and the earliest
- // time on the Timer_Queue.
+ // The earliest item on the Timer_Queue is still in the
+ // future. Therefore, use the smaller of (1) caller's wait
+ // time or (2) the delta time between now and the earliest
+ // time on the Timer_Queue.
*the_timeout = this->earliest_time () - cur_time;
if (!(max_wait_time == 0 || *max_wait_time > *the_timeout))
- *the_timeout = *max_wait_time;
+ *the_timeout = *max_wait_time;
}
- else
+ else
{
- // The earliest item on the Timer_Queue is now in the past.
- // Therefore, we've got to "poll" the Reactor, i.e., it must
- // just check the descriptors and then dispatch timers, etc.
- *the_timeout = ACE_Time_Value::zero;
+ // The earliest item on the Timer_Queue is now in the past.
+ // Therefore, we've got to "poll" the Reactor, i.e., it must
+ // just check the descriptors and then dispatch timers, etc.
+ *the_timeout = ACE_Time_Value::zero;
}
}
return the_timeout;
@@ -206,25 +206,25 @@ ACE_Timer_Queue_T<TYPE, FUNCTOR, ACE_LOCK>::expire (const ACE_Time_Value &cur_ti
// 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".
- do
- expired->set_timer_value (expired->get_timer_value () + expired->get_interval ());
- while (expired->get_timer_value () <= cur_time);
-
- // Since this is an interval timer, we need to reschedule
- // it.
- this->reschedule (expired);
- reclaim = 0;
- }
+ {
+ // Make sure that we skip past values that have already
+ // "expired".
+ do
+ expired->set_timer_value (expired->get_timer_value () + expired->get_interval ());
+ while (expired->get_timer_value () <= cur_time);
+
+ // Since this is an interval timer, we need to reschedule
+ // it.
+ this->reschedule (expired);
+ reclaim = 0;
+ }
// call the functor
this->upcall (type, act, cur_time);
if (reclaim)
- // Call the factory method to free up the node.
- this->free_node (expired);
+ // Call the factory method to free up the node.
+ this->free_node (expired);
number_of_timers_expired++;
@@ -237,11 +237,11 @@ ACE_Timer_Queue_T<TYPE, FUNCTOR, ACE_LOCK>::expire (const ACE_Time_Value &cur_ti
template <class ACE_LOCK> int
ACE_Event_Handler_Handle_Timeout_Upcall<ACE_LOCK>::timeout (ACE_Timer_Queue_T<ACE_Event_Handler *,
- ACE_Event_Handler_Handle_Timeout_Upcall<ACE_LOCK>,
- ACE_LOCK> &timer_queue,
- ACE_Event_Handler *handler,
- const void *act,
- const ACE_Time_Value &cur_time)
+ ACE_Event_Handler_Handle_Timeout_Upcall<ACE_LOCK>,
+ ACE_LOCK> &timer_queue,
+ ACE_Event_Handler *handler,
+ const void *act,
+ const ACE_Time_Value &cur_time)
{
// Upcall to the <handler>s handle_timeout method
if (handler->handle_timeout (cur_time, act) == -1)
@@ -252,24 +252,24 @@ ACE_Event_Handler_Handle_Timeout_Upcall<ACE_LOCK>::timeout (ACE_Timer_Queue_T<AC
template <class ACE_LOCK> int
ACE_Event_Handler_Handle_Timeout_Upcall<ACE_LOCK>::cancellation (ACE_Timer_Queue_T<ACE_Event_Handler *,
- ACE_Event_Handler_Handle_Timeout_Upcall<ACE_LOCK>,
- ACE_LOCK> &timer_queue,
- ACE_Event_Handler *handler)
+ ACE_Event_Handler_Handle_Timeout_Upcall<ACE_LOCK>,
+ ACE_LOCK> &timer_queue,
+ ACE_Event_Handler *handler)
{
ACE_UNUSED_ARG (timer_queue);
// Upcall to the <handler>s handle_close method
handler->handle_close (ACE_INVALID_HANDLE,
- ACE_Event_Handler::TIMER_MASK);
+ ACE_Event_Handler::TIMER_MASK);
return 0;
}
template <class ACE_LOCK> int
ACE_Event_Handler_Handle_Timeout_Upcall<ACE_LOCK>::deletion (ACE_Timer_Queue_T<ACE_Event_Handler *,
- ACE_Event_Handler_Handle_Timeout_Upcall<ACE_LOCK>,
- ACE_LOCK> &timer_queue,
- ACE_Event_Handler *handler,
- const void *arg)
+ ACE_Event_Handler_Handle_Timeout_Upcall<ACE_LOCK>,
+ ACE_LOCK> &timer_queue,
+ ACE_Event_Handler *handler,
+ const void *arg)
{
ACE_UNUSED_ARG (timer_queue);
ACE_UNUSED_ARG (handler);
@@ -288,7 +288,7 @@ ACE_Async_Timer_Queue_Adapter<TQ>::timer_queue (void)
template <class TQ> int
ACE_Async_Timer_Queue_Adapter<TQ>::cancel (long timer_id,
- const void **act)
+ const void **act)
{
// Block designated signals.
ACE_Sig_Guard sg (&this->mask_);
@@ -307,11 +307,29 @@ ACE_Async_Timer_Queue_Adapter<TQ>::expire (void)
return this->timer_queue_.expire ();
}
+template <class TQ> long
+ACE_Async_Timer_Queue_Adapter<TQ>::schedule_ualarm (void)
+{
+ ACE_Time_Value tv = this->timer_queue_.earliest_time ()
+ - ACE_OS::gettimeofday ();
+
+ // Beware of negative times and zero times (which cause problems for
+ // ualarm()).
+ if (tv < ACE_Time_Value::zero)
+ tv = ACE_Time_Value (0, 1);
+
+ // @@ This code should be clever enough to avoid updating the
+ // ualarm() if we haven't actually changed the earliest time.
+ // Schedule a new timer.
+ ACE_OS::ualarm (tv);
+ return 0;
+}
+
template <class TQ> long
ACE_Async_Timer_Queue_Adapter<TQ>::schedule (ACE_Event_Handler *eh,
- const void *act,
- const ACE_Time_Value &delay,
- const ACE_Time_Value &interval)
+ const void *act,
+ const ACE_Time_Value &delay,
+ const ACE_Time_Value &interval)
{
ACE_UNUSED_ARG (act);
ACE_UNUSED_ARG (interval);
@@ -320,28 +338,13 @@ ACE_Async_Timer_Queue_Adapter<TQ>::schedule (ACE_Event_Handler *eh,
ACE_Sig_Guard sg (&this->mask_);
ACE_UNUSED_ARG (sg);
+ // @@ We need to figure out how to implement interval timers...
long tid = this->timer_queue_.schedule (eh, 0, delay);
if (tid == -1)
ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "schedule_timer"), -1);
- ACE_Time_Value tv = this->timer_queue_.earliest_time ()
- - ACE_OS::gettimeofday ();
-
- ACE_DEBUG ((LM_DEBUG,
- "scheduling timer %d for (%d, %d)\n",
- tid, tv.sec (), tv.usec ()));
-
- // Beware of negative times and zero times (which cause problems for
- // ualarm()).
- if (tv < ACE_Time_Value::zero)
- tv = ACE_Time_Value (0, 1);
-
- // @@ This code should be clever enough to avoid updating the
- // ualarm() if we haven't actually changed the earliest time.
- // Schedule a new timer.
- ACE_OS::ualarm (tv);
- return 0;
+ return this->schedule_ualarm ();
}
template <class TQ>
@@ -355,8 +358,8 @@ ACE_Async_Timer_Queue_Adapter<TQ>::ACE_Async_Timer_Queue_Adapter (ACE_Sig_Set *m
// calls that are interrupted by the signals.
ACE_Sig_Action sa ((ACE_SignalHandler) 0,
- this->mask_,
- SA_RESTART);
+ this->mask_,
+ SA_RESTART);
if (this->sig_handler_.register_handler (SIGALRM, this, &sa) == -1)
ACE_ERROR ((LM_ERROR, "%p\n", "register_handler"));
@@ -365,10 +368,11 @@ ACE_Async_Timer_Queue_Adapter<TQ>::ACE_Async_Timer_Queue_Adapter (ACE_Sig_Set *m
// This is the signal handler function for the asynchronous timer
// list. It gets invoked asynchronously when the SIGALRM signal
// occurs.
+
template <class TQ> int
ACE_Async_Timer_Queue_Adapter<TQ>::handle_signal (int signum,
- siginfo_t *,
- ucontext_t *)
+ siginfo_t *,
+ ucontext_t *)
{
ACE_DEBUG ((LM_DEBUG, "handling signal %S\n", signum));
@@ -376,26 +380,26 @@ ACE_Async_Timer_Queue_Adapter<TQ>::handle_signal (int signum,
{
case SIGALRM:
{
- int expired_timers;
-
- // Expire the pending timers.
- expired_timers = this->timer_queue_.expire ();
-
- if (expired_timers > 0)
- ACE_DEBUG ((LM_DEBUG,
- "time = %d, timers expired = %d\n",
- ACE_OS::time (),
- expired_timers));
-
- // Only schedule a new timer if there is one in the list.
- // @@ This code should also become smarter to avoid
- // unnecessary calls to ualarm().
- if (this->timer_queue_.is_empty () == 0)
- ACE_OS::ualarm (this->timer_queue_.earliest_time ()
- - ACE_OS::gettimeofday ());
-
- return 0;
- /* NOTREACHED */
+ int expired_timers;
+
+ // Expire the pending timers.
+ // @@ We need to figure out how to implement interval timers...
+ expired_timers = this->timer_queue_.expire ();
+
+ if (expired_timers > 0)
+ ACE_DEBUG ((LM_DEBUG,
+ "time = %d, timers expired = %d\n",
+ ACE_OS::time (),
+ expired_timers));
+
+ // Only schedule a new timer if there is one in the list.
+ // @@ This code should also become smarter to avoid
+ // unnecessary calls to ualarm().
+ if (this->timer_queue_.is_empty () == 0)
+ return this->schedule_ualarm ();
+ else
+ return 0;
+ /* NOTREACHED */
}
default:
ACE_ERROR_RETURN ((LM_ERROR, "unexpected signal %S\n", signum), -1);