aboutsummaryrefslogtreecommitdiff
path: root/kernel/sys/schedule.c
diff options
context:
space:
mode:
authorChristian Cunningham <cc@localhost>2022-03-25 23:59:05 -0700
committerChristian Cunningham <cc@localhost>2022-03-25 23:59:05 -0700
commit32ef93110fc993f24540bdcff6c3d88c47cd64c1 (patch)
tree0ac9b4fa0258b0f3c9f2506b5f42a19fffa0629e /kernel/sys/schedule.c
parente733d37ee2aee3a5f3850ab336d588f814bb134c (diff)
Don't schedule if you don't have to
Diffstat (limited to 'kernel/sys/schedule.c')
-rw-r--r--kernel/sys/schedule.c22
1 files changed, 14 insertions, 8 deletions
diff --git a/kernel/sys/schedule.c b/kernel/sys/schedule.c
index 9b6d46e..3157c5d 100644
--- a/kernel/sys/schedule.c
+++ b/kernel/sys/schedule.c
@@ -418,12 +418,12 @@ void sched_semaphore_yield(void* s)
push_thread_to_queue(rt->value, THREAD_SWAIT, priority);
}
-void sched_mutex_resurrect(void* m)
+unsigned long sched_mutex_resurrect(void* m)
{
// Find any mutex to resurrect
struct Entry* prev = find_mutex_wait_next(m);
if (prev == 0)
- return;
+ return 0;
struct Entry* entry = prev->next;
struct Thread* thread = entry->value;
// Resurrect the thread
@@ -431,7 +431,7 @@ void sched_mutex_resurrect(void* m)
// Remove from wait queue
entry = remove_next_from_queue(prev);
if (entry == 0)
- return;
+ return 1;
// Add to ready queue
push_thread_to_queue(entry->value, THREAD_READY, ((struct Thread*)entry->value)->priority);
// Demote current thread
@@ -445,15 +445,19 @@ void sched_mutex_resurrect(void* m)
((struct Thread*)tentry->value)->old_priority = 0xFF;
prepend_thread_to_queue(tentry->value, THREAD_READY, op);
}
+ return 1;
}
-void sched_semaphore_resurrect(void* s, unsigned long count)
+unsigned long sched_semaphore_resurrect(void* s, unsigned long count)
{
- while (count--) {
+ unsigned long cnt = count;
+ while (cnt) {
// Find any signal/ semaphore to resurrect
struct Entry* prev = find_signal_wait_next(s);
- if (prev == 0)
- return;
+ if (prev == 0 && count == cnt)
+ return 0;
+ else if (prev == 0)
+ return 1;
struct Entry* entry = prev->next;
struct Thread* thread = entry->value;
// Resurrect the thread
@@ -461,8 +465,10 @@ void sched_semaphore_resurrect(void* s, unsigned long count)
// Remove from wait queue
entry = remove_next_from_queue(prev);
if (entry == 0)
- return;
+ return 1;
// Add to ready queue
push_thread_to_queue(entry->value, THREAD_READY, ((struct Thread*)entry->value)->priority);
+ cnt--;
}
+ return 1;
}