2023-03-09 19:55:52 +00:00
|
|
|
#include <socks/sched.h>
|
|
|
|
|
#include <socks/object.h>
|
2023-03-28 21:39:59 +01:00
|
|
|
#include <socks/cpu.h>
|
2023-03-09 19:55:52 +00:00
|
|
|
|
2023-04-12 20:17:11 +01:00
|
|
|
static struct object_type thread_type = {
|
2023-03-09 19:55:52 +00:00
|
|
|
.ob_name = "thread",
|
2023-04-12 20:17:11 +01:00
|
|
|
.ob_size = sizeof(struct thread),
|
2023-03-09 19:55:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
kern_status_t thread_object_type_init(void)
|
|
|
|
|
{
|
|
|
|
|
return object_type_register(&thread_type);
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-12 20:17:11 +01:00
|
|
|
struct thread *thread_alloc(void)
|
2023-03-09 19:55:52 +00:00
|
|
|
{
|
2023-04-12 20:17:11 +01:00
|
|
|
struct object *thread_obj = object_create(&thread_type);
|
2023-03-09 19:55:52 +00:00
|
|
|
if (!thread_obj) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2023-03-28 21:39:59 +01:00
|
|
|
|
2023-04-12 20:17:11 +01:00
|
|
|
struct thread *t = object_data(thread_obj);
|
2023-03-09 19:55:52 +00:00
|
|
|
memset(t, 0x00, sizeof *t);
|
|
|
|
|
return t;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-12 20:17:11 +01:00
|
|
|
void thread_free(struct thread *thr)
|
2023-03-09 19:55:52 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
2023-03-28 21:39:59 +01:00
|
|
|
|
2023-04-12 20:17:11 +01:00
|
|
|
struct thread *current_thread(void)
|
2023-03-28 21:39:59 +01:00
|
|
|
{
|
2023-04-12 20:17:11 +01:00
|
|
|
struct cpu_data *cpu = get_this_cpu();
|
2023-04-09 16:38:08 +01:00
|
|
|
if (!cpu) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-12 20:17:11 +01:00
|
|
|
struct thread *out = cpu->c_current_thread;
|
2023-03-28 21:39:59 +01:00
|
|
|
put_cpu(cpu);
|
|
|
|
|
return out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool need_resched(void)
|
|
|
|
|
{
|
|
|
|
|
return (current_thread()->tr_flags & THREAD_F_NEED_RESCHED) != 0;
|
|
|
|
|
}
|