initgraph, whole lot of refactor

This commit is contained in:
2026-10-12 15:36:48 +02:00
parent 41cc7fea77
commit eabce70866
79 changed files with 3700 additions and 302 deletions
+29 -2
View File
@@ -9,7 +9,6 @@
#include <zinnia/sched.h>
#include <zinnia/spin.h>
#include <zinnia/stack.h>
#include <zinnia/string.h>
#include <zinnia/tailq.h>
#include <zinnia/vma.h>
#include <arch/sched.h>
@@ -54,6 +53,7 @@ void sched_init(struct scheduler* sched) {
void sched_add_task(struct scheduler* sched, struct task* task) {
assert(task != nullptr, "Tried to add NULL to the run queue\n");
task->state = TASK_STATE_READY;
tailq_insert_tail(&sched->run_queue, task, next);
}
@@ -64,6 +64,7 @@ static struct task* next_task(struct scheduler* sched) {
return sched->idle_task;
tailq_remove(&sched->run_queue, t, next);
t->state = TASK_STATE_RUNNING;
return t;
}
@@ -110,6 +111,25 @@ void sched_yield(struct scheduler* sched) {
do_reschedule(sched);
}
void sched_block(struct scheduler* sched) {
irq_lock();
if (atomic_exchange_explicit(&sched->current->wake_pending, false, memory_order_acq_rel)) {
irq_unlock();
return;
}
sched->current->state = TASK_STATE_BLOCKED;
do_reschedule(sched);
}
void sched_wake(struct task* task) {
irq_lock();
if (task->state == TASK_STATE_BLOCKED)
sched_add_task(&percpu_get()->sched, task);
else
atomic_store_explicit(&task->wake_pending, true, memory_order_release);
irq_unlock();
}
errno_t task_create(const char* name, struct vma* space, task_fn_t entry, uintptr_t arg0, struct task** out) {
if (!out)
return EINVAL;
@@ -118,7 +138,7 @@ errno_t task_create(const char* name, struct vma* space, task_fn_t entry, uintpt
if (new_task == nullptr)
return ENOMEM;
static _Atomic(size_t) last_tid = 0;
static atomic_size_t last_tid = 0;
new_task->id = atomic_fetch_add_explicit(&last_tid, 1, memory_order_acquire);
new_task->space = space;
strncpy(new_task->name, name, sizeof(new_task->name));
@@ -165,3 +185,10 @@ void task_entry(task_fn_t entry, uintptr_t arg0, struct task* prev) {
sched_yield(sched);
panic("unreachable");
}
[[__init]]
static void sched_stage_init(struct boot_info*) {
sched_init(&percpu_get()->sched);
}
INIT_TASK(sched_stage, "core.sched", sched_stage_init);
INIT_DEPENDS(sched_stage, percpu_stage);