ppos

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

commit dc9311c65f3e43c34a94aabf49bb3981af3f10a4
parent e59f162dd22da9d3fcef9c7171f7d6d8e46a5ca1
Author: Gabriel G. de Brito <me@gboncoffee.dev.br>
Date:   Sat, 29 Aug 2026 18:05:16 -0300

Scheduler.

Diffstat:
Mkernel/memory.c | 1+
Mkernel/scheduler.c | 36+++++++++++++++++++++++++++++++++++-
Mkernel/task.c | 8++++----
Mkernel/tcb.h | 3+++
Mlib/map.c | 1+
Mlib/queue.c | 1+
6 files changed, 45 insertions(+), 5 deletions(-)

diff --git a/kernel/memory.c b/kernel/memory.c @@ -1,3 +1,4 @@ +// GRR20235159 Gabriel Gioia de Brito // PingPongOS - PingPong Operating System // Este arquivo PODE/DEVE ser alterado. diff --git a/kernel/scheduler.c b/kernel/scheduler.c @@ -1,3 +1,4 @@ +// GRR20235159 Gabriel Gioia de Brito // PingPongOS - PingPong Operating System // Este arquivo PODE/DEVE ser alterado. @@ -8,6 +9,8 @@ #include <queue.h> +extern struct task_t* current; + void sched_init() { } @@ -18,5 +21,36 @@ void sched_term() struct task_t* scheduler(struct queue_t* ready) { - return queue_head(ready); + struct task_t* task = queue_head(ready); + for (struct task_t* it = task; it != NULL; it = queue_next(ready)) { + if (it->prio < task->prio) + task = it; + } + for (struct task_t* it = queue_head(ready); it != NULL; + it = queue_next(ready)) { + if (it != task && it->prio > -20) + it->prio -= 1; + } + task->prio = task->nice; + return task; +} + +void sched_setprio(struct task_t* task, int prio) +{ + if (task == NULL) + task = current; + if (prio < -20 || prio > 20) + return; + + task->nice = prio; + task->prio = prio; +} + +int sched_getprio(struct task_t* task) +{ + // Jeito simples de indicar erros, se precisar no futuro... + if (task == NULL) + task = current; + + return task->nice; } diff --git a/kernel/task.c b/kernel/task.c @@ -1,3 +1,4 @@ +// GRR20235159 Gabriel Gioia de Brito // PingPongOS - PingPong Operating System // Este arquivo PODE/DEVE ser alterado. @@ -40,7 +41,7 @@ void task_term() struct task_t* task_create(char* name, void (*entry)(void*), void* arg) { - struct task_t* task = malloc(sizeof(*task)); + struct task_t* task = calloc(1, sizeof(*task)); if (task == NULL) return NULL; @@ -70,9 +71,7 @@ struct task_t* task_create(char* name, void (*entry)(void*), void* arg) int task_destroy(struct task_t* task) { - if (task == NULL) - return ERROR; - if (task->status != TaskStatusFinished) + if (task == NULL || task->status != TaskStatusFinished) return ERROR; if (task->context.stack != NULL) @@ -97,6 +96,7 @@ char* task_name(struct task_t* task) { if (task == NULL) task = current; + return task->name; } diff --git a/kernel/tcb.h b/kernel/tcb.h @@ -1,3 +1,4 @@ +// GRR20235159 Gabriel Gioia de Brito // PingPongOS - PingPong Operating System // © Prof. Carlos A. Maziero, DINF UFPR // Versão 2.1 -- 06/2026 @@ -30,6 +31,8 @@ struct task_t { struct queue_t* waiting_queue; int id; // identificador da tarefa int valgrind_id; + int nice; + int prio; TaskStatus status; }; diff --git a/lib/map.c b/lib/map.c @@ -1,3 +1,4 @@ +// GRR20235159 Gabriel Gioia de Brito // PingPongOS - PingPong Operating System // Prof. Carlos A. Maziero, DINF UFPR // Versão 2.1 -- 07/2026 diff --git a/lib/queue.c b/lib/queue.c @@ -1,3 +1,4 @@ +// GRR20235159 Gabriel Gioia de Brito // PingPongOS - PingPong Operating System // © Prof. Carlos A. Maziero, DINF UFPR // Versão 2.1 -- 06/2026