mirror of
https://github.com/ziglang/zig.git
synced 2026-01-20 22:35:24 +00:00
Fixes for std.Thread.Condition (#7883)
* thread/condition: fix PthreadCondition compilation * thread/condition: add wait, signal and broadcast This is like std.Thread.Mutex which forwards calls to `impl`; avoids having to call `cond.impl` every time. * thread/condition: initialize the implementation
This commit is contained in:
parent
11f6916f9b
commit
16905d96f7
@ -8,7 +8,7 @@
|
||||
//! to wake up. Spurious wakeups are possible.
|
||||
//! This API supports static initialization and does not require deinitialization.
|
||||
|
||||
impl: Impl,
|
||||
impl: Impl = .{},
|
||||
|
||||
const std = @import("../std.zig");
|
||||
const Condition = @This();
|
||||
@ -17,6 +17,18 @@ const linux = std.os.linux;
|
||||
const Mutex = std.Thread.Mutex;
|
||||
const assert = std.debug.assert;
|
||||
|
||||
pub fn wait(cond: *Condition, mutex: *Mutex) void {
|
||||
cond.impl.wait(mutex);
|
||||
}
|
||||
|
||||
pub fn signal(cond: *Condition) void {
|
||||
cond.impl.signal();
|
||||
}
|
||||
|
||||
pub fn broadcast(cond: *Condition) void {
|
||||
cond.impl.broadcast();
|
||||
}
|
||||
|
||||
const Impl = if (std.builtin.single_threaded)
|
||||
SingleThreadedCondition
|
||||
else if (std.Target.current.os.tag == .windows)
|
||||
@ -62,7 +74,7 @@ pub const PthreadCondition = struct {
|
||||
cond: std.c.pthread_cond_t = .{},
|
||||
|
||||
pub fn wait(cond: *PthreadCondition, mutex: *Mutex) void {
|
||||
const rc = std.c.pthread_cond_wait(&cond.cond, &mutex.mutex);
|
||||
const rc = std.c.pthread_cond_wait(&cond.cond, &mutex.impl.pthread_mutex);
|
||||
assert(rc == 0);
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user