scheduler: Add cancellation flag to Task and .cancel method to set it from the parent

This commit is contained in:
2026-06-04 17:31:15 +02:00
parent cf6c78577b
commit 144de52f27
+15
View File
@@ -45,7 +45,11 @@ const Task = struct {
context: ?*const anyopaque, context: ?*const anyopaque,
state : State, state : State,
node : *Node, node : *Node,
// If this is a subtask, parent_id refers to the parent.
// The cancel flag is set when the parent requests cancellation.
parent_id: ?TaskID, parent_id: ?TaskID,
cancel: bool,
// These fields are only used when state=.blocked and // These fields are only used when state=.blocked and
// are not mutually exclusive. Each represents a different // are not mutually exclusive. Each represents a different
@@ -138,6 +142,7 @@ fn spawnInner(
.wakeup_futex = null, .wakeup_futex = null,
.node = node, .node = node,
.parent_id = parent_id, .parent_id = parent_id,
.cancel = false,
}; };
try self.tasks.append(self.gpa, task); try self.tasks.append(self.gpa, task);
@@ -376,3 +381,13 @@ pub fn wait(self: *Scheduler, ids: []const TaskID) !TaskID {
contextSwitch(&task.regs, &self.regs); contextSwitch(&task.regs, &self.regs);
} }
} }
pub fn cancel(self: *Scheduler, id: TaskID) !void {
const child = self.findTaskByID(id)
orelse return error.InvalidHandle;
if (child.parent_id != self.current_id)
return error.InvalidHandle;
child.cancel = true;
}