authorgravatar for mail@isaacfreund.comIsaac Freund <mail@isaacfreund.com> 2020-09-09 19:51:59+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-09-10 15:40:38-04:00
log486a774e5fa079c4caba334f311ee32b54272f1f
tree4ff352cd107590dd9b379167c20a44cb6b278746
parent4170f3f77f23bca52a2a9b24d1a249fae35c04ac

std: add option to use single-threaded event loop

std.event.Loop does not yet work in single threaded builds. However, using evented io on a single thread can be very convenient. This commit allows settind @import("root").event_loop_mode to .single_threaded in order to allow this without reimplementing the startup code in start.zig

1 files changed, 2 insertions(+), 1 deletions(-)

lib/std/event/loop.zig+2-1
...@@ -112,7 +112,8 @@ pub const Loop = struct {...@@ -112,7 +112,8 @@ pub const Loop = struct {
112 /// have the correct pointer value.112 /// have the correct pointer value.
113 /// https://github.com/ziglang/zig/issues/2761 and https://github.com/ziglang/zig/issues/2765113 /// https://github.com/ziglang/zig/issues/2761 and https://github.com/ziglang/zig/issues/2765
114 pub fn init(self: *Loop) !void {114 pub fn init(self: *Loop) !void {
115 if (builtin.single_threaded) {115 if (builtin.single_threaded
116 or (@hasDecl(root, "event_loop_mode") and root.event_loop_mode == .single_threaded)) {
116 return self.initSingleThreaded();117 return self.initSingleThreaded();
117 } else {118 } else {
118 return self.initMultiThreaded();119 return self.initMultiThreaded();