aboutsummaryrefslogtreecommitdiff
path: root/lib/std/Thread/Mutex.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-08-28 12:41:24 -0700
committerAndrew Kelley <andrew@ziglang.org>2021-08-28 12:41:24 -0700
commit6aeab0f323ff14d7ad248e18c372573f7a5a8cd1 (patch)
tree7080297f629f39baa0b742985c5804cf6a2047e8 /lib/std/Thread/Mutex.zig
parent47f7ed1c4cb8acf7fed99a057fb84202962e4b1b (diff)
parent05cf44933d753f7a5a53ab289ea60fd43761de57 (diff)
downloadzig-6aeab0f323ff14d7ad248e18c372573f7a5a8cd1.tar.gz
zig-6aeab0f323ff14d7ad248e18c372573f7a5a8cd1.zip
Merge remote-tracking branch 'origin/master' into llvm13
Conflicts: lib/libcxx/include/__config d57c0cc3bfeff9af297279759ec2b631e6d95140 added support for DragonFlyBSD to libc++ by updating some ifdefs. This needed to be synced with llvm13.
Diffstat (limited to 'lib/std/Thread/Mutex.zig')
-rw-r--r--lib/std/Thread/Mutex.zig38
1 files changed, 16 insertions, 22 deletions
diff --git a/lib/std/Thread/Mutex.zig b/lib/std/Thread/Mutex.zig
index 35095b2a3c..ee54a1582b 100644
--- a/lib/std/Thread/Mutex.zig
+++ b/lib/std/Thread/Mutex.zig
@@ -1,9 +1,3 @@
-// SPDX-License-Identifier: MIT
-// Copyright (c) 2015-2021 Zig Contributors
-// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
-// The MIT license requires this copyright notice to be included in all copies
-// and substantial portions of the software.
-
//! Lock may be held only once. If the same thread tries to acquire
//! the same mutex twice, it deadlocks. This type supports static
//! initialization and is at most `@sizeOf(usize)` in size. When an
@@ -143,9 +137,9 @@ pub const AtomicMutex = struct {
@enumToInt(new_state),
null,
))) {
- 0 => {},
- std.os.EINTR => {},
- std.os.EAGAIN => {},
+ .SUCCESS => {},
+ .INTR => {},
+ .AGAIN => {},
else => unreachable,
}
},
@@ -164,8 +158,8 @@ pub const AtomicMutex = struct {
linux.FUTEX_PRIVATE_FLAG | linux.FUTEX_WAKE,
1,
))) {
- 0 => {},
- std.os.EFAULT => {},
+ .SUCCESS => {},
+ .FAULT => unreachable, // invalid pointer passed to futex_wake
else => unreachable,
}
},
@@ -182,10 +176,10 @@ pub const PthreadMutex = struct {
pub fn release(held: Held) void {
switch (std.c.pthread_mutex_unlock(&held.mutex.pthread_mutex)) {
- 0 => return,
- std.c.EINVAL => unreachable,
- std.c.EAGAIN => unreachable,
- std.c.EPERM => unreachable,
+ .SUCCESS => return,
+ .INVAL => unreachable,
+ .AGAIN => unreachable,
+ .PERM => unreachable,
else => unreachable,
}
}
@@ -195,7 +189,7 @@ pub const PthreadMutex = struct {
/// the mutex is unavailable. Otherwise returns Held. Call
/// release on Held.
pub fn tryAcquire(m: *PthreadMutex) ?Held {
- if (std.c.pthread_mutex_trylock(&m.pthread_mutex) == 0) {
+ if (std.c.pthread_mutex_trylock(&m.pthread_mutex) == .SUCCESS) {
return Held{ .mutex = m };
} else {
return null;
@@ -206,12 +200,12 @@ pub const PthreadMutex = struct {
/// held by the calling thread.
pub fn acquire(m: *PthreadMutex) Held {
switch (std.c.pthread_mutex_lock(&m.pthread_mutex)) {
- 0 => return Held{ .mutex = m },
- std.c.EINVAL => unreachable,
- std.c.EBUSY => unreachable,
- std.c.EAGAIN => unreachable,
- std.c.EDEADLK => unreachable,
- std.c.EPERM => unreachable,
+ .SUCCESS => return Held{ .mutex = m },
+ .INVAL => unreachable,
+ .BUSY => unreachable,
+ .AGAIN => unreachable,
+ .DEADLK => unreachable,
+ .PERM => unreachable,
else => unreachable,
}
}