]> git.pond.sub.org Git - empserver/blobdiff - src/server/update.c
Simplify checks whether player thread may sleep
[empserver] / src / server / update.c
index 0b20f03139b88a877982bc989f3e24ab832b5953..7b4a4b676ee3ef17b4bf9f67a6a19e27eb5477b5 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-2009, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
@@ -26,7 +26,7 @@
  *  ---
  *
  *  update.c: Update scheduler
- * 
+ *
  *  Known contributors to this file:
  *     Dave Pare, 1994
  *     Steve McClure, 1996
@@ -63,7 +63,6 @@ static empth_t *update_thread;
 static int update_get_schedule(void);
 static void update_sched(void *);
 static void update_run(void);
-static int run_hook(char *cmd, char *name);
 
 void
 update_init(void)
@@ -137,7 +136,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);
@@ -194,12 +193,12 @@ update_run(void)
 {
     struct player *p;
 
-    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;
        if (p->command) {
            pr_flash(p, "Update aborting command\n");
+           p->may_sleep = PLAYER_SLEEP_NEVER;
            p->aborted = 1;
            empth_wakeup(p->proc);
        }
@@ -207,24 +206,23 @@ update_run(void)
     empth_rwlock_wrlock(play_lock);
     if (*pre_update_hook) {
        if (run_hook(pre_update_hook, "pre-update")) {
-           play_wrlock_wanted = 0;
            empth_rwlock_unlock(play_lock);
            return;
        }
     }
     update_running = 1;
     update_main();
-    play_wrlock_wanted = update_running = 0;
+    update_running = 0;
     empth_rwlock_unlock(play_lock);
 }
 
-static int
+int
 run_hook(char *cmd, char *name)
 {
     int status;
-    
+
     fflush(NULL);
-    
+
     status = system(cmd);
     if (status == 0)
        ;                       /* successful exit */