long air_money[MAXNOC];
long tpops[MAXNOC];
-int update_pending = 0;
-
-/*ARGSUSED*/
void
-update_main(void *unused)
+update_main(void)
{
int etu = etu_per_update;
int n;
struct natstr *cnp;
struct natstr *np;
- if (CANT_HAPPEN(!update_pending))
- update_pending = 1;
-
logerror("production update (%d etus)", etu);
journal_update(etu);
mob_plane(etu);
mob_land(etu);
}
- player->proc = empth_self();
- player->cnum = 0;
- player->god = 1;
if (opt_AUTO_POWER)
update_power();
/* Clear all the telegram flags */
for (cn = 0; cn < MAXNOC; cn++)
clear_telegram_is_new(cn);
- update_pending = 0;
logerror("End update");
- player_delete(player);
- empth_exit();
- /*NOTREACHED*/
}
empth_sem_t *update_sem;
empth_rwlock_t *update_lock;
+int update_pending;
time_t update_time;
static void update_sched(void *);
void
update_init(void)
{
+ struct player *dp;
+ int stacksize;
+
update_sem = empth_sem_create("Update", 0);
update_lock = empth_rwlock_create("Update");
if (!update_sem || !update_lock)
exit_nomem();
- if (!empth_create(PP_SCHED, update_wait, 50 * 1024, 0,
- "UpdateWait", "Waits until players idle", NULL))
+ dp = player_new(-1);
+ if (!dp)
+ exit_nomem();
+ /* FIXME ancient black magic; figure out true stack need */
+ stacksize = 100000 +
+/* finish_sects */ WORLD_X * WORLD_Y * (2 * sizeof(double) +
+ sizeof(char *));
+ if (!empth_create(PP_UPDATE, update_wait, stacksize, 0,
+ "Update", "Updates the world", dp))
exit_nomem();
if (!empth_create(PP_SCHED, update_sched, 50 * 1024, 0,
update_wait(void *unused)
{
struct player *p;
- int stacksize;
- struct player *dp;
+
+ player->proc = empth_self();
+ player->cnum = 0;
+ player->god = 1;
while (1) {
empth_sem_wait(update_sem);
continue;
}
}
- /*
- * we rely on the fact that update's priority is the highest
- * in the land so it can finish before it yields.
- */
- dp = player_new(-1);
- if (!dp) {
- logerror("can't create dummy player for update");
- update_pending = 0;
- empth_rwlock_unlock(update_lock);
- continue;
- }
- stacksize = 100000 +
-/* finish_sects */ WORLD_X * WORLD_Y * (2 * sizeof(double) +
- sizeof(char *));
-
- empth_create(PP_UPDATE, update_main, stacksize, 0,
- "UpdateRun", "Updates the world", dp);
-
- while (update_pending)
- empth_yield(); /* FIXME cheesy! */
+ update_main();
update_pending = 0;
empth_rwlock_unlock(update_lock);
}