Adapts an ACE timer queue to be driven asynchronously using signals. More...
#include <Timer_Queue_Adapters.h>
Public Types | |
typedef TQ | TIMER_QUEUE |
Public Member Functions | |
ACE_Async_Timer_Queue_Adapter (ACE_Sig_Set *mask=0) | |
Constructor. | |
long | schedule (TYPE type, const void *act, const ACE_Time_Value &future_time, const ACE_Time_Value &interval=ACE_Time_Value::zero) |
int | cancel (long timer_id, const void **act=0) |
int | expire (void) |
TQ & | timer_queue (void) |
Return a reference to the underlying timer queue. | |
Private Member Functions | |
virtual int | schedule_ualarm (void) |
Perform the logic to compute the new ualarm(2) setting. | |
virtual int | handle_signal (int signum, siginfo_t *, ucontext_t *) |
Called back by SIGALRM handler. | |
Private Attributes | |
ACE_Sig_Handler | sig_handler_ |
TQ | timer_queue_ |
ACE_Sig_Set | mask_ |
Mask of signals to be blocked when we're servicing SIGALRM . |
Adapts an ACE timer queue to be driven asynchronously using signals.
This implementation uses the ACE_OS::ualarm call, to generate the SIGARLM signal that is caught by this class.
Definition at line 53 of file Timer_Queue_Adapters.h.
typedef TQ ACE_Async_Timer_Queue_Adapter< TQ, TYPE >::TIMER_QUEUE |
Definition at line 56 of file Timer_Queue_Adapters.h.
ACE_Async_Timer_Queue_Adapter< TQ, TYPE >::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 100 of file Timer_Queue_Adapters.cpp.
: mask_ (mask) { // The following code is necessary to selectively "block" certain // signals when SIGALRM is running. Also, we always restart system // calls that are interrupted by the signals. ACE_Sig_Action sa ((ACE_SignalHandler) 0, this->mask_, SA_RESTART); if (this->sig_handler_.register_handler (SIGALRM, this, &sa) == -1) ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("register_handler"))); }
int ACE_Async_Timer_Queue_Adapter< TQ, TYPE >::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 33 of file Timer_Queue_Adapters.cpp.
{ // Block designated signals. ACE_Sig_Guard sg (&this->mask_); ACE_UNUSED_ARG (sg); return this->timer_queue_.cancel (timer_id, act); }
int ACE_Async_Timer_Queue_Adapter< TQ, TYPE >::expire | ( | void | ) |
Dispatch all timers with expiry time at or before the current time. Returns the number of timers expired.
Definition at line 44 of file Timer_Queue_Adapters.cpp.
{ // Block designated signals. ACE_Sig_Guard sg (&this->mask_); ACE_UNUSED_ARG (sg); return this->timer_queue_.expire (); }
int ACE_Async_Timer_Queue_Adapter< TQ, TYPE >::handle_signal | ( | int | signum, | |
siginfo_t * | , | |||
ucontext_t * | ||||
) | [private, virtual] |
Called back by SIGALRM
handler.
Reimplemented from ACE_Event_Handler.
Definition at line 124 of file Timer_Queue_Adapters.cpp.
{ switch (signum) { case SIGALRM: { // Expire the pending timers. // @@ We need to figure out how to implement interval // timers... this->timer_queue_.expire (); // 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); /* NOTREACHED */ } }
long ACE_Async_Timer_Queue_Adapter< TQ, TYPE >::schedule | ( | TYPE | 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 72 of file Timer_Queue_Adapters.cpp.
{ ACE_UNUSED_ARG (act); ACE_UNUSED_ARG (interval); // Block designated signals. ACE_Sig_Guard sg (&this->mask_); ACE_UNUSED_ARG (sg); // @@ We still need to implement interval timers... long tid = this->timer_queue_.schedule (eh, act, future_time); if (tid == -1) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("schedule_timer")), -1); if (this->schedule_ualarm () == -1) return 0; return tid; }
int ACE_Async_Timer_Queue_Adapter< TQ, TYPE >::schedule_ualarm | ( | void | ) | [private, virtual] |
Perform the logic to compute the new ualarm(2) setting.
Definition at line 54 of file Timer_Queue_Adapters.cpp.
{ ACE_Time_Value tv = this->timer_queue_.earliest_time () - this->timer_queue_.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; }
TQ & ACE_Async_Timer_Queue_Adapter< TQ, TYPE >::timer_queue | ( | void | ) |
Return a reference to the underlying timer queue.
Definition at line 27 of file Timer_Queue_Adapters.cpp.
{ return this->timer_queue_; }
ACE_Sig_Set ACE_Async_Timer_Queue_Adapter< TQ, TYPE >::mask_ [private] |
Mask of signals to be blocked when we're servicing SIGALRM
.
Definition at line 105 of file Timer_Queue_Adapters.h.
ACE_Sig_Handler ACE_Async_Timer_Queue_Adapter< TQ, TYPE >::sig_handler_ [private] |
Handler for the SIGALRM
signal, so that we can access our state without requiring any global variables.
Definition at line 98 of file Timer_Queue_Adapters.h.
TQ ACE_Async_Timer_Queue_Adapter< TQ, TYPE >::timer_queue_ [private] |
Implementation of the timer queue (e.g., ACE_Timer_List, ACE_Timer_Heap, etc.).
Definition at line 102 of file Timer_Queue_Adapters.h.