]> git.pond.sub.org Git - empserver/blobdiff - src/server/update.c
Update copyright notice
[empserver] / src / server / update.c
index 2704cad1d38f8140f3fbed220756ed46244b098a..06124f43df5356cffe0ca9e347fe0fa902919279 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2007, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2008, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
 #endif
 #include <time.h>
 #include "empthread.h"
+#include "game.h"
 #include "misc.h"
 #include "optlist.h"
 #include "player.h"
 #include "prototypes.h"
 #include "server.h"
 
-/*
- * Lock to synchronize player threads with the update.
- * Update takes it exclusive, commands take it shared.
- */
-empth_rwlock_t *update_lock;
-
-/*
- * Update is pending, player threads must give up update_lock ASAP.
- * This means they must not block while update_pending.
- */
-int update_pending;
-
 /*
  * Update is running.
  * Can be used to suppress messages, or direct them to bulletins.
@@ -86,8 +75,8 @@ update_init(void)
     if (update_get_schedule() < 0)
        exit(1);
 
-    update_lock = empth_rwlock_create("Update");
-    if (!update_lock)
+    play_lock = empth_rwlock_create("Update");
+    if (!play_lock)
        exit_nomem();
 
     dp = player_new(-1);
@@ -97,7 +86,7 @@ update_init(void)
     stacksize = 100000 +
 /* finish_sects */ WORLD_X * WORLD_Y * (2 * sizeof(double) +
                                        sizeof(char *));
-    update_thread = empth_create(PP_UPDATE, update_sched, stacksize, 0,
+    update_thread = empth_create(update_sched, stacksize, 0,
                                 "Update", dp);
     if (!update_thread)
        exit_nomem();
@@ -148,7 +137,7 @@ update_sched(void *unused)
        } else {
            logerror("No update scheduled");
            /* want to sleep forever, but empthread doesn't provide that */
-           while (empth_sleep(60 * 60 * 24) >= 0) ;
+           while (empth_sleep(time(NULL) + (60 * 60 * 24)) >= 0) ;
        }
 
        now = time(NULL);
@@ -205,7 +194,7 @@ update_run(void)
 {
     struct player *p;
 
-    update_pending = 1;
+    play_wrlock_wanted = 1;
     for (p = player_next(0); p != 0; p = player_next(p)) {
        if (p->state != PS_PLAYING)
            continue;
@@ -215,18 +204,18 @@ update_run(void)
            empth_wakeup(p->proc);
        }
     }
-    empth_rwlock_wrlock(update_lock);
+    empth_rwlock_wrlock(play_lock);
     if (*pre_update_hook) {
        if (run_hook(pre_update_hook, "pre-update")) {
-           update_pending = 0;
-           empth_rwlock_unlock(update_lock);
+           play_wrlock_wanted = 0;
+           empth_rwlock_unlock(play_lock);
            return;
        }
     }
     update_running = 1;
     update_main();
-    update_pending = update_running = 0;
-    empth_rwlock_unlock(update_lock);
+    play_wrlock_wanted = update_running = 0;
+    empth_rwlock_unlock(play_lock);
 }
 
 static int