diff src/audacious/signals.c @ 2486:113f75c7b0ce trunk

[svn] - make SIGTERM handler always work.
author yaz
date Wed, 07 Feb 2007 21:08:20 -0800
parents ad1d7687814c
children 021321cb5426
line wrap: on
line diff
--- a/src/audacious/signals.c	Wed Feb 07 18:38:48 2007 -0800
+++ b/src/audacious/signals.c	Wed Feb 07 21:08:20 2007 -0800
@@ -33,6 +33,9 @@
 #include "ui_main.h"
 #include "signals.h"
 
+GCond *exit_cond;
+GMutex *exit_mutex;
+
 typedef void (*SignalHandler) (gint);
 
 static SignalHandler
@@ -103,19 +106,24 @@
 sigterm_handler (gint signal_number)
 {
     cfg.terminate = TRUE;
+    g_cond_signal(exit_cond);
 }
 
-static gboolean
-signal_process_events (gpointer data)
+static void *
+signal_process_events (void *data)
 {
-    if (cfg.terminate == TRUE)
-    {
-        g_message("Audacious has received SIGTERM and is shutting down.");
-        mainwin_quit_cb();
-        return FALSE;
+    while (1) {
+        if (cfg.terminate == TRUE)
+        {
+            g_print("Audacious has received SIGTERM and is shutting down.\n");
+            mainwin_quit_cb();
+        }
+        g_mutex_lock(exit_mutex);
+        g_cond_wait(exit_cond, exit_mutex);
+        g_mutex_unlock(exit_mutex);
     }
 
-    return TRUE;
+    return NULL;
 }
 
 void 
@@ -124,6 +132,9 @@
     char *magic;
     magic = getenv("AUD_ENSURE_BACKTRACE");
 
+    exit_cond = g_cond_new();
+    exit_mutex = g_mutex_new();
+
     signal_install_handler(SIGPIPE, signal_empty_handler);
     signal_install_handler(SIGINT, sigterm_handler);
     signal_install_handler(SIGTERM, sigterm_handler);
@@ -133,5 +144,6 @@
     if (magic == NULL)
         signal_install_handler(SIGSEGV, sigsegv_handler);
 
-    g_timeout_add(100, signal_process_events, NULL);
+    g_thread_create(signal_process_events, NULL, FALSE, NULL);
+
 }