From 573e9c61b65ebf7a9e273470104aa25881136dfd Mon Sep 17 00:00:00 2001 From: coryan Date: Sat, 20 Sep 1997 00:05:52 +0000 Subject: ChangeLogTag:Fri Sep 19 14:13:07 1997 Carlos O'Ryan --- ace/Timer_Queue_T.cpp | 192 ++++++++++++++++++++++++++------------------------ 1 file changed, 98 insertions(+), 94 deletions(-) (limited to 'ace/Timer_Queue_T.cpp') 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::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 ACE_Time_Value * ACE_Timer_Queue_T::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::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::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::expire (const ACE_Time_Value &cur_ti template int ACE_Event_Handler_Handle_Timeout_Upcall::timeout (ACE_Timer_Queue_T, - 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> &timer_queue, + ACE_Event_Handler *handler, + const void *act, + const ACE_Time_Value &cur_time) { // Upcall to the s handle_timeout method if (handler->handle_timeout (cur_time, act) == -1) @@ -252,24 +252,24 @@ ACE_Event_Handler_Handle_Timeout_Upcall::timeout (ACE_Timer_Queue_T int ACE_Event_Handler_Handle_Timeout_Upcall::cancellation (ACE_Timer_Queue_T, - ACE_LOCK> &timer_queue, - ACE_Event_Handler *handler) + ACE_Event_Handler_Handle_Timeout_Upcall, + ACE_LOCK> &timer_queue, + ACE_Event_Handler *handler) { ACE_UNUSED_ARG (timer_queue); // Upcall to the s handle_close method handler->handle_close (ACE_INVALID_HANDLE, - ACE_Event_Handler::TIMER_MASK); + ACE_Event_Handler::TIMER_MASK); return 0; } template int ACE_Event_Handler_Handle_Timeout_Upcall::deletion (ACE_Timer_Queue_T, - ACE_LOCK> &timer_queue, - ACE_Event_Handler *handler, - const void *arg) + ACE_Event_Handler_Handle_Timeout_Upcall, + 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::timer_queue (void) template int ACE_Async_Timer_Queue_Adapter::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::expire (void) return this->timer_queue_.expire (); } +template long +ACE_Async_Timer_Queue_Adapter::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 long ACE_Async_Timer_Queue_Adapter::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::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 @@ -355,8 +358,8 @@ ACE_Async_Timer_Queue_Adapter::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::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 int ACE_Async_Timer_Queue_Adapter::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::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); -- cgit v1.2.1