ppos

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit b138a0194434d2c434d659f95cc92d2824e9ea6a
parent 049015a681d6c5ea61f275c79faff40b0b08325e
Author: Gabriel G. de Brito <me@gboncoffee.dev.br>
Date:   Sun, 30 Aug 2026 00:59:52 -0300

Wait (intermitentemente falha se preemptar o malloc).

Diffstat:
Mkernel/dispatcher.c | 24+++++++++++++++++++++---
Mkernel/task.c | 12+++++++-----
Mkernel/tcb.h | 6++++--
3 files changed, 32 insertions(+), 10 deletions(-)

diff --git a/kernel/dispatcher.c b/kernel/dispatcher.c @@ -37,7 +37,7 @@ void dispatcher() kernel_task.wall_last_grab = kernel_task.wall_start; kernel_task.activations = 1; - task_create("user_main", user_main, NULL); + struct task_t* user_task = task_create("user_main", user_main, NULL); while (queue_size(ready) > 0) { struct task_t* task = scheduler(ready); @@ -49,19 +49,27 @@ void dispatcher() kernel_task.activations += 1; if (task->status == TaskStatusFinished) { + task->wall_last_grab = time() - task->wall_start; printk( "PPOS: task %d (%s) %d ms run, %d ms cpu, %d acts, exit " "code %d\n", task->id, task->name, - time() - task->wall_start, + task->wall_last_grab, task->cpu_time, task->activations, task->exit_code ); - task_destroy(task); + struct queue_t* q = task->waiting_on_queue; + for (struct task_t* wt = queue_head(q); wt != NULL; + wt = queue_next(q)) { + task_awake(wt); + } } } + + task_destroy(user_task); + kernel_task.cpu_time += time() - kernel_task.wall_last_grab; printk( "PPOS: task %d (%s) %d ms run, %d ms cpu, %d acts, exit " @@ -134,3 +142,13 @@ void task_exit(int exit_code) kernel_task.wall_last_grab = time(); task_switch(&kernel_task); } + +int task_wait(struct task_t* task) +{ + if (task == NULL) + return ERROR; + if (task->status == TaskStatusFinished) + return task->exit_code; + task_suspend(task->waiting_on_queue); + return task->exit_code; +} diff --git a/kernel/task.c b/kernel/task.c @@ -63,11 +63,12 @@ struct task_t* task_create(char* name, void (*entry)(void*), void* arg) ctx_create(&task->context, entry, arg, stack, PPOS_STACK_SIZE); uid += 1; - task->id = uid; - task->parent = current; - task->name = name; - task->status = TaskStatusReady; - task->wall_start = time(); + task->id = uid; + task->parent = current; + task->name = name; + task->status = TaskStatusReady; + task->waiting_on_queue = queue_create(); + task->wall_start = time(); queue_add(ready, task); @@ -84,6 +85,7 @@ int task_destroy(struct task_t* task) VALGRIND_STACK_DEREGISTER(task->valgrind_id); + free(task->waiting_on_queue); free(task); return NOERROR; diff --git a/kernel/tcb.h b/kernel/tcb.h @@ -30,9 +30,11 @@ struct task_t { char* name; // nome da tarefa struct task_t* parent; struct queue_t* waiting_queue; + struct queue_t* waiting_on_queue; unsigned long wall_start; // wall time de quando ela começou - unsigned long - wall_last_grab; // wall time da última vez que ela ganhou a cpu + // wall time da última vez que ela ganhou a cpu, ou o wall time total caso + // ela já tenha finalizado + unsigned long wall_last_grab; unsigned long cpu_time; // tempo em que ela passou com a cpu unsigned long activations; int id; // identificador da tarefa