CoolPotOS/include/task.h

62 lines
1.3 KiB
C
Raw Normal View History

2024-04-09 23:46:56 +08:00
#ifndef CRASHPOWEROS_TASK_H
#define CRASHPOWEROS_TASK_H
#include "memory.h"
typedef
enum task_state {
TASK_UNINIT = 0, // 未初始化
TASK_SLEEPING = 1, // 睡眠中
TASK_RUNNABLE = 2, // 可运行(也许正在运行)
TASK_ZOMBIE = 3, // 僵尸状态
2024-04-10 01:18:08 +08:00
TASK_DEATH = 4 // 终止状态
2024-04-09 23:46:56 +08:00
} task_state;
struct context {
uint32_t esp;
uint32_t ebp;
uint32_t ebx;
uint32_t esi;
uint32_t edi;
uint32_t eflags;
};
// 进程控制块 PCB
struct task_struct {
volatile task_state state; // 进程当前状态
int pid; // 进程标识符
char *name; // 进程名
void *stack; // 进程的内核栈地址
page_directory_t *pgd_dir; // 进程页表
2024-04-14 17:14:26 +08:00
struct context context; // 上下文信息
2024-04-09 23:46:56 +08:00
struct task_struct *next; // 链表指针
};
2024-04-15 00:24:36 +08:00
void print_proc_t(int *i,struct task_struct *base,struct task_struct *cur,int is_print);
struct task_struct* get_current();
2024-04-09 23:46:56 +08:00
int32_t kernel_thread(int (*fn)(void *), void *arg, char *name);
void kthread_exit();
void print_proc();
void init_sched();
void schedule();
void change_task_to(struct task_struct *next);
2024-04-13 22:03:54 +08:00
void task_kill(int pid);
2024-04-14 17:14:26 +08:00
void kill_all_task();
2024-04-15 00:24:36 +08:00
struct task_struct* found_task_pid(int pid);
void wait_task(struct task_struct *task);
void start_task(struct task_struct *task);
2024-04-09 23:46:56 +08:00
#endif //CRASHPOWEROS_TASK_H