]> git.pond.sub.org Git - empserver/blobdiff - src/server/main.c
Update copyright notice
[empserver] / src / server / main.c
index da02ccdf3edb609c38188b57df23ffab053a100a..cbf1008db6b35c4757afaa15715a27a30da4d8d8 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2011, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2012, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                Ken Stevens, Steve McClure, Markus Armbruster
  *
  *  Empire is free software: you can redistribute it and/or modify
 #include "empthread.h"
 #include "file.h"
 #include "journal.h"
-#include "land.h"
 #include "match.h"
 #include "misc.h"
-#include "nat.h"
-#include "nuke.h"
 #include "optlist.h"
 #include "plane.h"
 #include "player.h"
@@ -66,7 +63,6 @@
 #include "prototypes.h"
 #include "sect.h"
 #include "server.h"
-#include "ship.h"
 #include "version.h"
 
 static void ignore(void);
@@ -79,10 +75,16 @@ static void loc_NTInit(void);
 #endif
 
 /*
- * Lock to synchronize player threads with update and shutdown.
- * Update and shutdown takes it exclusive, commands take it shared.
+ * Lock to synchronize player threads with update.
+ * Update holds it exclusive, commands hold it shared.
  */
-empth_rwlock_t *play_lock;
+empth_rwlock_t *update_lock;
+/*
+ * Lock to synchronize player threads with shutdown.
+ * Shutdown holds it exclusive, player threads in state PS_PLAYING
+ * hold it shared.
+ */
+empth_rwlock_t *shutdown_lock;
 
 static char pidfname[] = "server.pid";
 
@@ -378,6 +380,11 @@ start_server(int flags)
     if (journal_startup() < 0)
        exit(1);
 
+    update_lock = empth_rwlock_create("Update");
+    shutdown_lock = empth_rwlock_create("Shutdown");
+    if (!update_lock || !shutdown_lock)
+       exit_nomem();
+
     market_init();
     update_init();
     empth_create(player_accept, 50 * 1024, flags, "AcceptPlayers", NULL);
@@ -410,7 +417,7 @@ void
 shutdwn(int sig)
 {
     struct player *p;
-    time_t now;
+    time_t now = time(NULL);
     int i;
 
     logerror("Shutdown commencing (cleaning up threads.)");
@@ -427,10 +434,10 @@ shutdwn(int sig)
        }
        empth_wakeup(p->proc);
     }
-    empth_rwlock_wrlock(play_lock);
 
-    now = time(NULL);
+    empth_rwlock_wrlock(shutdown_lock);
     empth_yield();
+
     for (i = 1; i <= 3 && player_next(NULL); i++) {
        logerror("Waiting for player threads to terminate\n");
        empth_sleep(now + i);