@zigc/lib 0.17.0-dev.44 → 0.17.0-dev.76
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/c/inttypes.zig +0 -10
- package/c/math.zig +27 -116
- package/c/search.zig +1 -27
- package/c/stdlib/drand48.zig +0 -57
- package/c/stdlib.zig +0 -100
- package/c/string.zig +0 -7
- package/c/strings.zig +0 -38
- package/c/unistd.zig +27 -26
- package/c.zig +1 -2
- package/compiler_rt/cos.zig +0 -2
- package/compiler_rt/exp.zig +0 -2
- package/compiler_rt/exp2.zig +0 -2
- package/compiler_rt/fabs.zig +0 -2
- package/compiler_rt/fma.zig +0 -2
- package/compiler_rt/fmax.zig +0 -2
- package/compiler_rt/fmin.zig +0 -2
- package/compiler_rt/fmod.zig +0 -2
- package/compiler_rt/limb64.zig +32 -0
- package/compiler_rt/log.zig +0 -2
- package/compiler_rt/log10.zig +0 -2
- package/compiler_rt/log2.zig +0 -2
- package/compiler_rt/round.zig +0 -2
- package/compiler_rt/sin.zig +0 -2
- package/compiler_rt/sincos.zig +0 -2
- package/compiler_rt/sqrt.zig +0 -2
- package/compiler_rt/tan.zig +0 -2
- package/compiler_rt/trunc.zig +0 -2
- package/package.json +1 -1
- package/std/Io/Dispatch.zig +3 -13
- package/std/Io/Semaphore.zig +112 -17
- package/std/Io/Threaded.zig +158 -24
- package/std/Io/Uring.zig +11 -13
- package/std/Io/net.zig +11 -11
- package/std/Io.zig +89 -25
- package/std/Target.zig +0 -2
- package/std/c/haiku.zig +3 -0
- package/std/c/serenity.zig +1 -6
- package/std/c.zig +59 -6
- package/std/debug.zig +1 -1
- package/std/os.zig +41 -0
- package/std/zig/LibCInstallation.zig +1 -0
- package/libc/musl/src/unistd/dup2.c +0 -20
- package/libc/musl/src/unistd/dup3.c +0 -26
package/compiler_rt/limb64.zig
CHANGED
|
@@ -152,6 +152,10 @@ fn test__addo_limb64(comptime T: type, a: T, b: T, expected: struct { T, bool })
|
|
|
152
152
|
}
|
|
153
153
|
|
|
154
154
|
test __addo_limb64 {
|
|
155
|
+
if (builtin.cpu.arch == .aarch64_be) return error.SkipZigTest; // https://codeberg.org/ziglang/zig/issues/31905
|
|
156
|
+
if (builtin.cpu.arch == .mips64) return error.SkipZigTest; // https://codeberg.org/ziglang/zig/issues/31905
|
|
157
|
+
if (builtin.cpu.arch == .powerpc64) return error.SkipZigTest; // https://codeberg.org/ziglang/zig/issues/31905
|
|
158
|
+
|
|
155
159
|
try test__addo_limb64(u64, 1, 2, .{ 3, false });
|
|
156
160
|
try test__addo_limb64(u64, maxInt(u64), 2, .{ 1, true });
|
|
157
161
|
try test__addo_limb64(u65, maxInt(u65), 2, .{ 1, true });
|
|
@@ -228,6 +232,10 @@ fn test__subo_limb64(comptime T: type, a: T, b: T, expected: struct { T, bool })
|
|
|
228
232
|
}
|
|
229
233
|
|
|
230
234
|
test __subo_limb64 {
|
|
235
|
+
if (builtin.cpu.arch == .aarch64_be) return error.SkipZigTest; // https://codeberg.org/ziglang/zig/issues/31905
|
|
236
|
+
if (builtin.cpu.arch == .mips64) return error.SkipZigTest; // https://codeberg.org/ziglang/zig/issues/31905
|
|
237
|
+
if (builtin.cpu.arch == .powerpc64) return error.SkipZigTest; // https://codeberg.org/ziglang/zig/issues/31905
|
|
238
|
+
|
|
231
239
|
try test__subo_limb64(u64, 3, 2, .{ 1, false });
|
|
232
240
|
try test__subo_limb64(u64, 0, 1, .{ maxInt(u64), true });
|
|
233
241
|
try test__subo_limb64(u65, 0, 1, .{ maxInt(u65), true });
|
|
@@ -477,6 +485,10 @@ fn test__not_limb64(comptime T: type, a: T, expected: T) !void {
|
|
|
477
485
|
}
|
|
478
486
|
|
|
479
487
|
test __not_limb64 {
|
|
488
|
+
if (builtin.cpu.arch == .aarch64_be) return error.SkipZigTest; // https://codeberg.org/ziglang/zig/issues/31905
|
|
489
|
+
if (builtin.cpu.arch == .mips64) return error.SkipZigTest; // https://codeberg.org/ziglang/zig/issues/31905
|
|
490
|
+
if (builtin.cpu.arch == .powerpc64) return error.SkipZigTest; // https://codeberg.org/ziglang/zig/issues/31905
|
|
491
|
+
|
|
480
492
|
try test__not_limb64(u64, 1, maxInt(u64) - 1);
|
|
481
493
|
try test__not_limb64(u64, 3, maxInt(u64) - 3);
|
|
482
494
|
try test__not_limb64(u65, maxInt(u65), 0);
|
|
@@ -555,6 +567,10 @@ fn test__shlo_limb64(comptime T: type, a: T, shift: u16, expected: struct { T, b
|
|
|
555
567
|
}
|
|
556
568
|
|
|
557
569
|
test __shlo_limb64 {
|
|
570
|
+
if (builtin.cpu.arch == .aarch64_be) return error.SkipZigTest; // https://codeberg.org/ziglang/zig/issues/31905
|
|
571
|
+
if (builtin.cpu.arch == .mips64) return error.SkipZigTest; // https://codeberg.org/ziglang/zig/issues/31905
|
|
572
|
+
if (builtin.cpu.arch == .powerpc64) return error.SkipZigTest; // https://codeberg.org/ziglang/zig/issues/31905
|
|
573
|
+
|
|
558
574
|
try test__shlo_limb64(u64, 0x1234_5678_9ABC_DEF0, 4, .{ 0x2345_6789_ABCD_EF00, true });
|
|
559
575
|
try test__shlo_limb64(u64, 0x8000_0000_0000_0001, 63, .{ 0x8000_0000_0000_0000, true });
|
|
560
576
|
try test__shlo_limb64(u65, 1, 64, .{ 0x1_0000_0000_0000_0000, false });
|
|
@@ -631,6 +647,10 @@ fn test__shr_limb64(comptime T: type, a: T, shift: u16, expected: T) !void {
|
|
|
631
647
|
}
|
|
632
648
|
|
|
633
649
|
test __shr_limb64 {
|
|
650
|
+
if (builtin.cpu.arch == .aarch64_be) return error.SkipZigTest; // https://codeberg.org/ziglang/zig/issues/31905
|
|
651
|
+
if (builtin.cpu.arch == .mips64) return error.SkipZigTest; // https://codeberg.org/ziglang/zig/issues/31905
|
|
652
|
+
if (builtin.cpu.arch == .powerpc64) return error.SkipZigTest; // https://codeberg.org/ziglang/zig/issues/31905
|
|
653
|
+
|
|
634
654
|
try test__shr_limb64(u64, 0x1234_5678_9ABC_DEF0, 4, 0x0123_4567_89AB_CDEF);
|
|
635
655
|
try test__shr_limb64(u64, 0x8000_0000_0000_0001, 63, 1);
|
|
636
656
|
try test__shr_limb64(u65, 0x1_0000_0000_0000_0000, 64, 1);
|
|
@@ -858,6 +878,10 @@ fn test__bitreverse_limb64(comptime T: type, a: T, expected: T) !void {
|
|
|
858
878
|
}
|
|
859
879
|
|
|
860
880
|
test __bitreverse_limb64 {
|
|
881
|
+
if (builtin.cpu.arch == .aarch64_be) return error.SkipZigTest; // https://codeberg.org/ziglang/zig/issues/31905
|
|
882
|
+
if (builtin.cpu.arch == .mips64) return error.SkipZigTest; // https://codeberg.org/ziglang/zig/issues/31905
|
|
883
|
+
if (builtin.cpu.arch == .powerpc64) return error.SkipZigTest; // https://codeberg.org/ziglang/zig/issues/31905
|
|
884
|
+
|
|
861
885
|
try test__bitreverse_limb64(u64, 1 << 7, 1 << 56);
|
|
862
886
|
try test__bitreverse_limb64(u65, 1 << 64, 1);
|
|
863
887
|
try test__bitreverse_limb64(u65, 1 << 9, 1 << 55);
|
|
@@ -910,6 +934,10 @@ fn test__byteswap_limb64(comptime T: type, a: T, expected: T) !void {
|
|
|
910
934
|
}
|
|
911
935
|
|
|
912
936
|
test __byteswap_limb64 {
|
|
937
|
+
if (builtin.cpu.arch == .aarch64_be) return error.SkipZigTest; // https://codeberg.org/ziglang/zig/issues/31905
|
|
938
|
+
if (builtin.cpu.arch == .mips64) return error.SkipZigTest; // https://codeberg.org/ziglang/zig/issues/31905
|
|
939
|
+
if (builtin.cpu.arch == .powerpc64) return error.SkipZigTest; // https://codeberg.org/ziglang/zig/issues/31905
|
|
940
|
+
|
|
913
941
|
try test__byteswap_limb64(u64, 0x0123_4567_89AB_CDEF, 0xEFCD_AB89_6745_2301);
|
|
914
942
|
try test__byteswap_limb64(u72, 0x01_23_45_67_89_AB_CD_EF_11, 0x11_EF_CD_AB_89_67_45_23_01);
|
|
915
943
|
try test__byteswap_limb64(u128, 1 << 72, 1 << 48);
|
|
@@ -1036,6 +1064,10 @@ fn test__mulo_limb64(comptime T: type, a: T, b: T, expected: struct { T, bool })
|
|
|
1036
1064
|
}
|
|
1037
1065
|
|
|
1038
1066
|
test __mulo_limb64 {
|
|
1067
|
+
if (builtin.cpu.arch == .aarch64_be) return error.SkipZigTest; // https://codeberg.org/ziglang/zig/issues/31905
|
|
1068
|
+
if (builtin.cpu.arch == .mips64) return error.SkipZigTest; // https://codeberg.org/ziglang/zig/issues/31905
|
|
1069
|
+
if (builtin.cpu.arch == .powerpc64) return error.SkipZigTest; // https://codeberg.org/ziglang/zig/issues/31905
|
|
1070
|
+
|
|
1039
1071
|
try test__mulo_limb64(u64, 3, 5, .{ 15, false });
|
|
1040
1072
|
try test__mulo_limb64(u64, maxInt(u64), 2, .{ maxInt(u64) - 1, true });
|
|
1041
1073
|
try test__mulo_limb64(u65, 1 << 32, 1 << 32, .{ 1 << 64, false });
|
package/compiler_rt/log.zig
CHANGED
|
@@ -443,8 +443,6 @@ pub fn logq(a: f128) callconv(.c) f128 {
|
|
|
443
443
|
|
|
444
444
|
pub fn logl(x: c_longdouble) callconv(.c) c_longdouble {
|
|
445
445
|
switch (@typeInfo(c_longdouble).float.bits) {
|
|
446
|
-
16 => return __logh(x),
|
|
447
|
-
32 => return logf(x),
|
|
448
446
|
64 => return log(x),
|
|
449
447
|
80 => return __logx(x),
|
|
450
448
|
128 => return logq(x),
|
package/compiler_rt/log10.zig
CHANGED
|
@@ -177,8 +177,6 @@ pub fn log10q(a: f128) callconv(.c) f128 {
|
|
|
177
177
|
|
|
178
178
|
pub fn log10l(x: c_longdouble) callconv(.c) c_longdouble {
|
|
179
179
|
switch (@typeInfo(c_longdouble).float.bits) {
|
|
180
|
-
16 => return __log10h(x),
|
|
181
|
-
32 => return log10f(x),
|
|
182
180
|
64 => return log10(x),
|
|
183
181
|
80 => return __log10x(x),
|
|
184
182
|
128 => return log10q(x),
|
package/compiler_rt/log2.zig
CHANGED
|
@@ -170,8 +170,6 @@ pub fn log2q(a: f128) callconv(.c) f128 {
|
|
|
170
170
|
|
|
171
171
|
pub fn log2l(x: c_longdouble) callconv(.c) c_longdouble {
|
|
172
172
|
switch (@typeInfo(c_longdouble).float.bits) {
|
|
173
|
-
16 => return __log2h(x),
|
|
174
|
-
32 => return log2f(x),
|
|
175
173
|
64 => return log2(x),
|
|
176
174
|
80 => return __log2x(x),
|
|
177
175
|
128 => return log2q(x),
|
package/compiler_rt/round.zig
CHANGED
|
@@ -142,8 +142,6 @@ pub fn roundq(x_: f128) callconv(.c) f128 {
|
|
|
142
142
|
|
|
143
143
|
pub fn roundl(x: c_longdouble) callconv(.c) c_longdouble {
|
|
144
144
|
switch (@typeInfo(c_longdouble).float.bits) {
|
|
145
|
-
16 => return __roundh(x),
|
|
146
|
-
32 => return roundf(x),
|
|
147
145
|
64 => return round(x),
|
|
148
146
|
80 => return __roundx(x),
|
|
149
147
|
128 => return roundq(x),
|
package/compiler_rt/sin.zig
CHANGED
|
@@ -189,8 +189,6 @@ pub fn sinq(x: f128) callconv(.c) f128 {
|
|
|
189
189
|
|
|
190
190
|
pub fn sinl(x: c_longdouble) callconv(.c) c_longdouble {
|
|
191
191
|
switch (@typeInfo(c_longdouble).float.bits) {
|
|
192
|
-
16 => return sinh(x),
|
|
193
|
-
32 => return sinf(x),
|
|
194
192
|
64 => return sin(x),
|
|
195
193
|
80 => return sinx(x),
|
|
196
194
|
128 => return sinq(x),
|
package/compiler_rt/sincos.zig
CHANGED
|
@@ -292,8 +292,6 @@ pub fn sincosq(x: f128, r_sin: *f128, r_cos: *f128) callconv(.c) void {
|
|
|
292
292
|
|
|
293
293
|
pub fn sincosl(x: c_longdouble, r_sin: *c_longdouble, r_cos: *c_longdouble) callconv(.c) void {
|
|
294
294
|
switch (@typeInfo(c_longdouble).float.bits) {
|
|
295
|
-
16 => return sincosh(x, r_sin, r_cos),
|
|
296
|
-
32 => return sincosf(x, r_sin, r_cos),
|
|
297
295
|
64 => return sincos(x, r_sin, r_cos),
|
|
298
296
|
80 => return sincosx(x, r_sin, r_cos),
|
|
299
297
|
128 => return sincosq(x, r_sin, r_cos),
|
package/compiler_rt/sqrt.zig
CHANGED
|
@@ -481,8 +481,6 @@ fn _Qp_sqrt(c: *f128, a: *f128) callconv(.c) void {
|
|
|
481
481
|
|
|
482
482
|
pub fn sqrtl(x: c_longdouble) callconv(.c) c_longdouble {
|
|
483
483
|
switch (@typeInfo(c_longdouble).float.bits) {
|
|
484
|
-
16 => return __sqrth(x),
|
|
485
|
-
32 => return sqrtf(x),
|
|
486
484
|
64 => return sqrt(x),
|
|
487
485
|
80 => return __sqrtx(x),
|
|
488
486
|
128 => return sqrtq(x),
|
package/compiler_rt/tan.zig
CHANGED
|
@@ -164,8 +164,6 @@ pub fn tanq(x: f128) callconv(.c) f128 {
|
|
|
164
164
|
|
|
165
165
|
pub fn tanl(x: c_longdouble) callconv(.c) c_longdouble {
|
|
166
166
|
switch (@typeInfo(c_longdouble).float.bits) {
|
|
167
|
-
16 => return tanh(x),
|
|
168
|
-
32 => return tanf(x),
|
|
169
167
|
64 => return tan(x),
|
|
170
168
|
80 => return tanx(x),
|
|
171
169
|
128 => return tanq(x),
|
package/compiler_rt/trunc.zig
CHANGED
|
@@ -99,8 +99,6 @@ pub fn truncq(x: f128) callconv(.c) f128 {
|
|
|
99
99
|
|
|
100
100
|
pub fn truncl(x: c_longdouble) callconv(.c) c_longdouble {
|
|
101
101
|
switch (@typeInfo(c_longdouble).float.bits) {
|
|
102
|
-
16 => return __trunch(x),
|
|
103
|
-
32 => return truncf(x),
|
|
104
102
|
64 => return trunc(x),
|
|
105
103
|
80 => return __truncx(x),
|
|
106
104
|
128 => return truncq(x),
|
package/package.json
CHANGED
package/std/Io/Dispatch.zig
CHANGED
|
@@ -459,7 +459,6 @@ pub fn io(ev: *Evented) Io {
|
|
|
459
459
|
.netConnectUnix = netConnectUnixUnavailable,
|
|
460
460
|
.netSocketCreatePair = netSocketCreatePairUnavailable,
|
|
461
461
|
.netSend = netSendUnavailable,
|
|
462
|
-
.netRead = netReadUnavailable,
|
|
463
462
|
.netWrite = netWriteUnavailable,
|
|
464
463
|
.netWriteFile = netWriteFileUnavailable,
|
|
465
464
|
.netClose = netClose,
|
|
@@ -1713,6 +1712,7 @@ fn operate(userdata: ?*anyopaque, operation: Io.Operation) Io.Cancelable!Io.Oper
|
|
|
1713
1712
|
},
|
|
1714
1713
|
.device_io_control => |*o| return .{ .device_io_control = try deviceIoControl(o) },
|
|
1715
1714
|
.net_receive => @panic("TODO implement net_receive operation"),
|
|
1715
|
+
.net_read => @panic("TODO implement net_read operation"),
|
|
1716
1716
|
}
|
|
1717
1717
|
}
|
|
1718
1718
|
|
|
@@ -2134,6 +2134,7 @@ fn batchDrainSubmitted(
|
|
|
2134
2134
|
},
|
|
2135
2135
|
.device_io_control => {},
|
|
2136
2136
|
.net_receive => @panic("TODO implement batched net_receive"),
|
|
2137
|
+
.net_read => @panic("TODO implement batched net_read"),
|
|
2137
2138
|
};
|
|
2138
2139
|
if (concurrency) return error.ConcurrencyUnavailable;
|
|
2139
2140
|
break :result try operate(ev, storage.submission.operation);
|
|
@@ -2193,6 +2194,7 @@ fn batchSourceEvent(context: ?*anyopaque) callconv(.c) void {
|
|
|
2193
2194
|
},
|
|
2194
2195
|
.device_io_control => unreachable,
|
|
2195
2196
|
.net_receive => @panic("TODO implement batched net_receive"),
|
|
2197
|
+
.net_read => @panic("TODO implement batched net_read"),
|
|
2196
2198
|
};
|
|
2197
2199
|
|
|
2198
2200
|
switch (pending.node.prev) {
|
|
@@ -4877,18 +4879,6 @@ fn netSendUnavailable(
|
|
|
4877
4879
|
return .{ error.NetworkDown, 0 };
|
|
4878
4880
|
}
|
|
4879
4881
|
|
|
4880
|
-
fn netReadUnavailable(
|
|
4881
|
-
userdata: ?*anyopaque,
|
|
4882
|
-
fd: net.Socket.Handle,
|
|
4883
|
-
data: [][]u8,
|
|
4884
|
-
) net.Stream.Reader.Error!usize {
|
|
4885
|
-
const ev: *Evented = @ptrCast(@alignCast(userdata));
|
|
4886
|
-
_ = ev;
|
|
4887
|
-
_ = fd;
|
|
4888
|
-
_ = data;
|
|
4889
|
-
return error.NetworkDown;
|
|
4890
|
-
}
|
|
4891
|
-
|
|
4892
4882
|
fn netWriteUnavailable(
|
|
4893
4883
|
userdata: ?*anyopaque,
|
|
4894
4884
|
handle: net.Socket.Handle,
|
package/std/Io/Semaphore.zig
CHANGED
|
@@ -15,14 +15,42 @@ cond: Io.Condition = .init,
|
|
|
15
15
|
/// It is OK to initialize this field to any value.
|
|
16
16
|
permits: usize = 0,
|
|
17
17
|
|
|
18
|
+
/// Blocks until a `permit` is available and consumes a single one.
|
|
19
|
+
/// Unblocks without consuming a `permit` when canceled.
|
|
20
|
+
///
|
|
21
|
+
/// See also:
|
|
22
|
+
/// * `waitTimeout`
|
|
23
|
+
/// * `waitUncancelable`
|
|
18
24
|
pub fn wait(s: *Semaphore, io: Io) Io.Cancelable!void {
|
|
25
|
+
s.waitTimeout(io, .none) catch |err| switch (err) {
|
|
26
|
+
error.Timeout => unreachable,
|
|
27
|
+
error.Canceled => |e| return e,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
pub const WaitTimeoutError = Io.Cancelable || Io.Timeout.Error;
|
|
32
|
+
|
|
33
|
+
/// Blocks until a `permit` is available and consumes a single one.
|
|
34
|
+
/// Unblocks without consuming a `permit` when canceled or when the provided
|
|
35
|
+
/// timeout expires before a `permit` is available.
|
|
36
|
+
///
|
|
37
|
+
/// See also:
|
|
38
|
+
/// * `wait`
|
|
39
|
+
/// * `waitUncancelable`
|
|
40
|
+
pub fn waitTimeout(s: *Semaphore, io: Io, timeout: Io.Timeout) WaitTimeoutError!void {
|
|
41
|
+
const deadline = timeout.toDeadline(io);
|
|
19
42
|
try s.mutex.lock(io);
|
|
20
43
|
defer s.mutex.unlock(io);
|
|
21
|
-
while (s.permits == 0) try s.cond.
|
|
44
|
+
while (s.permits == 0) try s.cond.waitTimeout(io, &s.mutex, deadline);
|
|
22
45
|
s.permits -= 1;
|
|
23
46
|
if (s.permits > 0) s.cond.signal(io);
|
|
24
47
|
}
|
|
25
48
|
|
|
49
|
+
/// Blocks until a `permit` is available and consumes a single one.
|
|
50
|
+
///
|
|
51
|
+
/// See also:
|
|
52
|
+
/// * `wait`
|
|
53
|
+
/// * `waitTimeout`
|
|
26
54
|
pub fn waitUncancelable(s: *Semaphore, io: Io) void {
|
|
27
55
|
s.mutex.lockUncancelable(io);
|
|
28
56
|
defer s.mutex.unlock(io);
|
|
@@ -31,6 +59,7 @@ pub fn waitUncancelable(s: *Semaphore, io: Io) void {
|
|
|
31
59
|
if (s.permits > 0) s.cond.signal(io);
|
|
32
60
|
}
|
|
33
61
|
|
|
62
|
+
/// Makes an additional `permit` available.
|
|
34
63
|
pub fn post(s: *Semaphore, io: Io) void {
|
|
35
64
|
s.mutex.lockUncancelable(io);
|
|
36
65
|
defer s.mutex.unlock(io);
|
|
@@ -39,27 +68,93 @@ pub fn post(s: *Semaphore, io: Io) void {
|
|
|
39
68
|
s.cond.signal(io);
|
|
40
69
|
}
|
|
41
70
|
|
|
42
|
-
test
|
|
43
|
-
if (builtin.single_threaded) return error.SkipZigTest;
|
|
71
|
+
test wait {
|
|
44
72
|
const io = testing.io;
|
|
45
73
|
|
|
46
|
-
const
|
|
47
|
-
sem:
|
|
48
|
-
n:
|
|
74
|
+
const Context = struct {
|
|
75
|
+
sem: Semaphore = .{ .permits = 1 },
|
|
76
|
+
n: u32 = 0,
|
|
77
|
+
|
|
49
78
|
fn worker(ctx: *@This()) !void {
|
|
50
79
|
try ctx.sem.wait(io);
|
|
51
|
-
ctx.n
|
|
80
|
+
ctx.n += 1;
|
|
52
81
|
ctx.sem.post(io);
|
|
53
82
|
}
|
|
54
83
|
};
|
|
55
|
-
|
|
56
|
-
var
|
|
57
|
-
|
|
58
|
-
var
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
for (
|
|
63
|
-
|
|
64
|
-
try
|
|
84
|
+
|
|
85
|
+
var ctx: Context = .{};
|
|
86
|
+
|
|
87
|
+
var group: Io.Group = .init;
|
|
88
|
+
defer group.cancel(io);
|
|
89
|
+
|
|
90
|
+
const num_workers = 3;
|
|
91
|
+
for (0..num_workers) |_| group.async(io, Context.worker, .{&ctx});
|
|
92
|
+
|
|
93
|
+
try group.await(io);
|
|
94
|
+
try testing.expectEqual(num_workers, ctx.n);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
test waitTimeout {
|
|
98
|
+
const io = testing.io;
|
|
99
|
+
|
|
100
|
+
const Context = struct {
|
|
101
|
+
ready: Io.Event = .unset,
|
|
102
|
+
sem: Semaphore = .{ .permits = 0 },
|
|
103
|
+
value: u32 = 0,
|
|
104
|
+
|
|
105
|
+
fn worker(ctx: *@This()) !void {
|
|
106
|
+
defer ctx.ready.set(io);
|
|
107
|
+
|
|
108
|
+
try testing.expectError(error.Timeout, ctx.sem.waitTimeout(io, .{ .duration = .{
|
|
109
|
+
.raw = .fromMilliseconds(1),
|
|
110
|
+
.clock = .awake,
|
|
111
|
+
} }));
|
|
112
|
+
try testing.expectEqual(0, ctx.value);
|
|
113
|
+
|
|
114
|
+
ctx.ready.set(io);
|
|
115
|
+
|
|
116
|
+
while (ctx.value == 0) try ctx.sem.wait(io);
|
|
117
|
+
try testing.expectEqual(1, ctx.value);
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
var ctx: Context = .{};
|
|
122
|
+
|
|
123
|
+
var future = io.concurrent(Context.worker, .{&ctx}) catch |err| switch (err) {
|
|
124
|
+
error.ConcurrencyUnavailable => return error.SkipZigTest,
|
|
125
|
+
};
|
|
126
|
+
defer future.cancel(io) catch {};
|
|
127
|
+
|
|
128
|
+
try ctx.ready.wait(io);
|
|
129
|
+
|
|
130
|
+
ctx.value = 1;
|
|
131
|
+
ctx.sem.post(io);
|
|
132
|
+
|
|
133
|
+
try future.await(io);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
test waitUncancelable {
|
|
137
|
+
const io = testing.io;
|
|
138
|
+
|
|
139
|
+
const Context = struct {
|
|
140
|
+
sem: Semaphore = .{ .permits = 1 },
|
|
141
|
+
n: u32 = 0,
|
|
142
|
+
|
|
143
|
+
fn worker(ctx: *@This()) !void {
|
|
144
|
+
ctx.sem.waitUncancelable(io);
|
|
145
|
+
ctx.n += 1;
|
|
146
|
+
ctx.sem.post(io);
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
var ctx: Context = .{};
|
|
151
|
+
|
|
152
|
+
var group: Io.Group = .init;
|
|
153
|
+
defer group.cancel(io);
|
|
154
|
+
|
|
155
|
+
const num_workers = 3;
|
|
156
|
+
for (0..num_workers) |_| group.async(io, Context.worker, .{&ctx});
|
|
157
|
+
|
|
158
|
+
try group.await(io);
|
|
159
|
+
try testing.expectEqual(num_workers, ctx.n);
|
|
65
160
|
}
|