fix: use a real fifo for yield

This commit is contained in:
Martin Eyben 2025-03-21 17:44:35 +01:00
parent 9e02e4ef67
commit c5c1b74906

View File

@ -48,12 +48,10 @@ int thread_yield(void) {
} }
TAILQ_REMOVE(&head, first, link); TAILQ_REMOVE(&head, first, link);
TAILQ_INSERT_TAIL(&head, first, link); TAILQ_INSERT_TAIL(&head, first, link);
if (first->id == running->id) {
return 0;
}
} while ((first->status & FINISHED) || } while ((first->status & FINISHED) ||
((first->status & WAITING) && !(((struct context_entry *)first->retvalue)->status & FINISHED))); ((first->status & WAITING) && !(((struct context_entry *)first->retvalue)->status & FINISHED)) ||
TRACE("PICKING %p", first); (first->id == running->id));
TRACE("PICKING %p (previous was %p)", first->id, running->id);
struct context_entry *old_runner = running; struct context_entry *old_runner = running;
running = first; running = first;
swapcontext(&old_runner->context, &running->context); 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->id = 0;
new_entry->status = 0; new_entry->status = 0;
new_entry->retvalue = 0; new_entry->retvalue = 0;
TAILQ_INSERT_HEAD(&head, new_entry, link); TAILQ_INSERT_TAIL(&head, new_entry, link);
running = new_entry; running = new_entry;
counter++; counter++;
new_entry = malloc(sizeof(*new_entry)); new_entry = malloc(sizeof(*new_entry));
@ -100,7 +98,7 @@ int thread_create(thread_t *newthread, void *(*func)(void *), void *funcarg) {
*newthread = new_entry; *newthread = new_entry;
makecontext(&new_entry->context, (void (*)(void)) thread_function_wrapper, 2, func, funcarg); makecontext(&new_entry->context, (void (*)(void)) thread_function_wrapper, 2, func, funcarg);
counter++; counter++;
TAILQ_INSERT_HEAD(&head, new_entry, link); TAILQ_INSERT_TAIL(&head, new_entry, link);
return 0; return 0;
} }