Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

ACE_Async_Timer_Queue_Adapter Class Template Reference

Adapts a <TQ> to be run asynchronously. More...

#include <Timer_Queue_Adapters.h>

Inheritance diagram for ACE_Async_Timer_Queue_Adapter:

Inheritance graph
[legend]
Collaboration diagram for ACE_Async_Timer_Queue_Adapter:

Collaboration graph
[legend]
List of all members.

Public Types

typedef TQ TIMER_QUEUE

Public Methods

 ACE_Async_Timer_Queue_Adapter (ACE_Sig_Set *mask=0)
 Constructor. More...

long schedule (ACE_Event_Handler *type, const void *act, const ACE_Time_Value &future_time, const ACE_Time_Value &interval=ACE_Time_Value::zero)
 Schedule the timer according to the semantics of the <ACE_Timer_List>. More...

int cancel (long timer_id, const void **act=0)
 Cancel the timer_id and pass back the act if an address is passed in. More...

int expire (void)
 Dispatch all timers whose values are <= <cur_time>. Returns the number of timers canceled. More...

TQ & timer_queue (void)
 Access the underlying <TIMER_QUEUE>. More...


Private Methods

virtual int schedule_ualarm (void)
 Perform the logic to compute the new ualarm(2) setting. More...

virtual int handle_signal (int signum, siginfo_t *, ucontext_t *)
 Called back by <SIGALRM> handler. More...


Private Attributes

ACE_Sig_Handler sig_handler_
 Handler for the <SIGALRM> signal, so that we can access our state without requiring any global variables. More...

TQ timer_queue_
 Implementation of the timer queue (e.g., <ACE_Timer_List>, <ACE_Timer_Heap>, etc.). More...

ACE_Sig_Set mask_
 Mask of signals to be blocked when we're servicing <SIGALRM>. More...


Detailed Description

template<class TQ>
class ACE_Async_Timer_Queue_Adapter< TQ >

Adapts a <TQ> to be run asynchronously.

This implementation uses the <ualarm> call, which generates the SIGARLM signal that is caught by this class.

Definition at line 35 of file Timer_Queue_Adapters.h.


Member Typedef Documentation

template<class TQ>
typedef TQ ACE_Async_Timer_Queue_Adapter::TIMER_QUEUE
 

Definition at line 38 of file Timer_Queue_Adapters.h.


Constructor & Destructor Documentation

template<class TQ>
ACE_Async_Timer_Queue_Adapter< TQ >::ACE_Async_Timer_Queue_Adapter ACE_Sig_Set   mask = 0
 

Constructor.

Register the SIGALRM handler. If <mask> == 0 then block all signals when <SIGALRM> is run. Otherwise, just block the signals indicated in <mask>.

Definition at line 92 of file Timer_Queue_Adapters.cpp.

References ACE_ERROR, ACE_LIB_TEXT, ACE_SignalHandler, LM_ERROR, SA_RESTART, and SIGALRM.

00095   : mask_ (mask)
00096 {
00097   // The following code is necessary to selectively "block" certain
00098   // signals when SIGALRM is running.  Also, we always restart system
00099   // calls that are interrupted by the signals.
00100 
00101   ACE_Sig_Action sa ((ACE_SignalHandler) 0,
00102                      this->mask_,
00103                      SA_RESTART);
00104 
00105   if (this->sig_handler_.register_handler (SIGALRM, this, &sa) == -1)
00106     ACE_ERROR ((LM_ERROR,
00107                 ACE_LIB_TEXT ("%p\n"),
00108                 ACE_LIB_TEXT ("register_handler")));
00109 }


Member Function Documentation

template<class TQ>
int ACE_Async_Timer_Queue_Adapter< TQ >::cancel long    timer_id,
const void **    act = 0
 

Cancel the timer_id and pass back the act if an address is passed in.

Definition at line 25 of file Timer_Queue_Adapters.cpp.

References timer_queue_.

00027 {
00028   // Block designated signals.
00029   ACE_Sig_Guard sg (&this->mask_);
00030   ACE_UNUSED_ARG (sg);
00031 
00032   return this->timer_queue_.cancel (timer_id, act);
00033 }

template<class TQ>
int ACE_Async_Timer_Queue_Adapter< TQ >::expire void   
 

Dispatch all timers whose values are <= <cur_time>. Returns the number of timers canceled.

Definition at line 36 of file Timer_Queue_Adapters.cpp.

References timer_queue_.

00037 {
00038   // Block designated signals.
00039   ACE_Sig_Guard sg (&this->mask_);
00040   ACE_UNUSED_ARG (sg);
00041 
00042   return this->timer_queue_.expire ();
00043 }

template<class TQ>
int ACE_Async_Timer_Queue_Adapter< TQ >::handle_signal int    signum,
siginfo_t  ,
ucontext_t  
[private, virtual]
 

Called back by <SIGALRM> handler.

Reimplemented from ACE_Event_Handler.

Definition at line 116 of file Timer_Queue_Adapters.cpp.

References ACE_ERROR_RETURN, LM_ERROR, schedule_ualarm, SIGALRM, timer_queue_, and ucontext_t.

00119 {
00120   switch (signum)
00121     {
00122     case SIGALRM:
00123       {
00124         // Expire the pending timers.
00125 
00126         // @@ We need to figure out how to implement interval
00127         // timers...
00128         this->timer_queue_.expire ();
00129 
00130         // Only schedule a new timer if there is one in the list.
00131 
00132         // @@ This code should also become smarter to avoid
00133         // unnecessary calls to ualarm().
00134         if (this->timer_queue_.is_empty () == 0)
00135           return this->schedule_ualarm ();
00136         else
00137           return 0;
00138         /* NOTREACHED */
00139       }
00140     default:
00141       ACE_ERROR_RETURN ((LM_ERROR,
00142                          "unexpected signal %S\n",
00143                          signum),
00144                         -1);
00145       /* NOTREACHED */
00146     }
00147 }

template<class TQ>
long ACE_Async_Timer_Queue_Adapter< TQ >::schedule ACE_Event_Handler   type,
const void *    act,
const ACE_Time_Value   future_time,
const ACE_Time_Value   interval = ACE_Time_Value::zero
 

Schedule the timer according to the semantics of the <ACE_Timer_List>.

This timer gets dispatched via a signal, rather than by a user calling expire(). Note that interval timers are not implemented yet.

Definition at line 64 of file Timer_Queue_Adapters.cpp.

References ACE_ERROR_RETURN, ACE_LIB_TEXT, LM_ERROR, schedule_ualarm, and timer_queue_.

00068 {
00069   ACE_UNUSED_ARG (act);
00070   ACE_UNUSED_ARG (interval);
00071 
00072   // Block designated signals.
00073   ACE_Sig_Guard sg (&this->mask_);
00074   ACE_UNUSED_ARG (sg);
00075 
00076   // @@ We still need to implement interval timers...
00077   long tid = this->timer_queue_.schedule (eh, act, future_time);
00078 
00079   if (tid == -1)
00080     ACE_ERROR_RETURN ((LM_ERROR,
00081                        ACE_LIB_TEXT ("%p\n"),
00082                        ACE_LIB_TEXT ("schedule_timer")),
00083                       -1);
00084 
00085   if (this->schedule_ualarm () == -1)
00086     return 0;
00087 
00088   return tid;
00089 }

template<class TQ>
int ACE_Async_Timer_Queue_Adapter< TQ >::schedule_ualarm void    [private, virtual]
 

Perform the logic to compute the new ualarm(2) setting.

Definition at line 46 of file Timer_Queue_Adapters.cpp.

References ACE_OS::gettimeofday, timer_queue_, ACE_OS::ualarm, and ACE_Time_Value::zero.

Referenced by handle_signal, and schedule.

00047 {
00048   ACE_Time_Value tv = this->timer_queue_.earliest_time ()
00049     - ACE_OS::gettimeofday ();
00050 
00051   // Beware of negative times and zero times (which cause problems for
00052   // <ualarm>).
00053   if (tv < ACE_Time_Value::zero)
00054     tv = ACE_Time_Value (0, 1);
00055 
00056   // @@ This code should be clever enough to avoid updating the
00057   // <ualarm> if we haven't actually changed the earliest time.
00058   // Schedule a new timer.
00059   ACE_OS::ualarm (tv);
00060   return 0;
00061 }

template<class TQ>
TQ & ACE_Async_Timer_Queue_Adapter< TQ >::timer_queue void   
 

Access the underlying <TIMER_QUEUE>.

Definition at line 19 of file Timer_Queue_Adapters.cpp.

References timer_queue_.

00020 {
00021   return this->timer_queue_;
00022 }


Member Data Documentation

template<class TQ>
ACE_Sig_Set ACE_Async_Timer_Queue_Adapter::mask_ [private]
 

Mask of signals to be blocked when we're servicing <SIGALRM>.

Definition at line 87 of file Timer_Queue_Adapters.h.

template<class TQ>
ACE_Sig_Handler ACE_Async_Timer_Queue_Adapter::sig_handler_ [private]
 

Handler for the <SIGALRM> signal, so that we can access our state without requiring any global variables.

Definition at line 80 of file Timer_Queue_Adapters.h.

template<class TQ>
TQ ACE_Async_Timer_Queue_Adapter::timer_queue_ [private]
 

Implementation of the timer queue (e.g., <ACE_Timer_List>, <ACE_Timer_Heap>, etc.).

Definition at line 84 of file Timer_Queue_Adapters.h.

Referenced by cancel, expire, handle_signal, schedule, schedule_ualarm, and timer_queue.


The documentation for this class was generated from the following files:
Generated on Mon Jun 16 12:44:57 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002