ps: initial process subsystem

This commit is contained in:
Loïc Grégoire
2026-06-18 18:54:38 -04:00
parent 42b10b886e
commit e50b1e0167
9 changed files with 92 additions and 73 deletions
+28
View File
@@ -0,0 +1,28 @@
const r = @import("root");
const ke = r.ke;
const ki = ke.private;
const mm = r.mm;
pub const thread = @import("thread.zig");
pub var turnstile_zone: mm.zone.TypedZone(ki.turnstile.Turnstile) = undefined;
fn turnstile_ctor(ts: *ki.turnstile.Turnstile) void {
ts.* = .{
.link = undefined,
.next_free = null,
.obj = undefined,
.owner = null,
.boost_link = undefined,
.donated = null,
.queues = undefined,
.waiters = 0,
};
ts.queues[0].init();
ts.queues[1].init();
}
/// Initialize the process subsystem.
pub fn init() void {
turnstile_zone.init("turnstiles", .{ .ctor = turnstile_ctor });
}
+16
View File
@@ -0,0 +1,16 @@
//! Higher-level process management.
// === Exported modules ===
pub const private = @import("private.zig");
const p = private;
// === Exported types ===
pub const Thread = p.thread.Thread;
// === Exported interfaces ===
pub const thread = struct {
pub const create_kernel = p.thread.create_kernel;
};
pub const init = p.init;
+28
View File
@@ -0,0 +1,28 @@
//! Higher-level thread management.
const r = @import("root");
const psp = r.ps.private;
const ke = r.ke;
const ki = ke.private;
const mm = r.mm;
const kernel_thread_stack_size = r.kib(16);
/// Higher-level wrapper over a thread.
pub const Thread = struct {
/// Lower-level part of the thread.
kern: ke.Thread,
};
/// Create a kernel thread.
/// - `prio`: base priority of the thread.
/// - `entry`: entry point.
/// - `arg`: argument passed to `entry`.
pub fn create_kernel(prio: u8, entry: *const fn (arg: ?*anyopaque) void, arg: ?*anyopaque) !*Thread {
var td = try mm.zone.gpa.create(Thread);
const stack = try mm.heap.alloc(kernel_thread_stack_size);
td.kern.init(@intFromPtr(stack), kernel_thread_stack_size, prio, entry, arg);
td.kern.turnstile = try psp.turnstile_zone.create();
return td;
}