(update_running): New.

(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.
This commit is contained in:
Markus Armbruster 2007-07-17 06:13:14 +00:00
parent c1a0a42024
commit e9cfbdc241
7 changed files with 33 additions and 14 deletions

View file

@ -38,6 +38,7 @@
extern int shutdown_pending; extern int shutdown_pending;
extern int update_pending; extern int update_pending;
extern int update_running;
extern empth_rwlock_t *update_lock; extern empth_rwlock_t *update_lock;
extern time_t update_time[]; extern time_t update_time[];

View file

@ -472,7 +472,7 @@ PR(int cn, char *format, ...)
newline = strrchr(buf, '\n') ? 1 : 0; newline = strrchr(buf, '\n') ? 1 : 0;
strcat(longline[cn], buf); strcat(longline[cn], buf);
if (newline) { if (newline) {
if (update_pending || (cn && cn != player->cnum)) if (update_running || (cn && cn != player->cnum))
typed_wu(0, cn, longline[cn], TEL_BULLETIN); typed_wu(0, cn, longline[cn], TEL_BULLETIN);
else else
pr_player(player, C_DATA, longline[cn]); pr_player(player, C_DATA, longline[cn]);
@ -524,7 +524,7 @@ mpr(int cn, char *format, ...)
(void)vsprintf(buf, format, ap); (void)vsprintf(buf, format, ap);
va_end(ap); va_end(ap);
if (cn) { if (cn) {
if (update_pending || cn != player->cnum) if (update_running || cn != player->cnum)
typed_wu(0, cn, buf, TEL_BULLETIN); typed_wu(0, cn, buf, TEL_BULLETIN);
else else
pr_player(player, C_DATA, buf); pr_player(player, C_DATA, buf);

View file

@ -94,7 +94,7 @@ setrel(natid us, natid them, int rel)
if (theirrel <= MOBILIZATION) { if (theirrel <= MOBILIZATION) {
rel = theirrel; rel = theirrel;
cost = 0; cost = 0;
} else if (us == player->cnum && !update_pending) { } else if (us == player->cnum && !update_running) {
if (mynp->nat_money < War_Cost) { if (mynp->nat_money < War_Cost) {
mpr(us, "You don't have the money!\n"); mpr(us, "You don't have the money!\n");
return RET_FAIL; return RET_FAIL;
@ -105,7 +105,7 @@ setrel(natid us, natid them, int rel)
return RET_FAIL; return RET_FAIL;
} }
if (rel >= oldrel) { if (rel >= oldrel) {
if (us == player->cnum && !update_pending) if (us == player->cnum && !update_running)
mpr(us, "No change required for that!\n"); mpr(us, "No change required for that!\n");
return RET_FAIL; return RET_FAIL;
} }
@ -116,7 +116,7 @@ setrel(natid us, natid them, int rel)
n_down = N_DECL_WAR; n_down = N_DECL_WAR;
} }
if (addendum && us == player->cnum && !update_pending) if (addendum && us == player->cnum && !update_running)
pr("%s\n", addendum); pr("%s\n", addendum);
mpr(us, "Diplomatic relations with %s %s to \"%s\".\n", mpr(us, "Diplomatic relations with %s %s to \"%s\".\n",
themname, whichway, relates[rel]); themname, whichway, relates[rel]);

View file

@ -139,7 +139,7 @@ shp_nav(struct emp_qelem *list, double *minmobp, double *maxmobp,
continue; continue;
} }
if (opt_SAIL) { if (opt_SAIL) {
if (*ship.shp_path && !update_pending) { if (*ship.shp_path && !update_running) {
shp_mess("has a sail path", mlp); shp_mess("has a sail path", mlp);
mpr(actor, "Use `sail <#> -' to reset\n"); mpr(actor, "Use `sail <#> -' to reset\n");
continue; continue;

View file

@ -74,7 +74,7 @@ telegram_is_new(natid to, struct telstr *tel)
is_new |= tel->tel_type != last_tel[to].tel_type; is_new |= tel->tel_type != last_tel[to].tel_type;
is_new |= tel->tel_from != last_tel[to].tel_from; 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; abs(tel->tel_date - last_tel[to].tel_date) > TEL_SECONDS;
last_tel[to].tel_type = tel->tel_type; last_tel[to].tel_type = tel->tel_type;
@ -104,7 +104,7 @@ wu(natid from, natid to, char *format, ...)
(void)vsprintf(buf, format, ap); (void)vsprintf(buf, format, ap);
va_end(ap); va_end(ap);
np = getnatp(from); np = getnatp(from);
if (update_pending) if (update_running)
return typed_wu(from, to, buf, TEL_UPDATE); return typed_wu(from, to, buf, TEL_UPDATE);
else if (np->nat_stat == STAT_GOD) else if (np->nat_stat == STAT_GOD)
return typed_wu(from, to, buf, TEL_BULLETIN); return typed_wu(from, to, buf, TEL_BULLETIN);

View file

@ -53,7 +53,7 @@ sct_do_upd_mob(struct sctstr *sp)
{ {
int etus; int etus;
if (do_upd_checking || update_pending) if (do_upd_checking || update_running)
return; return;
if (sp->sct_own == 0) if (sp->sct_own == 0)
return; return;
@ -73,7 +73,7 @@ shp_do_upd_mob(struct shpstr *sp)
{ {
int etus; int etus;
if (do_upd_checking || update_pending) if (do_upd_checking || update_running)
return; return;
if (sp->shp_own == 0) if (sp->shp_own == 0)
return; return;
@ -91,7 +91,7 @@ lnd_do_upd_mob(struct lndstr *lp)
{ {
int etus; int etus;
if (do_upd_checking || update_pending) if (do_upd_checking || update_running)
return; return;
if (lp->lnd_own == 0) if (lp->lnd_own == 0)
return; return;
@ -109,7 +109,7 @@ pln_do_upd_mob(struct plnstr *pp)
{ {
int etus; int etus;
if (do_upd_checking || update_pending) if (do_upd_checking || update_running)
return; return;
if (pp->pln_own == 0) if (pp->pln_own == 0)
return; return;

View file

@ -50,14 +50,31 @@
#define UPDATES 16 #define UPDATES 16
/*
* Lock to synchronize player threads with the update.
* Update takes it exclusive, commands take it shared.
*/
empth_rwlock_t *update_lock; 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; 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]; time_t update_time[UPDATES];
static time_t update_schedule_anchor; static time_t update_schedule_anchor;
static int update_wanted; static int update_wanted;
static empth_t *update_thread;
static int update_get_schedule(void); static int update_get_schedule(void);
static void update_sched(void *); static void update_sched(void *);
static void update_run(void); static void update_run(void);
@ -209,8 +226,9 @@ update_run(void)
return; return;
} }
} }
update_running = 1;
update_main(); update_main();
update_pending = 0; update_pending = update_running = 0;
empth_rwlock_unlock(update_lock); empth_rwlock_unlock(update_lock);
} }