| ... | @@ -103,12 +103,17 @@ pub const Loop = struct { | ... | @@ -103,12 +103,17 @@ pub const Loop = struct { |
| 103 | }; | 103 | }; |
| 104 | }; | 104 | }; |
| 105 | | 105 | |
| 106 | var global_instance_state: Loop = undefined; | 106 | const LoopOrVoid = switch (std.io.mode) { |
| 107 | const default_instance: ?*Loop = switch (std.io.mode) { | 107 | .blocking => void, |
| | 108 | .evented => Loop, |
| | 109 | }; |
| | 110 | |
| | 111 | var global_instance_state: LoopOrVoid = undefined; |
| | 112 | const default_instance: ?*LoopOrVoid = switch (std.io.mode) { |
| 108 | .blocking => null, | 113 | .blocking => null, |
| 109 | .evented => &global_instance_state, | 114 | .evented => &global_instance_state, |
| 110 | }; | 115 | }; |
| 111 | pub const instance: ?*Loop = if (@hasDecl(root, "event_loop")) root.event_loop else default_instance; | 116 | pub const instance: ?*LoopOrVoid = if (@hasDecl(root, "event_loop")) root.event_loop else default_instance; |
| 112 | | 117 | |
| 113 | /// TODO copy elision / named return values so that the threads referencing *Loop | 118 | /// TODO copy elision / named return values so that the threads referencing *Loop |
| 114 | /// have the correct pointer value. | 119 | /// have the correct pointer value. |