std: avoid referencing event loop when io_mode is blocking

This prevents unwanted symbols from ending up in the output binary.
This commit is contained in:
Andrew Kelley 2022-03-29 22:16:43 -07:00
parent 9821a0c6f0
commit 83617eac59

View File

@ -103,12 +103,17 @@ pub const Loop = struct {
};
};
var global_instance_state: Loop = undefined;
const default_instance: ?*Loop = switch (std.io.mode) {
const LoopOrVoid = switch (std.io.mode) {
.blocking => void,
.evented => Loop,
};
var global_instance_state: LoopOrVoid = undefined;
const default_instance: ?*LoopOrVoid = switch (std.io.mode) {
.blocking => null,
.evented => &global_instance_state,
};
pub const instance: ?*Loop = if (@hasDecl(root, "event_loop")) root.event_loop else default_instance;
pub const instance: ?*LoopOrVoid = if (@hasDecl(root, "event_loop")) root.event_loop else default_instance;
/// TODO copy elision / named return values so that the threads referencing *Loop
/// have the correct pointer value.