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

@@ -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;
}