@@ -196,7 +196,10 @@ const DarwinImpl = struct {
196
196
var timeout_overflowed = false ;
197
197
198
198
const addr : * const anyopaque = ptr ;
199
- const flags = c .UL_COMPARE_AND_WAIT | c .ULF_NO_ERRNO ;
199
+ const flags : c.UL = .{
200
+ .op = .COMPARE_AND_WAIT ,
201
+ .NO_ERRNO = true ,
202
+ };
200
203
const status = blk : {
201
204
if (supports_ulock_wait2 ) {
202
205
break :blk c .__ulock_wait2 (flags , addr , expect , timeout_ns , 0 );
@@ -228,10 +231,11 @@ const DarwinImpl = struct {
228
231
}
229
232
230
233
fn wake (ptr : * const atomic .Value (u32 ), max_waiters : u32 ) void {
231
- var flags : u32 = c .UL_COMPARE_AND_WAIT | c .ULF_NO_ERRNO ;
232
- if (max_waiters > 1 ) {
233
- flags |= c .ULF_WAKE_ALL ;
234
- }
234
+ const flags : c.UL = .{
235
+ .op = .COMPARE_AND_WAIT ,
236
+ .NO_ERRNO = true ,
237
+ .WAKE_ALL = max_waiters > 1 ,
238
+ };
235
239
236
240
while (true ) {
237
241
const addr : * const anyopaque = ptr ;
@@ -242,7 +246,7 @@ const DarwinImpl = struct {
242
246
.INTR = > continue , // spurious wake()
243
247
.FAULT = > unreachable , // __ulock_wake doesn't generate EFAULT according to darwin pthread_cond_t
244
248
.NOENT = > return , // nothing was woken up
245
- .ALREADY = > unreachable , // only for ULF_WAKE_THREAD
249
+ .ALREADY = > unreachable , // only for UL.Op.WAKE_THREAD
246
250
else = > unreachable ,
247
251
}
248
252
}
@@ -254,8 +258,8 @@ const LinuxImpl = struct {
254
258
fn wait (ptr : * const atomic .Value (u32 ), expect : u32 , timeout : ? u64 ) error {Timeout }! void {
255
259
var ts : linux.timespec = undefined ;
256
260
if (timeout ) | timeout_ns | {
257
- ts .tv_sec = @as (@TypeOf (ts .tv_sec ), @intCast (timeout_ns / std .time .ns_per_s ));
258
- ts .tv_nsec = @as (@TypeOf (ts .tv_nsec ), @intCast (timeout_ns % std .time .ns_per_s ));
261
+ ts .sec = @as (@TypeOf (ts .sec ), @intCast (timeout_ns / std .time .ns_per_s ));
262
+ ts .nsec = @as (@TypeOf (ts .nsec ), @intCast (timeout_ns % std .time .ns_per_s ));
259
263
}
260
264
261
265
const rc = linux .futex_wait (
@@ -306,10 +310,10 @@ const FreebsdImpl = struct {
306
310
tm_ptr = & tm ;
307
311
tm_size = @sizeOf (@TypeOf (tm ));
308
312
309
- tm ._flags = 0 ; // use relative time not UMTX_ABSTIME
310
- tm ._clockid = c . CLOCK .MONOTONIC ;
311
- tm ._timeout . tv_sec = @as (@TypeOf (tm ._timeout . tv_sec ), @intCast (timeout_ns / std .time .ns_per_s ));
312
- tm ._timeout . tv_nsec = @as (@TypeOf (tm ._timeout . tv_nsec ), @intCast (timeout_ns % std .time .ns_per_s ));
313
+ tm .flags = 0 ; // use relative time not UMTX_ABSTIME
314
+ tm .clockid = .MONOTONIC ;
315
+ tm .timeout . sec = @as (@TypeOf (tm .timeout . sec ), @intCast (timeout_ns / std .time .ns_per_s ));
316
+ tm .timeout . nsec = @as (@TypeOf (tm .timeout . nsec ), @intCast (timeout_ns % std .time .ns_per_s ));
313
317
}
314
318
315
319
const rc = c ._umtx_op (
@@ -356,16 +360,16 @@ const OpenbsdImpl = struct {
356
360
fn wait (ptr : * const atomic .Value (u32 ), expect : u32 , timeout : ? u64 ) error {Timeout }! void {
357
361
var ts : c.timespec = undefined ;
358
362
if (timeout ) | timeout_ns | {
359
- ts .tv_sec = @as (@TypeOf (ts .tv_sec ), @intCast (timeout_ns / std .time .ns_per_s ));
360
- ts .tv_nsec = @as (@TypeOf (ts .tv_nsec ), @intCast (timeout_ns % std .time .ns_per_s ));
363
+ ts .sec = @as (@TypeOf (ts .sec ), @intCast (timeout_ns / std .time .ns_per_s ));
364
+ ts .nsec = @as (@TypeOf (ts .nsec ), @intCast (timeout_ns % std .time .ns_per_s ));
361
365
}
362
366
363
367
const rc = c .futex (
364
368
@as (* const volatile u32 , @ptrCast (& ptr .raw )),
365
- c .FUTEX_WAIT | c .FUTEX_PRIVATE_FLAG ,
369
+ c .FUTEX . WAIT | c .FUTEX . PRIVATE_FLAG ,
366
370
@as (c_int , @bitCast (expect )),
367
371
if (timeout != null ) & ts else null ,
368
- null , // FUTEX_WAIT takes no requeue address
372
+ null , // FUTEX.WAIT takes no requeue address
369
373
);
370
374
371
375
switch (std .posix .errno (rc )) {
@@ -387,10 +391,10 @@ const OpenbsdImpl = struct {
387
391
fn wake (ptr : * const atomic .Value (u32 ), max_waiters : u32 ) void {
388
392
const rc = c .futex (
389
393
@as (* const volatile u32 , @ptrCast (& ptr .raw )),
390
- c .FUTEX_WAKE | c .FUTEX_PRIVATE_FLAG ,
394
+ c .FUTEX . WAKE | c .FUTEX . PRIVATE_FLAG ,
391
395
std .math .cast (c_int , max_waiters ) orelse std .math .maxInt (c_int ),
392
- null , // FUTEX_WAKE takes no timeout ptr
393
- null , // FUTEX_WAKE takes no requeue address
396
+ null , // FUTEX.WAKE takes no timeout ptr
397
+ null , // FUTEX.WAKE takes no requeue address
394
398
);
395
399
396
400
// returns number of threads woken up.
@@ -540,12 +544,12 @@ const PosixImpl = struct {
540
544
var ts : c.timespec = undefined ;
541
545
if (timeout ) | timeout_ns | {
542
546
std .posix .clock_gettime (c .CLOCK .REALTIME , & ts ) catch unreachable ;
543
- ts .tv_sec + |= @as (@TypeOf (ts .tv_sec ), @intCast (timeout_ns / std .time .ns_per_s ));
544
- ts .tv_nsec += @as (@TypeOf (ts .tv_nsec ), @intCast (timeout_ns % std .time .ns_per_s ));
547
+ ts .sec + |= @as (@TypeOf (ts .sec ), @intCast (timeout_ns / std .time .ns_per_s ));
548
+ ts .nsec += @as (@TypeOf (ts .nsec ), @intCast (timeout_ns % std .time .ns_per_s ));
545
549
546
- if (ts .tv_nsec >= std .time .ns_per_s ) {
547
- ts .tv_sec + |= 1 ;
548
- ts .tv_nsec -= std .time .ns_per_s ;
550
+ if (ts .nsec >= std .time .ns_per_s ) {
551
+ ts .sec + |= 1 ;
552
+ ts .nsec -= std .time .ns_per_s ;
549
553
}
550
554
}
551
555
0 commit comments