changeset 17971:54784619350b

Make CTRL-C to work in GUI with "system" calls. * libgui/src/thread-manager.cc (block_or_unblock_signal): Don't do anything on Win32 platform, as thread-specific signal handling is not supported. This allow to delay SetConsoleCtrlHandler after AllocConsole. (windows_thread_manager::interrupt): Call GenerateConsoleCtrlEvent instead of w32_raise_sigint.
author Michael Goffioul <michael.goffioul@gmail.com>
date Thu, 21 Nov 2013 13:14:03 -0500
parents f6e1be4ad923
children afeb233ea443
files libgui/src/thread-manager.cc
diffstat 1 files changed, 9 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/thread-manager.cc	Tue Nov 19 15:47:06 2013 -0500
+++ b/libgui/src/thread-manager.cc	Thu Nov 21 13:14:03 2013 -0500
@@ -48,7 +48,7 @@
 
   void interrupt (void)
   {
-    w32_raise_sigint ();
+    GenerateConsoleCtrlEvent (CTRL_C_EVENT, 0);
   }
 };
 
@@ -90,15 +90,20 @@
 static void
 block_or_unblock_signal (int how, int sig)
 {
+#if ! defined (__WIN32__) || defined (__CYGWIN__)
+  // Blocking/unblocking signals at thread level is only supported
+  // on platform with fully compliant POSIX threads. This is not
+  // supported on Win32. Moreover, we have to make sure that SIGINT
+  // handler is not installed before calling AllocConsole: installing
+  // a SIGINT handler internally calls SetConsoleCtrlHandler, which
+  // must be called after AllocConsole to be effective.
+
   sigset_t signal_mask;
 
   sigemptyset (&signal_mask);
 
   sigaddset (&signal_mask, sig);
 
-#if defined (__WIN32__) && ! defined (__CYGWIN__)
-  sigprocmask (how, &signal_mask, 0);
-#else
   pthread_sigmask (how, &signal_mask, 0);
 #endif
 }