]> git.pond.sub.org Git - empserver/blobdiff - src/server/main.c
Simplify checks whether player thread may sleep
[empserver] / src / server / main.c
index 1f66f98810f9e4eb2906b432e5b9c91f3e45ff40..336eb6a65d1e4c408b910b9271f4481bbdce08f8 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2008, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2009, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
@@ -31,7 +31,7 @@
  *     Dave Pare, 1994
  *     Steve McClure, 1996, 1998
  *     Doug Hay, 1998
- *     Ron Koenderink, 2004-2005
+ *     Ron Koenderink, 2004-2009
  *     Markus Armbruster, 2005-2008
  */
 
@@ -86,13 +86,6 @@ static void loc_NTTerm(void);
  */
 empth_rwlock_t *play_lock;
 
-/*
- * Is a thread attempting to take an exclusive play_lock?
- * Threads holding a shared play_lock must not sleep while this is
- * true.
- */
-int play_wrlock_wanted;
-
 static char pidfname[] = "server.pid";
 
 /* Run as daemon?  If yes, detach from controlling terminal etc. */
@@ -324,13 +317,14 @@ crash_dump(void)
     pid_t pid;
     int status;
 
+    fflush(NULL);
     pid = fork();
     if (pid < 0) {
        logerror("Can't fork for crash dump (%s)", strerror(errno));
        return;
     }
     if (pid == 0)
-       abort();                /* child */
+       raise(SIGABRT);         /* child */
 
     /* parent */
     while (waitpid(pid, &status, 0) < 0) {
@@ -381,7 +375,7 @@ start_server(int flags)
     if (journal_startup() < 0)
        exit(1);
 
-    empth_create(player_accept, 50 * 1024, flags, "AcceptPlayers", 0);
+    empth_create(player_accept, 50 * 1024, flags, "AcceptPlayers", NULL);
 
     market_init();
     update_init();
@@ -420,12 +414,12 @@ shutdwn(int sig)
 
     logerror("Shutdown commencing (cleaning up threads.)");
 
-    play_wrlock_wanted = 1;
-    for (p = player_next(0); p != 0; p = player_next(p)) {
+    for (p = player_next(NULL); p; p = player_next(p)) {
        if (p->state != PS_PLAYING)
            continue;
        pr_flash(p, "Server shutting down...\n");
        p->state = PS_SHUTDOWN;
+       p->may_sleep = PLAYER_SLEEP_NEVER;
        p->aborted++;
        if (p->command) {
            pr_flash(p, "Shutdown aborting command\n");