Добавлено время потока

This commit is contained in:
Aren Elchinyan 2024-01-21 22:17:37 +03:00
parent a59ba3412f
commit feaab75a6f
3 changed files with 15 additions and 2 deletions

View File

@ -20,6 +20,8 @@ typedef struct task {
uint64_t rsi, rdi, rsp, rbp;
uint64_t cr3;
uint64_t cpu_time;
uint64_t cpu_time_expired;
uint64_t id;
void *stack;

View File

@ -1,3 +1,3 @@
#define VERSION_MAJOR 0
#define VERSION_MINOR 1
#define VERSION_BUILD 979
#define VERSION_BUILD 983

View File

@ -23,11 +23,20 @@ void task_switch_asm(task_t *, task_t *);
void task_switch(struct frame *state) {
UNUSED(state);
asm volatile("cli");
task_t *next = current_task->next;
task_t *last = current_task;
if (current_task->cpu_time_expired) {
current_task->cpu_time_expired--;
outb(0x20, 0x20);
task_switch_asm(current_task, current_task);
return;
}
current_task->cpu_time_expired = current_task->cpu_time;
current_task = next;
// LOG("Смена потоков %u->%u\n", last->id, next->id);
@ -55,6 +64,7 @@ uint64_t task_new_thread(void (*func)(void *)) {
stack[--stack_top] = (uint64_t)0;
new_task->rsp = (uint64_t)new_task->stack + sizeof(uint64_t) * stack_top;
new_task->cpu_time = 500;
new_task->id = next_thread_id++;
new_task->cr3 = cr3;
@ -89,6 +99,7 @@ void task_init( ) {
kernel_task->id = next_thread_id++;
kernel_task->rsp = rsp;
kernel_task->cr3 = cr3;
kernel_task->cpu_time = 1000;
current_task = kernel_task;