From: kosmirror <kos...@us...> - 2025-09-06 17:33:25
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "A pseudo Operating System for the Dreamcast.". The branch, master has been updated via c2350046b3111d6550a8ccb583a0f21fc15b0c29 (commit) from 05037ccd3d7318d9f2c1cd8e436adea24501e759 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit c2350046b3111d6550a8ccb583a0f21fc15b0c29 Author: QuzarDC <qu...@co...> Date: Fri Sep 5 01:49:39 2025 -0400 genwait: Keep queues in order by thread priority. Currently, new waiting threads are always added to the end of their genwait tailq and the first thread in the tailq is the first woken. This means that unless a thread is being woken and readded (like can happen with a `genwait_wake_all`) they will always be awoken based on how long they have been waiting. The downside to this method is that it ignores thread priorities, which should be the controlling factor in which thread gets woken first. By inserting into the queue by priority order, wakes will now happen based on priority rather than time waiting. The mild overhead of seeking through the waiting queues should be outweighed greatly by allowing priority management via thread priorities. ----------------------------------------------------------------------- Summary of changes: kernel/thread/genwait.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/kernel/thread/genwait.c b/kernel/thread/genwait.c index 3653edf5..bc874c2c 100644 --- a/kernel/thread/genwait.c +++ b/kernel/thread/genwait.c @@ -69,7 +69,7 @@ static kthread_t *tq_next(void) { } int genwait_wait(void *obj, const char *mesg, int timeout, void (*callback)(void *)) { - kthread_t *me; + kthread_t *me, *t; /* Twiddle interrupt state */ if(irq_inside_int()) { @@ -95,8 +95,17 @@ int genwait_wait(void *obj, const char *mesg, int timeout, void (*callback)(void me->wait_callback = callback; - /* Insert us on the appropriate wait queue */ - TAILQ_INSERT_TAIL(&slpque[LOOKUP(obj)], me, thdq); + /* Go through and find where to insert */ + TAILQ_FOREACH(t, &slpque[LOOKUP(obj)], thdq) { + if(me->prio < t->prio) { + TAILQ_INSERT_BEFORE(t, me, thdq); + break; + } + } + + /* We got to the end of the list, so insert at end */ + if(!t) + TAILQ_INSERT_TAIL(&slpque[LOOKUP(obj)], me, thdq); /* Block us until we're signaled */ return thd_block_now(&me->context); hooks/post-receive -- A pseudo Operating System for the Dreamcast. |