(update_run): Set it.
Replace incorrect uses of update_pending by update_running, fixing
buggy behavior while the update was trying to gain control:
(sct_do_upd_mob, shp_do_upd_mob, lnd_do_upd_mob, pln_do_upd_mob):
MOB_ACCESS mobility update was skipped.
(telegram_is_new): Fix recognition of new telegrams by timestamp.
(wu): Bulletins got misfiled as production reports.
(shp_nav): Sail path got ignored.
(setrel): Declaration of war failed silently with SLOW_WAR enabled.
Messages got suppressed.
(PR, mpr): Messages got misdirected to bulletins.
extern int shutdown_pending;
extern int update_pending;
+extern int update_running;
extern empth_rwlock_t *update_lock;
extern time_t update_time[];
newline = strrchr(buf, '\n') ? 1 : 0;
strcat(longline[cn], buf);
if (newline) {
- if (update_pending || (cn && cn != player->cnum))
+ if (update_running || (cn && cn != player->cnum))
typed_wu(0, cn, longline[cn], TEL_BULLETIN);
else
pr_player(player, C_DATA, longline[cn]);
(void)vsprintf(buf, format, ap);
va_end(ap);
if (cn) {
- if (update_pending || cn != player->cnum)
+ if (update_running || cn != player->cnum)
typed_wu(0, cn, buf, TEL_BULLETIN);
else
pr_player(player, C_DATA, buf);
if (theirrel <= MOBILIZATION) {
rel = theirrel;
cost = 0;
- } else if (us == player->cnum && !update_pending) {
+ } else if (us == player->cnum && !update_running) {
if (mynp->nat_money < War_Cost) {
mpr(us, "You don't have the money!\n");
return RET_FAIL;
return RET_FAIL;
}
if (rel >= oldrel) {
- if (us == player->cnum && !update_pending)
+ if (us == player->cnum && !update_running)
mpr(us, "No change required for that!\n");
return RET_FAIL;
}
n_down = N_DECL_WAR;
}
- if (addendum && us == player->cnum && !update_pending)
+ if (addendum && us == player->cnum && !update_running)
pr("%s\n", addendum);
mpr(us, "Diplomatic relations with %s %s to \"%s\".\n",
themname, whichway, relates[rel]);
continue;
}
if (opt_SAIL) {
- if (*ship.shp_path && !update_pending) {
+ if (*ship.shp_path && !update_running) {
shp_mess("has a sail path", mlp);
mpr(actor, "Use `sail <#> -' to reset\n");
continue;
is_new |= tel->tel_type != last_tel[to].tel_type;
is_new |= tel->tel_from != last_tel[to].tel_from;
- is_new |= !update_pending && /* sometimes updates take a long time */
+ is_new |= !update_running && /* updates can take a long time */
abs(tel->tel_date - last_tel[to].tel_date) > TEL_SECONDS;
last_tel[to].tel_type = tel->tel_type;
(void)vsprintf(buf, format, ap);
va_end(ap);
np = getnatp(from);
- if (update_pending)
+ if (update_running)
return typed_wu(from, to, buf, TEL_UPDATE);
else if (np->nat_stat == STAT_GOD)
return typed_wu(from, to, buf, TEL_BULLETIN);
{
int etus;
- if (do_upd_checking || update_pending)
+ if (do_upd_checking || update_running)
return;
if (sp->sct_own == 0)
return;
{
int etus;
- if (do_upd_checking || update_pending)
+ if (do_upd_checking || update_running)
return;
if (sp->shp_own == 0)
return;
{
int etus;
- if (do_upd_checking || update_pending)
+ if (do_upd_checking || update_running)
return;
if (lp->lnd_own == 0)
return;
{
int etus;
- if (do_upd_checking || update_pending)
+ if (do_upd_checking || update_running)
return;
if (pp->pln_own == 0)
return;
#define UPDATES 16
+/*
+ * Lock to synchronize player threads with the update.
+ * Update takes it exclusive, commands take it shared.
+ */
empth_rwlock_t *update_lock;
-static empth_t *update_thread;
+
+/*
+ * 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.
+ */
+int update_running;
+
time_t update_time[UPDATES];
+
static time_t update_schedule_anchor;
static int update_wanted;
+static empth_t *update_thread;
+
static int update_get_schedule(void);
static void update_sched(void *);
static void update_run(void);
return;
}
}
+ update_running = 1;
update_main();
- update_pending = 0;
+ update_pending = update_running = 0;
empth_rwlock_unlock(update_lock);
}