core: Add thread states

This commit is contained in:
Gabriel 2025-02-16 11:57:04 +01:00
parent f87426753b
commit 4554bce8a8
2 changed files with 5 additions and 0 deletions

View File

@ -106,6 +106,7 @@ export fn _start(magic: u32, info: MultibootInfo) callconv(.C) noreturn {
platform.platformEndInit(); platform.platformEndInit();
init.state = .Running;
thread.enterTask(init); thread.enterTask(init);
} }

View File

@ -6,13 +6,16 @@ const pmm = @import("pmm.zig");
const cpu = @import("arch/cpu.zig"); const cpu = @import("arch/cpu.zig");
pub const ThreadState = enum { pub const ThreadState = enum {
Inactive,
Running, Running,
Blocked,
}; };
pub const ThreadControlBlock = struct { pub const ThreadControlBlock = struct {
id: u64, id: u64,
directory: ?*vmm.PageDirectory, directory: ?*vmm.PageDirectory,
regs: interrupts.InterruptStackFrame, regs: interrupts.InterruptStackFrame,
state: ThreadState,
ticks: u64, ticks: u64,
}; };
@ -82,6 +85,7 @@ pub fn createThreadControlBlock(allocator: *pmm.FrameAllocator) !*ThreadControlB
thread.id = next_id.fetchAdd(1, .seq_cst); thread.id = next_id.fetchAdd(1, .seq_cst);
thread.directory = null; thread.directory = null;
thread.regs = std.mem.zeroes(@TypeOf(thread.regs)); thread.regs = std.mem.zeroes(@TypeOf(thread.regs));
thread.state = .Inactive;
return thread; return thread;
} }