]> git.pond.sub.org Git - empserver/commitdiff
Fuse update wait thread and update thread:
authorMarkus Armbruster <armbru@pond.sub.org>
Tue, 16 Jan 2007 20:06:27 +0000 (20:06 +0000)
committerMarkus Armbruster <armbru@pond.sub.org>
Tue, 16 Jan 2007 20:06:27 +0000 (20:06 +0000)
(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.

include/server.h
src/lib/update/main.c
src/server/update.c

index 69b30cf37b716d4b865fbe6a4be9527081d53ef7..c1c03928f62c25eb9c1526a3c35ad97528681780 100644 (file)
@@ -50,7 +50,7 @@ void delete_lostitems(void *);
 void market_update(void *);
 void mobility_check(void *);
 void player_kill_idle(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 *);
 void update_init(void);
 void shutdown_sequence(void *);
 void update_force(void *);
index 3564460e62114645cf987a044849b123279f2273..17042a617567bb8ba4bd28d803036dc2e52b0ffd 100644 (file)
@@ -49,11 +49,8 @@ long lnd_money[MAXNOC];
 long air_money[MAXNOC];
 long tpops[MAXNOC];
 
 long air_money[MAXNOC];
 long tpops[MAXNOC];
 
-int update_pending = 0;
-
-/*ARGSUSED*/
 void
 void
-update_main(void *unused)
+update_main(void)
 {
     int etu = etu_per_update;
     int n;
 {
     int etu = etu_per_update;
     int n;
@@ -63,9 +60,6 @@ update_main(void *unused)
     struct natstr *cnp;
     struct natstr *np;
 
     struct natstr *cnp;
     struct natstr *np;
 
-    if (CANT_HAPPEN(!update_pending))
-        update_pending = 1;
-
     logerror("production update (%d etus)", etu);
     journal_update(etu);
 
     logerror("production update (%d etus)", etu);
     journal_update(etu);
 
@@ -76,9 +70,6 @@ update_main(void *unused)
        mob_plane(etu);
        mob_land(etu);
     }
        mob_plane(etu);
        mob_land(etu);
     }
-    player->proc = empth_self();
-    player->cnum = 0;
-    player->god = 1;
 
     if (opt_AUTO_POWER)
        update_power();
 
     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);
     /* Clear all the telegram flags */
     for (cn = 0; cn < MAXNOC; cn++)
        clear_telegram_is_new(cn);
-    update_pending = 0;
     logerror("End update");
     logerror("End update");
-    player_delete(player);
-    empth_exit();
-    /*NOTREACHED*/
 }
 }
index 75241f5d70222af342af1a3ada6e4895df9323c7..67e8404f5532441ce8ac47186ce8db75f8050571 100644 (file)
@@ -49,6 +49,7 @@
 
 empth_sem_t *update_sem;
 empth_rwlock_t *update_lock;
 
 empth_sem_t *update_sem;
 empth_rwlock_t *update_lock;
+int update_pending;
 time_t update_time;
 
 static void update_sched(void *);
 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)
 {
 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();
 
     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,
        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;
 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);
 
     while (1) {
        empth_sem_wait(update_sem);
@@ -154,26 +167,7 @@ update_wait(void *unused)
                continue;
            }
        }
                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);
     }
        update_pending = 0;
        empth_rwlock_unlock(update_lock);
     }