/*
* 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.
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);
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();
} 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);
{
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;
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