From d500a7071c1de27e9bc0fea4551faae7370c064d Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Tue, 24 Jul 2007 05:13:31 +0000 Subject: [PATCH] Remove the concept of thread priorities from empthread.h. Only LWP supports priorities. Update synchronization used to rely on them, which naturally worked only with LWP (#1504036). With that fixed, no uses of priorities remained, but a minor bug did: players could starve out threads with priorities below PP_PLAYER, i.e. delete_lostitems() and player_kill_idle(). Closes #1458175: (empth_create): Remove parameter prio. Callers changed. Also gets rid of misleading comments in pthread.c and ntthread.c. (PP_MAIN, PP_UPDATE, PP_SHUTDOWN, PP_SCHED, PP_TIMESTAMP, PP_PLAYER) (PP_ACCEPT, PP_KILLIDLE): Remove. (empth_init, empth_create) [EMPTH_LWP]: Pass priority 1. --- include/empthread.h | 15 +-------------- src/lib/empthread/lwp.c | 6 +++--- src/lib/empthread/ntthread.c | 3 +-- src/lib/empthread/pthread.c | 8 +------- src/lib/player/accept.c | 3 +-- src/server/main.c | 9 +++------ src/server/marketup.c | 3 +-- src/server/shutdown.c | 2 +- src/server/update.c | 2 +- 9 files changed, 13 insertions(+), 38 deletions(-) diff --git a/include/empthread.h b/include/empthread.h index 0bb46bf93..3bd23d66f 100644 --- a/include/empthread.h +++ b/include/empthread.h @@ -51,18 +51,6 @@ #include -/* thread priorities */ -enum { - PP_MAIN = 7, - PP_UPDATE = 6, - PP_SHUTDOWN = 5, - PP_SCHED = 4, - PP_TIMESTAMP = 2, - PP_PLAYER = 3, - PP_ACCEPT = 3, - PP_KILLIDLE = 2 -}; - #ifdef EMPTH_LWP #include "lwp.h" @@ -123,7 +111,6 @@ int empth_init(void **ctx, int flags); /* * Create a new thread. - * PRIO is the scheduling priority. * ENTRY is the entry point. It will be called with argument UD. * Thread stack is at least SIZE bytes. * FLAGS should be the same as were passed to empth_init(), or zero. @@ -134,7 +121,7 @@ int empth_init(void **ctx, int flags); * Yield the processor. * Return the thread, or NULL on error. */ -empth_t *empth_create(int prio, void (*entry)(void *), +empth_t *empth_create(void (*entry)(void *), int size, int flags, char *name, void *ud); /* diff --git a/src/lib/empthread/lwp.c b/src/lib/empthread/lwp.c index c8d1d0a7e..d1c0a0231 100644 --- a/src/lib/empthread/lwp.c +++ b/src/lib/empthread/lwp.c @@ -54,18 +54,18 @@ empth_init(void **ctx, int flags) sigaddset(&set, SIGHUP); sigaddset(&set, SIGINT); sigaddset(&set, SIGTERM); - lwpInitSystem(PP_MAIN, ctx, flags, &set); + lwpInitSystem(1, ctx, flags, &set); return 0; } empth_t * -empth_create(int prio, void (*entry)(void *), int size, int flags, +empth_create(void (*entry)(void *), int size, int flags, char *name, void *ud) { if (!flags) flags = empth_flags; - return lwpCreate(prio, entry, size, flags, name, 0, 0, ud); + return lwpCreate(1, entry, size, flags, name, 0, 0, ud); } empth_t * diff --git a/src/lib/empthread/ntthread.c b/src/lib/empthread/ntthread.c index a7115435c..4b921e7a7 100644 --- a/src/lib/empthread/ntthread.c +++ b/src/lib/empthread/ntthread.c @@ -418,7 +418,6 @@ empth_init(void **ctx_ptr, int flags) * * Create a new thread. * - * prio - priority, not particularly useful in our context. * entry - entry point function for thread. * size - stack size. * flags - debug control. @@ -429,7 +428,7 @@ empth_init(void **ctx_ptr, int flags) * It is also passed to the entry function... */ empth_t * -empth_create(int prio, void (*entry)(void *), int size, int flags, +empth_create(void (*entry)(void *), int size, int flags, char *name, void *ud) { empth_t *pThread = NULL; diff --git a/src/lib/empthread/pthread.c b/src/lib/empthread/pthread.c index 9681b1abc..3c3679175 100644 --- a/src/lib/empthread/pthread.c +++ b/src/lib/empthread/pthread.c @@ -180,14 +180,8 @@ empth_init(void **ctx_ptr, int flags) } -/* - * prio can be used for setting scheeduling policy but... - * it seems to be optional in POSIX threads and Solaris - * for example just ignores it. - * More then that priority is not needed even in lwp threads. - */ empth_t * -empth_create(int prio, void (*entry)(void *), int size, int flags, +empth_create(void (*entry)(void *), int size, int flags, char *name, void *ud) { pthread_t t; diff --git a/src/lib/player/accept.c b/src/lib/player/accept.c index fa52d8507..909604ae2 100644 --- a/src/lib/player/accept.c +++ b/src/lib/player/accept.c @@ -224,7 +224,6 @@ player_accept(void *unused) /* budget */ + MAX(WORLD_X * WORLD_Y / 2 * sizeof(int) * 7, /* power */ MAXNOC * sizeof(struct powstr)); sprintf(buf, "Player (fd #%d)", ns); - empth_create(PP_PLAYER, player_login, stacksize, - 0, buf, np); + empth_create(player_login, stacksize, 0, buf, np); } } diff --git a/src/server/main.c b/src/server/main.c index 77183386c..1141008cf 100644 --- a/src/server/main.c +++ b/src/server/main.c @@ -331,12 +331,9 @@ start_server(int flags) if (journal_startup() < 0) exit(1); - empth_create(PP_ACCEPT, player_accept, (50 * 1024), flags, - "AcceptPlayers", 0); - empth_create(PP_KILLIDLE, player_kill_idle, (50 * 1024), flags, - "KillIdle", 0); - empth_create(PP_TIMESTAMP, delete_lostitems, (50 * 1024), flags, - "DeleteItems", 0); + empth_create(player_accept, 50 * 1024, flags, "AcceptPlayers", 0); + empth_create(player_kill_idle, 50 * 1024, flags, "KillIdle", 0); + empth_create(delete_lostitems, 50 * 1024, flags, "DeleteItems", 0); market_init(); update_init(); diff --git a/src/server/marketup.c b/src/server/marketup.c index d1df31a0d..22ca6771d 100644 --- a/src/server/marketup.c +++ b/src/server/marketup.c @@ -71,7 +71,6 @@ market_init(void) dp = player_new(-1); if (!dp) exit_nomem(); - if (!empth_create(PP_UPDATE, market_update, 50 * 1024, 0, - "MarketUpdate", dp)) + if (!empth_create(market_update, 50 * 1024, 0, "MarketUpdate", dp)) exit_nomem(); } diff --git a/src/server/shutdown.c b/src/server/shutdown.c index 8e0b68a73..2e83bb5fa 100644 --- a/src/server/shutdown.c +++ b/src/server/shutdown.c @@ -65,7 +65,7 @@ shutdown_initiate(int mins_from_now) mins_from_now); /* FIXME wake up shutdown_sequence() */ } else { - if (!empth_create(PP_SHUTDOWN, shutdown_sequence, 50 * 1024, 0, + if (!empth_create(shutdown_sequence, 50 * 1024, 0, "shutdownSeq", NULL)) return -1; } diff --git a/src/server/update.c b/src/server/update.c index 1240cc31d..77571904d 100644 --- a/src/server/update.c +++ b/src/server/update.c @@ -85,7 +85,7 @@ update_init(void) stacksize = 100000 + /* finish_sects */ WORLD_X * WORLD_Y * (2 * sizeof(double) + sizeof(char *)); - update_thread = empth_create(PP_UPDATE, update_sched, stacksize, 0, + update_thread = empth_create(update_sched, stacksize, 0, "Update", dp); if (!update_thread) exit_nomem(); -- 2.43.0