From: Markus Armbruster Date: Tue, 16 Jan 2007 20:06:27 +0000 (+0000) Subject: Fuse update wait thread and update thread: X-Git-Tag: v4.3.10~274 X-Git-Url: http://git.pond.sub.org/?p=empserver;a=commitdiff_plain;h=02584d8a5068e0a93b66a3fa10893c49186037fe Fuse update wait thread and update thread: (update_main): No longer a thread entry point. Remove the parameter. Remove *player setup. Don't terminate the thread when done. (update_pending): Move to src/server/update.c. (update_wait): Call update_main() instead of running it in its own thread. Set up *player for it. (update_init): Create the fused update thread instead of the update wait thread. --- diff --git a/include/server.h b/include/server.h index 69b30cf37..c1c03928f 100644 --- a/include/server.h +++ b/include/server.h @@ -50,7 +50,7 @@ void delete_lostitems(void *); void market_update(void *); void mobility_check(void *); void player_kill_idle(void *); -void update_main(void *); +void update_main(void); void update_init(void); void shutdown_sequence(void *); void update_force(void *); diff --git a/src/lib/update/main.c b/src/lib/update/main.c index 3564460e6..17042a617 100644 --- a/src/lib/update/main.c +++ b/src/lib/update/main.c @@ -49,11 +49,8 @@ long lnd_money[MAXNOC]; 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; @@ -63,9 +60,6 @@ update_main(void *unused) struct natstr *cnp; struct natstr *np; - if (CANT_HAPPEN(!update_pending)) - update_pending = 1; - logerror("production update (%d etus)", etu); journal_update(etu); @@ -76,9 +70,6 @@ update_main(void *unused) mob_plane(etu); mob_land(etu); } - player->proc = empth_self(); - player->cnum = 0; - player->god = 1; if (opt_AUTO_POWER) update_power(); @@ -180,9 +171,5 @@ update_main(void *unused) /* 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*/ } diff --git a/src/server/update.c b/src/server/update.c index 75241f5d7..67e8404f5 100644 --- a/src/server/update.c +++ b/src/server/update.c @@ -49,6 +49,7 @@ empth_sem_t *update_sem; empth_rwlock_t *update_lock; +int update_pending; time_t update_time; static void update_sched(void *); @@ -58,13 +59,23 @@ static int run_hook(char *cmd, char *name); 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, @@ -131,8 +142,10 @@ static void 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); @@ -154,26 +167,7 @@ update_wait(void *unused) 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); }