summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ace/ACE.h3
-rw-r--r--ace/ACE.i10
-rw-r--r--ace/Handle_Set.cpp13
-rw-r--r--ace/Handle_Set.h3
-rw-r--r--ace/Handle_Set.i6
-rw-r--r--ace/Log_Msg.cpp4
-rw-r--r--ace/Log_Priority.h2
-rw-r--r--ace/Log_Record.cpp14
-rw-r--r--ace/Log_Record.h10
-rw-r--r--ace/OS.cpp15
-rw-r--r--ace/OS.h2
-rw-r--r--ace/README1
-rw-r--r--ace/Signal.cpp25
-rw-r--r--ace/Signal.h5
-rw-r--r--ace/Signal.i10
-rw-r--r--ace/Timer_Queue_T.cpp3
-rw-r--r--ace/config-sco-5.0.0-fsu-pthread.h2
-rw-r--r--ace/config-sco-5.0.0-mit-pthread.h1
-rw-r--r--ace/config-sco-5.0.0-nothread.h2
-rw-r--r--tests/Async_Timer_Queue_Test.cpp209
20 files changed, 232 insertions, 108 deletions
diff --git a/ace/ACE.h b/ace/ACE.h
index 33059209543..dfacd105a67 100644
--- a/ace/ACE.h
+++ b/ace/ACE.h
@@ -500,6 +500,9 @@ public:
// the same process. The uniqueness of this name is therefore only
// valid for the life of <object>.
+ static u_long log2 (u_long num);
+ // Computes the base 2 logarithm of <num>.
+
private:
ACE (void);
// Ensure we can't define an instance of this class...
diff --git a/ace/ACE.i b/ace/ACE.i
index 8d00aed2d7c..d6d3398a053 100644
--- a/ace/ACE.i
+++ b/ace/ACE.i
@@ -65,3 +65,13 @@ ACE::get_flags (ACE_HANDLE handle)
return ACE_OS::fcntl (handle, F_GETFL, 0);
}
+inline u_long
+ACE::log2 (u_long num)
+{
+ for (u_long log = 0;
+ num > 0;
+ log++)
+ num >>= 1;
+
+ return log;
+}
diff --git a/ace/Handle_Set.cpp b/ace/Handle_Set.cpp
index ce5ce1af3fa..b0000cce45f 100644
--- a/ace/Handle_Set.cpp
+++ b/ace/Handle_Set.cpp
@@ -80,8 +80,8 @@ ACE_Handle_Set::ACE_Handle_Set (const ACE_FD_SET_TYPE &fd_mask)
// speed up the count.
#if defined (ACE_HAS_LONG_FDMASK)
-// If there are platforms where fd_mask isn't typedef'd to "int" we'll
-// have to use the following code.
+// If there are platforms where fd_mask isn't typedef'd to a 4 byte
+// quantify we'll have to use the following code.
int
ACE_Handle_Set::count_bits (u_long n) const
@@ -89,16 +89,23 @@ ACE_Handle_Set::count_bits (u_long n) const
ACE_TRACE ("ACE_Handle_Set::count_bits");
int rval = 0;
- for (int i = 0; n != 0; i++)
+ while (n > 0)
{
+#if defined (ACE_HAS_HANDLE_SET_OPTIMIZED_FOR_SELECT)
+ rval++;
+ n &= n - 1;
+#else
rval += ACE_Handle_Set::nbits_[n & 0xff];
n >>= 8;
+#endif /* ACE_HAS_HANDLE_SET_OPTIMIZED_FOR_SELECT */
}
return rval;
}
#else
+// Otherwise we can use the following.
+
int
ACE_Handle_Set::count_bits (u_long n) const
{
diff --git a/ace/Handle_Set.h b/ace/Handle_Set.h
index b62cc4ca216..1024ba863c4 100644
--- a/ace/Handle_Set.h
+++ b/ace/Handle_Set.h
@@ -61,7 +61,8 @@ public:
// Synchronize the underlying FD_SET with the MAX_FD and the SIZE.
operator fd_set *();
- // Returns a pointer to the underlying fd_set.
+ // Returns a pointer to the underlying <fd_set>. Returns 0 if
+ // <size_> == 0.
void dump (void) const;
// Dump the state of an object.
diff --git a/ace/Handle_Set.i b/ace/Handle_Set.i
index 839e567ad2a..ef4de0115a8 100644
--- a/ace/Handle_Set.i
+++ b/ace/Handle_Set.i
@@ -90,7 +90,11 @@ ACE_INLINE
ACE_Handle_Set::operator fd_set *()
{
ACE_TRACE ("ACE_Handle_Set::operator ACE_FD_SET_TYPE *");
- return (fd_set *) &this->mask_;
+
+ if (this->size_ > 0)
+ return (fd_set*) &this->mask_;
+ else
+ return (fd_set*) NULL;
}
ACE_INLINE ACE_HANDLE
diff --git a/ace/Log_Msg.cpp b/ace/Log_Msg.cpp
index d456063cb73..50f1d89a479 100644
--- a/ace/Log_Msg.cpp
+++ b/ace/Log_Msg.cpp
@@ -932,7 +932,9 @@ ACE_Log_Msg::log (const char *format_str,
ACE_Str_Buf log_msg ((void *) &log_record,
int (log_record.length ()));
#if defined (ACE_HAS_STREAM_PIPES)
- result = message_queue_.send (int (log_record.type ()),
+ // Try to use the putpmsg() API if possible in order to
+ // ensure correct message queueing according to priority.
+ result = message_queue_.send (int (log_record.priority ()),
&log_msg);
#elif !defined (ACE_WIN32)
result = message_queue_.send (log_msg);
diff --git a/ace/Log_Priority.h b/ace/Log_Priority.h
index 3f7e96a0211..dc05f6df1b3 100644
--- a/ace/Log_Priority.h
+++ b/ace/Log_Priority.h
@@ -24,7 +24,7 @@ enum ACE_Log_Priority
//
// = DESCRIPTION
// These values are defined using powers of two so that it's
- // possible to form a mask to turn the on or off dynamically.
+ // possible to form a mask to turn them on or off dynamically.
{
// = Note, this first argument *must* start at 1!
diff --git a/ace/Log_Record.cpp b/ace/Log_Record.cpp
index bab66d2c50f..f6f4fea8794 100644
--- a/ace/Log_Record.cpp
+++ b/ace/Log_Record.cpp
@@ -12,6 +12,20 @@
ACE_ALLOC_HOOK_DEFINE(ACE_Log_Record)
+u_long
+ACE_Log_Record::priority (void) const
+{
+ ACE_TRACE ("ACE_Log_Record::priority");
+ return ACE::log2 (this->type_);
+}
+
+void
+ACE_Log_Record::priority (u_long p)
+{
+ ACE_TRACE ("ACE_Log_Record::priority");
+ this->type_ = ACE::log2 (p);
+}
+
void
ACE_Log_Record::dump (void) const
{
diff --git a/ace/Log_Record.h b/ace/Log_Record.h
index bc3844c48d4..ff9dc122d41 100644
--- a/ace/Log_Record.h
+++ b/ace/Log_Record.h
@@ -86,6 +86,16 @@ public:
void type (long);
// Set the type of the <Log_Record>.
+ u_long priority (void) const;
+ // Get the priority of the <Log_Record> <type_>. This is computed
+ // as the base 2 logarithm of <type_> (which must be a power of 2,
+ // as defined by the enums in <ACE_Log_Priority>).
+
+ void priority (u_long num);
+ // Set the priority of the <Log_Record> <type_> (which must be a
+ // power of 2, as defined by the enums in <ACE_Log_Priority>). This
+ // <type_> is stored as the base 2 logarithm of <num>.
+
long length (void) const;
// Get the length of the <Log_Record>.
diff --git a/ace/OS.cpp b/ace/OS.cpp
index d5bb7ed9f3c..cce112dbf39 100644
--- a/ace/OS.cpp
+++ b/ace/OS.cpp
@@ -86,17 +86,10 @@ void
ACE_Time_Value::dump (void) const
{
// ACE_TRACE ("ACE_Time_Value::dump");
-#if 0
- if (tv.usec () < 0 || tv.sec () < 0)
- stream << "-";
-
- stream << dec << abs (int (tv.sec ())) << "."
-// << setw (6) << setfill ('0')
- << dec << abs (int (tv.usec ()));
-// I assume
- inline int abs(int d) { return (d>0)?d:-d; }
- is defined somewhere */
-#endif /* 0 */
+ ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
+ ACE_DEBUG ((LM_DEBUG, "\ntv_sec_ = %d", this->tv_.tv_sec));
+ ACE_DEBUG ((LM_DEBUG, "\ntv_usec_ = %d\n", this->tv_.tv_usec));
+ ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
}
void
diff --git a/ace/OS.h b/ace/OS.h
index d2c237aa3e8..209710a4332 100644
--- a/ace/OS.h
+++ b/ace/OS.h
@@ -303,7 +303,7 @@ private:
// enabled or disabled.
// Efficiently returns the least power of two >= X...
-#define ACE_POW(X) ((!X)?1:(X-=1,X|=X>>1,X|=X>>2,X|=X>>4,X|=X>>8,X|=X>>16,(++X)))
+#define ACE_POW(X) (((X) == 0)?1:(X-=1,X|=X>>1,X|=X>>2,X|=X>>4,X|=X>>8,X|=X>>16,(++X)))
#define ACE_EVEN(NUM) (((NUM) & 1) == 0)
#define ACE_ODD(NUM) (((NUM) & 1) == 1)
#define ACE_BIT_ENABLED(WORD, BIT) (((WORD) & (BIT)) != 0)
diff --git a/ace/README b/ace/README
index 06c9d8900a4..0fd5373f972 100644
--- a/ace/README
+++ b/ace/README
@@ -65,6 +65,7 @@ ACE_HAS_EXCEPTIONS Compiler supports C++ exception handling
ACE_HAS_GETPAGESIZE Platform supports getpagesize() call (otherwise, ACE_PAGE_SIZE must be defined, except on Win32)
ACE_HAS_GETRUSAGE Platform supports the getrusage() system call.
ACE_HAS_GNU_CSTRING_H Denotes that GNU has cstring.h as standard which redefines memchr()
+ACE_HAS_HANDLE_SET_OPTIMIZED_FOR_SELECT Optimize ACE_Handle_Set::count_bits for select() operations (common case)
ACE_HAS_HI_RES_TIMER Compiler/platform supports SunOS high resolution timers
ACE_HAS_INLINED_OSCALLS Inline all the static class OS methods to remove call overhead
ACE_HAS_IP_MULTICAST Platform supports IP multicast
diff --git a/ace/Signal.cpp b/ace/Signal.cpp
index 6b4d69a7af5..34235a124e0 100644
--- a/ace/Signal.cpp
+++ b/ace/Signal.cpp
@@ -145,6 +145,25 @@ ACE_Sig_Action::ACE_Sig_Action (ACE_SignalHandler sig_handler,
ACE_OS::sigaction (signum, &this->sa_, 0);
}
+ACE_Sig_Action::ACE_Sig_Action (ACE_SignalHandler sig_handler,
+ int signum,
+ ACE_Sig_Set &sig_mask,
+ int sig_flags)
+{
+ // ACE_TRACE ("ACE_Sig_Action::ACE_Sig_Action");
+ this->sa_.sa_flags = sig_flags;
+
+ // Structure assignment...
+ this->sa_.sa_mask = sig_mask.sigset ();
+
+#if !defined(ACE_HAS_TANDEM_SIGNALS)
+ this->sa_.sa_handler = ACE_SignalHandlerV (sig_handler);
+#else
+ this->sa_.sa_handler = (void (*)()) ACE_SignalHandlerV (sig_handler);
+#endif /* !ACE_HAS_TANDEM_SIGNALS */
+ ACE_OS::sigaction (signum, &this->sa_, 0);
+}
+
ACE_ALLOC_HOOK_DEFINE(ACE_Sig_Handler)
void
@@ -246,7 +265,7 @@ ACE_Sig_Handler::remove_handler (int signum,
if (ACE_Sig_Handler::in_range (signum))
{
- ACE_Sig_Action sa (SIG_DFL, 0, -1); // Define the default disposition.
+ ACE_Sig_Action sa (SIG_DFL, (sigset_t *) 0); // Define the default disposition.
if (new_disp == 0)
new_disp = &sa;
@@ -284,7 +303,7 @@ ACE_Sig_Handler::dispatch (int signum,
if (eh != 0 && eh->handle_signal (signum, siginfo, ucontext) == -1)
{
// Define the default disposition.
- ACE_Sig_Action sa (SIG_DFL, 0, -1);
+ ACE_Sig_Action sa (SIG_DFL, (sigset_t *) 0);
ACE_Sig_Handler::signal_handlers_[signum] = 0;
@@ -586,7 +605,7 @@ ACE_Sig_Handlers::remove_handler (int signum,
// register the new disposition or restore the default
// disposition.
- ACE_Sig_Action sa (SIG_DFL, 0, -1);
+ ACE_Sig_Action sa (SIG_DFL, (sigset_t *) 0);
if (new_disp == 0)
new_disp = &sa;
diff --git a/ace/Signal.h b/ace/Signal.h
index 164fbd4c39a..7c851869eea 100644
--- a/ace/Signal.h
+++ b/ace/Signal.h
@@ -87,6 +87,10 @@ public:
int signum,
sigset_t *sigmask = 0,
int flags = 0);
+ ACE_Sig_Action (ACE_SignalHandler handler,
+ int signum,
+ ACE_Sig_Set &sigmask,
+ int flags = 0);
ACE_Sig_Action (const ACE_Sig_Action &s);
ACE_Sig_Action (struct sigaction *);
@@ -113,6 +117,7 @@ public:
// = Set/get current signal mask.
void mask (sigset_t *);
+ void mask (ACE_Sig_Set &);
sigset_t *mask (void);
// = Set/get current signal handler (pointer to function).
diff --git a/ace/Signal.i b/ace/Signal.i
index 2dbcf710238..b14818db0ff 100644
--- a/ace/Signal.i
+++ b/ace/Signal.i
@@ -101,7 +101,15 @@ ACE_INLINE void
ACE_Sig_Action::mask (sigset_t *ss)
{
ACE_TRACE ("ACE_Sig_Action::mask");
- this->sa_.sa_mask = *ss; // Structure assignment
+ if (ss != 0)
+ this->sa_.sa_mask = *ss; // Structure assignment
+}
+
+ACE_INLINE void
+ACE_Sig_Action::mask (ACE_Sig_Set &ss)
+{
+ ACE_TRACE ("ACE_Sig_Action::mask");
+ this->sa_.sa_mask = ss.sigset (); // Structure assignment
}
ACE_INLINE ACE_SignalHandler
diff --git a/ace/Timer_Queue_T.cpp b/ace/Timer_Queue_T.cpp
index 1d52d885ace..06d5a3c75f8 100644
--- a/ace/Timer_Queue_T.cpp
+++ b/ace/Timer_Queue_T.cpp
@@ -16,13 +16,12 @@ ACE_Timer_Node_T<TYPE>::dump (void) const
{
ACE_TRACE ("ACE_Timer_Node_T::dump");
ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
- // ACE_DEBUG ((LM_DEBUG, "\type_ = %x", this->type_));
ACE_DEBUG ((LM_DEBUG, "\nact_ = %x", this->act_));
this->timer_value_.dump ();
this->interval_.dump ();
ACE_DEBUG ((LM_DEBUG, "\nprev_ = %x", this->prev_));
ACE_DEBUG ((LM_DEBUG, "\nnext_ = %x", this->next_));
- ACE_DEBUG ((LM_DEBUG, "\ntimer_id_ = %d", this->timer_id_));
+ ACE_DEBUG ((LM_DEBUG, "\ntimer_id_ = %d\n", this->timer_id_));
ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
}
diff --git a/ace/config-sco-5.0.0-fsu-pthread.h b/ace/config-sco-5.0.0-fsu-pthread.h
index 821bb9adb2f..b619e407d3c 100644
--- a/ace/config-sco-5.0.0-fsu-pthread.h
+++ b/ace/config-sco-5.0.0-fsu-pthread.h
@@ -21,7 +21,7 @@
#define ACE_TEMPLATES_REQUIRE_SOURCE
#define ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION
#define ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES
-
+#define ACE_HAS_LONG_FDMASK
#define ACE_LACKS_SYSCALL
#define ACE_LACKS_STRRECVFD
#define ACE_NEEDS_FTRUNCATE
diff --git a/ace/config-sco-5.0.0-mit-pthread.h b/ace/config-sco-5.0.0-mit-pthread.h
index 6ffb3cbcc7a..281bff9ab9a 100644
--- a/ace/config-sco-5.0.0-mit-pthread.h
+++ b/ace/config-sco-5.0.0-mit-pthread.h
@@ -22,6 +22,7 @@
#define ACE_LACKS_PWD_FUNCTIONS
#define ACE_TEMPLATES_REQUIRE_SOURCE
+#define ACE_HAS_LONG_FDMASK
#define ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION
#define ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES
diff --git a/ace/config-sco-5.0.0-nothread.h b/ace/config-sco-5.0.0-nothread.h
index c4f40dd9ed4..2b6c38336d5 100644
--- a/ace/config-sco-5.0.0-nothread.h
+++ b/ace/config-sco-5.0.0-nothread.h
@@ -49,6 +49,8 @@
// Platform supports System V IPC (most versions of UNIX, but not Win32)
#define ACE_HAS_SYSV_IPC
+#define ACE_HAS_LONG_FDMASK
+
// Platform supports recvmsg and sendmsg.
#define ACE_HAS_MSG
diff --git a/tests/Async_Timer_Queue_Test.cpp b/tests/Async_Timer_Queue_Test.cpp
index 5ff7323b7b7..9dd1b525452 100644
--- a/tests/Async_Timer_Queue_Test.cpp
+++ b/tests/Async_Timer_Queue_Test.cpp
@@ -30,15 +30,80 @@ sig_atomic_t sigint = 0;
// This is our main timer list. Right now, it doesn't know anything
// about signals.
-static ACE_Timer_List timer_list;
+class Async_Timer_List : public ACE_Timer_List
+{
+public:
+ Async_Timer_List (void);
+ // Register the SIGALRM handler.
+
+ virtual long schedule (const TYPE &type,
+ const void *act,
+ const ACE_Time_Value &delay,
+ const ACE_Time_Value &interval = ACE_Time_Value::zero);
+
+private:
+ static void handler (int signum);
+ // Called back by SIGALRM handler.
+
+ static Async_Timer_List timer_list;
+ // Keep a static instance of ourselves (until we add Reactor
+ // support).
+};
+
+// Static instance.
+Async_Timer_List Async_Timer_List::timer_list;
+
+long
+Async_Timer_List::schedule (const TYPE &type,
+ const void *act,
+ const ACE_Time_Value &delay,
+ const ACE_Time_Value &interval = ACE_Time_Value::zero)
+{
+ long tid = ACE_Timer_List::schedule (eh,
+ 0,
+ delay);
+
+ if (tid == -1)
+ ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "schedule_timer"), -1);
+
+ ACE_Time_Value tv = this->earliest_time () - this->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);
+
+ // Schedule a new timer.
+ ACE_OS::ualarm (tv);
+ return 0;
+}
+
+Async_Timer_List::Async_Timer_List (void)
+{
+ // The following code is necessary to selectively "block" all
+ // signals when SIGALRM is running. Also, we always restart system
+ // calls that are interrupted by the signals.
+
+ // Block *all* signals when the SIGARLM handler is running!
+ ACE_Set_Set ss (1);
+
+ ACE_Sig_Action sa ((ACE_SignalHandler) Async_Timer_List::handler,
+ SIGALRM,
+ ss,
+ SA_RESTART);
+ ACE_UNUSED_ARG (sa);
+}
// This is our signal handler function. It gets invoked
// asynchronously when SIGINT, SIGALRM, or SIGQUIT gets called.
static void
-handler (int signum)
+Async_Timer_Queue::handler (int signum)
{
ACE_DEBUG ((LM_DEBUG, "handling signal %S\n", signum));
- sigint = signum == SIGINT;
switch (signum)
{
@@ -46,14 +111,8 @@ handler (int signum)
{
int expired_timers;
- ACE_Sig_Set ss;
- ss.sig_add (SIGINT);
-
- // Prevent SIGINT from occurring while we're handling SIGALRM.
- ACE_Sig_Guard sg (&ss);
-
// Expire the pending timers.
- expired_timers = timer_list.expire ();
+ expired_timers = Async_Timer_List::timer_list.expire ();
if (expired_timers > 0)
ACE_DEBUG ((LM_DEBUG,
@@ -63,37 +122,15 @@ handler (int signum)
expired_timers));
// Only schedule a new timer if there is one in the list.
- if (timer_list.is_empty () == 0)
- ACE_OS::ualarm (timer_list.earliest_time () - timer_list.gettimeofday ());
+ if (Async_Timer_List::timer_list.is_empty () == 0)
+ ACE_OS::ualarm (Async_Timer_List::timer_list.earliest_time ()
+ - timer_list.gettimeofday ());
break;
}
+ default:
+ ACE_ERROR ((LM_ERROR, "unexpected signal %S\n", signum));
/* NOTREACHED */
- case SIGINT:
- {
- ACE_DEBUG ((LM_DEBUG, "begin dumping timer queue\n"));
-
- ACE_Sig_Set ss;
- ss.sig_add (SIGALRM);
-
- // Prevent SIGALRM from occurring while we're handling
- // SIGINT.
- ACE_Sig_Guard sg (&ss);
-
- for (ACE_Timer_List_Iterator iter (timer_list);
- iter.item () != 0;
- iter.next ())
- iter.item ()->dump ();
-
- ACE_DEBUG ((LM_DEBUG, "end dumping timer queue\n"));
-
- break;
- /* NOTREACHED */
- }
- case SIGQUIT:
- ACE_DEBUG ((LM_DEBUG, "shutting down on SIGQUIT%a\n", 1));
- /* NOTREACHED */
- break;
}
}
@@ -143,36 +180,12 @@ parse_commands (char *buf)
ACE_Event_Handler *eh;
ACE_NEW_RETURN (eh, Timer_Handler, -1);
- ACE_Sig_Set ss;
- ss.sig_add (SIGALRM);
- ss.sig_add (SIGINT);
-
- {
- // Prevent SIGALRM and SIGINT from occurring while we're
- // scheduling a timer.
- ACE_Sig_Guard sg (&ss);
-
- long tid = timer_list.schedule (eh, 0,
- timer_list.gettimeofday () + tv);
-
- if (tid == -1)
- ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "schedule_timer"), -1);
-
- tv = timer_list.earliest_time () - timer_list.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);
-
- // Schedule a new timer.
- ACE_OS::ualarm (tv);
+ long tid = timer_list.schedule (eh, 0,
+ timer_list.gettimeofday () + tv);
+ if (tid == -1)
+ ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "schedule_timer"), -1);
+
break;
/* NOTREACHED */
}
@@ -180,14 +193,6 @@ parse_commands (char *buf)
{
const void *act;
- ACE_Sig_Set ss;
- ss.sig_add (SIGALRM);
- ss.sig_add (SIGINT);
-
- // Prevent SIGALRM and SIGINT from occurring while we're
- // scheduling a timer.
- ACE_Sig_Guard sg (&ss);
-
if (timer_list.cancel (value, &act) == -1)
ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "cancel_timer"), -1);
@@ -202,6 +207,52 @@ parse_commands (char *buf)
return 0;
}
+static void
+handler (int signum)
+{
+ ACE_DEBUG ((LM_DEBUG, "handling signal %S\n", signum));
+ sigint = signum == SIGINT;
+
+ switch (signum)
+ {
+ /* NOTREACHED */
+ case SIGINT:
+ {
+ ACE_DEBUG ((LM_DEBUG, "begin dumping timer queue\n"));
+
+ for (ACE_Timer_List_Iterator iter (Async_Timer_List::timer_list);
+ iter.item () != 0;
+ iter.next ())
+ iter.item ()->dump ();
+
+ ACE_DEBUG ((LM_DEBUG, "end dumping timer queue\n"));
+
+ break;
+ /* NOTREACHED */
+ }
+ case SIGQUIT:
+ ACE_DEBUG ((LM_DEBUG, "shutting down on SIGQUIT%a\n", 1));
+ /* NOTREACHED */
+ break;
+ }
+}
+
+static void
+register_signal_handlers (void)
+{
+ // Register SIGQUIT (never blocked).
+ ACE_Sig_Action sa ((ACE_SignalHandler) handler, SIGQUIT);
+
+ // Don't let the SIGALRM interrupt the SIGINT handler!
+ ACE_Set_Set ss;
+ ss.add_sig (SIGALRM);
+
+ ACE_Sig_Action sa ((ACE_SignalHandler) handler,
+ SIGALRM,
+ ss,
+ SA_RESTART);
+}
+
static char menu[] =
"****\n"
"1) schedule_timer <usecs> \n"
@@ -215,16 +266,10 @@ main (int, char *[])
{
// ACE_START_TEST ("Timer_Queue_Test");
#if defined (ACE_HAS_UALARM)
- ACE_Sig_Action sa ((ACE_SignalHandler) handler);
- ACE_UNUSED_ARG (sa);
-
- // Register the signal handlers.
- sa.register_action (SIGINT);
- sa.register_action (SIGALRM);
- sa.register_action (SIGQUIT);
-
ACE_DEBUG ((LM_DEBUG, "%s", menu));
+ register_signal_handler ();
+
for (;;)
{
char buf[BUFSIZ];