From c5c1b7490673f117b7432b31fbf8e0dce578d601 Mon Sep 17 00:00:00 2001 From: Martin Eyben Date: Fri, 21 Mar 2025 17:44:35 +0100 Subject: [PATCH] fix: use a real fifo for yield --- src/thread/thread.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/thread/thread.c b/src/thread/thread.c index 4c9f740..66cbb94 100644 --- a/src/thread/thread.c +++ b/src/thread/thread.c @@ -48,12 +48,10 @@ int thread_yield(void) { } TAILQ_REMOVE(&head, first, link); TAILQ_INSERT_TAIL(&head, first, link); - if (first->id == running->id) { - return 0; - } } while ((first->status & FINISHED) || - ((first->status & WAITING) && !(((struct context_entry *)first->retvalue)->status & FINISHED))); - TRACE("PICKING %p", first); + ((first->status & WAITING) && !(((struct context_entry *)first->retvalue)->status & FINISHED)) || + (first->id == running->id)); + TRACE("PICKING %p (previous was %p)", first->id, running->id); struct context_entry *old_runner = running; running = first; swapcontext(&old_runner->context, &running->context); @@ -81,7 +79,7 @@ int thread_create(thread_t *newthread, void *(*func)(void *), void *funcarg) { new_entry->id = 0; new_entry->status = 0; new_entry->retvalue = 0; - TAILQ_INSERT_HEAD(&head, new_entry, link); + TAILQ_INSERT_TAIL(&head, new_entry, link); running = new_entry; counter++; new_entry = malloc(sizeof(*new_entry)); @@ -100,7 +98,7 @@ int thread_create(thread_t *newthread, void *(*func)(void *), void *funcarg) { *newthread = new_entry; makecontext(&new_entry->context, (void (*)(void)) thread_function_wrapper, 2, func, funcarg); counter++; - TAILQ_INSERT_HEAD(&head, new_entry, link); + TAILQ_INSERT_TAIL(&head, new_entry, link); return 0; }