65 lines
1.4 KiB
C
65 lines
1.4 KiB
C
|
|
#ifndef KERNEL_THREAD_H_
|
||
|
|
#define KERNEL_THREAD_H_
|
||
|
|
|
||
|
|
#include <kernel/msg.h>
|
||
|
|
#include <kernel/object.h>
|
||
|
|
#include <kernel/vm-controller.h>
|
||
|
|
|
||
|
|
#define THREAD_KSTACK_ORDER VM_PAGE_4K
|
||
|
|
|
||
|
|
enum thread_state {
|
||
|
|
THREAD_READY = 1,
|
||
|
|
THREAD_SLEEPING = 2,
|
||
|
|
THREAD_STOPPED = 3,
|
||
|
|
};
|
||
|
|
|
||
|
|
enum thread_flags {
|
||
|
|
THREAD_F_NEED_RESCHED = 0x01u,
|
||
|
|
THREAD_F_NO_PREEMPT = 0x02u,
|
||
|
|
};
|
||
|
|
|
||
|
|
struct thread {
|
||
|
|
struct object thr_base;
|
||
|
|
|
||
|
|
enum thread_state tr_state;
|
||
|
|
enum thread_flags tr_flags;
|
||
|
|
struct task *tr_parent;
|
||
|
|
|
||
|
|
unsigned int tr_id;
|
||
|
|
unsigned int tr_prio;
|
||
|
|
|
||
|
|
cycles_t tr_charge_period_start;
|
||
|
|
cycles_t tr_quantum_cycles, tr_quantum_target;
|
||
|
|
cycles_t tr_total_cycles;
|
||
|
|
|
||
|
|
virt_addr_t tr_ip, tr_sp, tr_bp;
|
||
|
|
virt_addr_t tr_cpu_user_sp, tr_cpu_kernel_sp;
|
||
|
|
|
||
|
|
struct runqueue *tr_rq;
|
||
|
|
struct msg tr_msg;
|
||
|
|
struct page_request tr_page_req;
|
||
|
|
|
||
|
|
struct queue_entry tr_parent_entry;
|
||
|
|
struct queue_entry tr_rqentry;
|
||
|
|
|
||
|
|
struct vm_page *tr_kstack;
|
||
|
|
struct vm_object *tr_ustack;
|
||
|
|
};
|
||
|
|
|
||
|
|
extern struct thread *thread_alloc(void);
|
||
|
|
extern struct thread *thread_cast(struct object *obj);
|
||
|
|
extern kern_status_t thread_init_kernel(struct thread *thr, virt_addr_t ip);
|
||
|
|
extern kern_status_t thread_init_user(
|
||
|
|
struct thread *thr,
|
||
|
|
virt_addr_t ip,
|
||
|
|
virt_addr_t sp,
|
||
|
|
const uintptr_t *args,
|
||
|
|
size_t nr_args);
|
||
|
|
extern int thread_priority(struct thread *thr);
|
||
|
|
extern void thread_awaken(struct thread *thr);
|
||
|
|
extern void idle(void);
|
||
|
|
extern struct thread *create_kernel_thread(void (*fn)(void));
|
||
|
|
extern struct thread *create_idle_thread(void);
|
||
|
|
|
||
|
|
#endif
|