sched: add current_task(), current_thread(), and preempt_disable/enable()

This commit is contained in:
2023-03-28 21:39:59 +01:00
parent e0e6f4a9ae
commit 7d003da960
6 changed files with 65 additions and 3 deletions

View File

@@ -26,9 +26,11 @@ kern_status_t sched_init(void)
return status;
}
thread_t *this_thread = QUEUE_CONTAINER(thread_t, tr_threads, queue_first(&kernel_task()->t_threads));
cpu_data_t *this_cpu = get_this_cpu();
runqueue_init(&this_cpu->c_rq);
this_cpu->c_current_task = kernel_task();
this_cpu->c_current_thread = this_thread;
put_cpu(this_cpu);
printk("sched: initialised");

View File

@@ -77,3 +77,8 @@ task_t *task_from_pid(unsigned int pid)
spin_unlock_irqrestore(&task_list_lock, flags);
return t;
}
task_t *current_task(void)
{
return current_thread()->tr_parent;
}

View File

@@ -1,5 +1,6 @@
#include <socks/sched.h>
#include <socks/object.h>
#include <socks/cpu.h>
static object_type_t thread_type = {
.ob_name = "thread",
@@ -17,7 +18,7 @@ thread_t *thread_alloc(void)
if (!thread_obj) {
return NULL;
}
thread_t *t = object_data(thread_obj);
memset(t, 0x00, sizeof *t);
return t;
@@ -27,3 +28,16 @@ void thread_free(thread_t *thr)
{
}
thread_t *current_thread(void)
{
cpu_data_t *cpu = get_this_cpu();
thread_t *out = cpu->c_current_thread;
put_cpu(cpu);
return out;
}
bool need_resched(void)
{
return (current_thread()->tr_flags & THREAD_F_NEED_RESCHED) != 0;
}