const Thread = struct thread: std.Threadidle_context: Io.fiber.Contextcurrent_context: *Io.fiber.Contextready_queue: ?*Fiberkq_fd: posix.fd_tidle_search_index: u32steal_ready_search_index: u32wait_queues: std.array_hash_map.Auto(WaitQueueKey, *Fiber)For ensuring multiple fibers waiting on the same file descriptor and filter use the same kevent.
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74const Thread = struct {
thread: std.Thread,
idle_context: Io.fiber.Context,
current_context: *Io.fiber.Context,
ready_queue: ?*Fiber,
kq_fd: posix.fd_t,
idle_search_index: u32,
steal_ready_search_index: u32,
/// For ensuring multiple fibers waiting on the same file descriptor and
/// filter use the same kevent.
wait_queues: std.array_hash_map.Auto(WaitQueueKey, *Fiber),
const WaitQueueKey = struct {
ident: usize,
filter: i32,
};
const canceling: ?*Thread = @ptrFromInt(@alignOf(Thread));
threadlocal var self: *Thread = undefined;
fn current() *Thread {
return self;
}
fn currentFiber(thread: *Thread) *Fiber {
return @fieldParentPtr("context", thread.current_context);
}
const List = struct {
allocated: []Thread,
reserved: u32,
active: u32,
};
fn deinit(thread: *Thread, gpa: Allocator) void {
closeFd(thread.kq_fd);
assert(thread.wait_queues.count() == 0);
thread.wait_queues.deinit(gpa);
thread.* = undefined;
}
}