From 495b3fd9d43a0eee1ab9effbb021a9d7e2c4f52d Mon Sep 17 00:00:00 2001 From: Christian Cunningham Date: Wed, 16 Mar 2022 19:03:43 -0700 Subject: Added prepending to queues --- src/sys/schedule.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'src/sys') diff --git a/src/sys/schedule.c b/src/sys/schedule.c index c7ed212..0a62350 100644 --- a/src/sys/schedule.c +++ b/src/sys/schedule.c @@ -84,6 +84,25 @@ void push_to_queue(struct Thread* t, unsigned char type, unsigned char priority) entry->next = &queue->end; } +void prepend_to_queue(struct Thread* t, unsigned char type, unsigned char priority) +{ + struct ThreadEntry* entry = &thread_entries[t->offset]; + struct ThreadQueue* queue; + if (type == THREAD_READY) { + queue = &scheduler.ready[priority]; + } else if (type == THREAD_MWAIT) { + queue = &scheduler.mwait[priority]; + } else if (type == THREAD_SWAIT) { + queue = &scheduler.swait[priority]; + } else { + return; + } + entry->next = queue->start.next; + queue->start.next = entry; + if (entry->next->entry_type == END_ENTRY) + queue->end.next = entry; +} + struct ThreadEntry* pop_from_queue(unsigned char type, unsigned char priority) { struct ThreadEntry* entry = 0; @@ -410,6 +429,6 @@ void sched_mutex_resurrect(void* m) struct ThreadEntry* tentry = pop_from_queue(THREAD_READY, p); tentry->thread->priority = op; tentry->thread->old_priority = 0xFF; - push_to_queue(tentry->thread, THREAD_READY, op); + prepend_to_queue(tentry->thread, THREAD_READY, op); } } -- cgit v1.2.1