]> git.pond.sub.org Git - empserver/blobdiff - src/lib/lwp/sig.c
Update copyright notice
[empserver] / src / lib / lwp / sig.c
index 9800a97ba603274476e9e868e97a2290d25b2cfa..49d2e049154dfdbcedec1b5a303c6c1b85315a57 100644 (file)
@@ -1,11 +1,11 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1994-2006, Dave Pare, Jeff Bailey, Thomas Ruschak,
- *                           Ken Stevens, Steve McClure
+ *  Copyright (C) 1994-2012, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *                Ken Stevens, Steve McClure, Markus Armbruster
  *
- *  This program is free software; you can redistribute it and/or modify
+ *  Empire is free software: you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
+ *  the Free Software Foundation, either version 3 of the License, or
  *  (at your option) any later version.
  *
  *  This program is distributed in the hope that it will be useful,
@@ -14,8 +14,7 @@
  *  GNU General Public License for more details.
  *
  *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *
  *  ---
  *
  *  ---
  *
  *  sig.c: Wait for signals
- * 
+ *
  *  Known contributors to this file:
- *     Markus Armbruster, 2006
+ *     Markus Armbruster, 2006-2007
  */
 
 #include <config.h>
 
 #include <errno.h>
+#include <stddef.h>
 #include <signal.h>
-#include "misc.h"
 #include "lwp.h"
 #include "lwpint.h"
 
-/* Signals awaited by lwpSigWait() */
-static sigset_t *LwpSigAwaited;
-
 /*
- * Signals from LwpSigAwaited catched so far
+ * Signals catched so far.
  * Access only with signals blocked!
  */
 static sigset_t LwpSigCatched;
 
+/*
+ * LwpSigCatched changed since last
+ */
+static sig_atomic_t LwpSigCheck;
+
 /* The thread waiting for signals in lwpSigWait() */
 static struct lwpProc *LwpSigWaiter;
 
-/* Where to return the signal number to the thread in lwpSigWait() */
-static int *LwpSigPtr;
-
 static void lwpCatchAwaitedSig(int);
 
 /*
@@ -81,6 +79,7 @@ static void
 lwpCatchAwaitedSig(int sig)
 {
     sigaddset(&LwpSigCatched, sig);
+    LwpSigCheck = 1;
 }
 
 /*
@@ -120,14 +119,14 @@ lwpSigWait(sigset_t *set, int *sig)
 
     if (CANT_HAPPEN(LwpSigWaiter))
        return EBUSY;
-    res = lwpGetSig(set);
-    if (res <= 0) {
+    for (;;) {
+       LwpSigCheck = 0;
+       res = lwpGetSig(set);
+       if (res > 0)
+           break;
        lwpStatus(LwpCurrent, "Waiting for signals");
-       LwpSigAwaited = set;
-       LwpSigPtr = sig;
        LwpSigWaiter = LwpCurrent;
        lwpReschedule();
-       return 0;
     }
     *sig = res;
     return 0;
@@ -140,13 +139,7 @@ lwpSigWait(sigset_t *set, int *sig)
 void
 lwpSigWakeup(void)
 {
-    int res;
-
-    if (!LwpSigWaiter)
-       return;
-    res = lwpGetSig(LwpSigAwaited);
-    if (res > 0) {
-       *LwpSigPtr = res;
+    if (LwpSigWaiter && LwpSigCheck) {
        lwpReady(LwpSigWaiter);
        LwpSigWaiter = NULL;
     }