-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess.h
More file actions
36 lines (27 loc) · 1.14 KB
/
Copy pathprocess.h
File metadata and controls
36 lines (27 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#pragma once
#include "interrupts.h"
#include <stdint.h>
#define PROCESS_NAME_LEN 32
#define STATE_READY 0
#define STATE_SLEEPING 1
typedef struct process {
uint32_t pid;
uint32_t esp; /* 当前保存的栈指针 (struct registers*) */
uint32_t kernel_stack_top; /* 初始/基础内核栈顶 (用于 TSS.esp0) */
uint32_t state; /* 进程状态 (READY, SLEEPING 等) */
uint32_t sleep_ticks; /* 休眠剩余滴答数 */
char name[PROCESS_NAME_LEN];
struct process* next;
} process_t;
/* 初始化多任务系统 (将当前流作为 Idle 任务) */
void process_init(void);
/* 创建新内核线程 (Ring 0) */
process_t* process_create(void (*entry_point)(void), const char* name);
/* 创建新用户进程 (Ring 3) */
process_t* process_create_user(void (*entry_point)(void), const char* name);
/* 调度函数 (被时钟中断调用) */
struct registers* schedule(struct registers* current_regs);
/* 更新所有进程的休眠计时 (由时钟中断调用) */
void process_update_sleep_ticks(void);
/* 使当前进程进入休眠 (由系统调用调用) */
void process_sleep(uint32_t ticks);