diff options
author | Christian Cunningham <cc@localhost> | 2022-03-16 19:03:43 -0700 |
---|---|---|
committer | Christian Cunningham <cc@localhost> | 2022-03-16 19:03:43 -0700 |
commit | 495b3fd9d43a0eee1ab9effbb021a9d7e2c4f52d (patch) | |
tree | f20489539a211a18380882e66dd4731457de21e8 /src | |
parent | 068ce025957171feee2971723e955650236ef1f1 (diff) |
Added prepending to queues
Diffstat (limited to 'src')
-rw-r--r-- | src/sys/schedule.c | 21 |
1 files changed, 20 insertions, 1 deletions
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); } } |