diff options
| -rw-r--r-- | kc/core/arch_thread.c | 2 | ||||
| -rw-r--r-- | kc/core/task.c | 31 |
2 files changed, 19 insertions, 14 deletions
diff --git a/kc/core/arch_thread.c b/kc/core/arch_thread.c index 19e8908..180923d 100644 --- a/kc/core/arch_thread.c +++ b/kc/core/arch_thread.c @@ -62,8 +62,6 @@ void arch_swap_thread( struct kc_thread *outgoing, struct kc_thread *incoming) { - kprintf("swapping thread...\n"); - kprintf("stack pointer %p\n", incoming->kernel_stack_pointer); arch_swap_thread_stack(&outgoing->kernel_stack_pointer, incoming->kernel_stack_pointer); } diff --git a/kc/core/task.c b/kc/core/task.c index dc7e218..e5933bd 100644 --- a/kc/core/task.c +++ b/kc/core/task.c @@ -16,8 +16,6 @@ #include "arch_thread.h" -extern uint64_t *get_tss_rsp0(void); - static void lock_scheduler(void); static void unlock_scheduler(void); static void lock_preempt(void); @@ -70,14 +68,16 @@ static void *idle_thread_entry(void *) return nullptr; } -static void *sleepy_thread_entry(void *) +static void *sleepy_thread_entry(void *p) { + uint64_t sleep_nanoseconds = (uint64_t)p; int thread_slept_count = 0; while (true) { - sleep_thread(1000000000); + sleep_thread(sleep_nanoseconds); thread_slept_count++; + kprintf("thread slept %d times\n", thread_slept_count); } (void)thread_slept_count; @@ -100,8 +100,10 @@ noreturn void task_init(void) timesource->nanoseconds_delta()); idle_thread = create_thread(idle_thread_entry, nullptr); - struct kc_thread *sleepy_thread = create_thread(sleepy_thread_entry, nullptr); + struct kc_thread *sleepy_thread = create_thread(sleepy_thread_entry, (void *)3000000000); + struct kc_thread *sleepy_thread2 = create_thread(sleepy_thread_entry, (void *)5000000000); ready_thread_push(sleepy_thread); + ready_thread_push(sleepy_thread2); __asm__ volatile ("movq %%rsp, %0" : "=g"(boot_thread.kernel_stack_pointer) :); ready_thread_push(idle_thread); block_thread(BLOCKED); @@ -110,9 +112,19 @@ noreturn void task_init(void) PANIC(DEAD_END); } +static inline bool check_preempt_count() +{ + if (atomic_load(&preempt_switch_count) > 0) + { + return true; + } + + return false; +} + void task_schedule(void) { - if (atomic_load(&preempt_switch_count)) + if (check_preempt_count()) { preempt_switch_flag = true; return; @@ -134,10 +146,6 @@ void task_schedule(void) { return; } - else - { - // NULL statement????? idon't like - } } set_thread(this_thread); } @@ -162,7 +170,7 @@ static void unlock_scheduler(void) static void unlock_preempt(void) { - if (atomic_load(&preempt_switch_count) >= 1) + if (atomic_load(&preempt_switch_count) > 0) { preempt_switch_count--; } @@ -343,7 +351,6 @@ static int sleeping_thread_callback(uint64_t nanoseconds) if (this_thread->sleep_expiration <= nanoseconds) { - kprintf("thread awakened: %p\n", this_thread); this_thread->sleep_expiration = 0; unblock_thread(this_thread); } |
