authorgravatar for vincent@rischmann.frVincent Rischmann <vincent@rischmann.fr> 2021-02-01 21:16:39+01:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2021-02-01 15:16:39-05:00
log16905d96f70045fd9d630219c85a2eb508db38b4
treeb06e307af5953f5f2d58836f2813c5ec3c323bfc
parent11f6916f9bd9fbaf81a4bd60fd375eff8db78374
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

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

1 files changed, 14 insertions(+), 2 deletions(-)

lib/std/Thread/Condition.zig+14-2
......@@ -8,7 +8,7 @@
88//! to wake up. Spurious wakeups are possible.
99//! This API supports static initialization and does not require deinitialization.
1010
11impl: Impl,
11impl: Impl = .{},
1212
1313const std = @import("../std.zig");
1414const Condition = @This();
......@@ -17,6 +17,18 @@ const linux = std.os.linux;
1717const Mutex = std.Thread.Mutex;
1818const assert = std.debug.assert;
1919
20pub fn wait(cond: *Condition, mutex: *Mutex) void {
21 cond.impl.wait(mutex);
22}
23
24pub fn signal(cond: *Condition) void {
25 cond.impl.signal();
26}
27
28pub fn broadcast(cond: *Condition) void {
29 cond.impl.broadcast();
30}
31
2032const Impl = if (std.builtin.single_threaded)
2133 SingleThreadedCondition
2234else if (std.Target.current.os.tag == .windows)
......@@ -62,7 +74,7 @@ pub const PthreadCondition = struct {
6274 cond: std.c.pthread_cond_t = .{},
6375
6476 pub fn wait(cond: *PthreadCondition, mutex: *Mutex) void {
65 const rc = std.c.pthread_cond_wait(&cond.cond, &mutex.mutex);
77 const rc = std.c.pthread_cond_wait(&cond.cond, &mutex.impl.pthread_mutex);
6678 assert(rc == 0);
6779 }
6880