aboutsummaryrefslogtreecommitdiff
path: root/kernel/sys
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
parente733d37ee2aee3a5f3850ab336d588f814bb134c (diff)
Don't schedule if you don't have to
Diffstat (limited to 'kernel/sys')
-rw-r--r--kernel/sys/core.c4
-rw-r--r--kernel/sys/schedule.c22
2 files changed, 17 insertions, 9 deletions
diff --git a/kernel/sys/core.c b/kernel/sys/core.c
index 4812b00..c06ed4b 100644
--- a/kernel/sys/core.c
+++ b/kernel/sys/core.c
@@ -10,6 +10,7 @@
#include <sys/core.h>
#include <sys/power.h>
#include <sys/schedule.h>
+#include <tests/test.h>
#include <usr/main.h>
#include <util/mutex.h>
#include <util/status.h>
@@ -39,5 +40,6 @@ void sysinit(void)
// Start Scheduler
init_scheduler();
- add_thread(main, 0, 0);
+ add_thread(test_entry, 0, 2);
+ //add_thread(main, 0, 0);
}
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;
}