aboutsummaryrefslogtreecommitdiff
path: root/lib/std/Thread/RwLock.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-08-23 17:06:56 -0700
committerAndrew Kelley <andrew@ziglang.org>2021-08-24 01:23:28 -0400
commita98fa56ae9ad437d3e4241bc2c231e0745766ba9 (patch)
treefa621754f81e0007a6f894c0f726e810f0462d95 /lib/std/Thread/RwLock.zig
parent9e3ec98937de07d0e06f483ba8f7e6592b4dd152 (diff)
downloadzig-a98fa56ae9ad437d3e4241bc2c231e0745766ba9.tar.gz
zig-a98fa56ae9ad437d3e4241bc2c231e0745766ba9.zip
std: [breaking] move errno to become an nonexhaustive enum
The primary purpose of this change is to eliminate one usage of `usingnamespace` in the standard library - specifically the usage for errno values in `std.os.linux`. This is accomplished by truncating the `E` prefix from error values, and making errno a proper enum. A similar strategy can be used to eliminate some other `usingnamespace` sites in the std lib.
Diffstat (limited to 'lib/std/Thread/RwLock.zig')
-rw-r--r--lib/std/Thread/RwLock.zig24
1 files changed, 11 insertions, 13 deletions
diff --git a/lib/std/Thread/RwLock.zig b/lib/std/Thread/RwLock.zig
index 1d606a9cf1..0721aad3f7 100644
--- a/lib/std/Thread/RwLock.zig
+++ b/lib/std/Thread/RwLock.zig
@@ -13,7 +13,7 @@ impl: Impl,
const RwLock = @This();
const std = @import("../std.zig");
-const builtin = std.builtin;
+const builtin = @import("builtin");
const assert = std.debug.assert;
const Mutex = std.Thread.Mutex;
const Semaphore = std.Semaphore;
@@ -165,43 +165,41 @@ pub const PthreadRwLock = struct {
}
pub fn deinit(rwl: *PthreadRwLock) void {
- const safe_rc = switch (std.builtin.os.tag) {
- .dragonfly, .netbsd => std.os.EAGAIN,
- else => 0,
+ const safe_rc: std.os.E = switch (builtin.os.tag) {
+ .dragonfly, .netbsd => .AGAIN,
+ else => .SUCCESS,
};
-
const rc = std.c.pthread_rwlock_destroy(&rwl.rwlock);
- assert(rc == 0 or rc == safe_rc);
-
+ assert(rc == .SUCCESS or rc == safe_rc);
rwl.* = undefined;
}
pub fn tryLock(rwl: *PthreadRwLock) bool {
- return pthread_rwlock_trywrlock(&rwl.rwlock) == 0;
+ return pthread_rwlock_trywrlock(&rwl.rwlock) == .SUCCESS;
}
pub fn lock(rwl: *PthreadRwLock) void {
const rc = pthread_rwlock_wrlock(&rwl.rwlock);
- assert(rc == 0);
+ assert(rc == .SUCCESS);
}
pub fn unlock(rwl: *PthreadRwLock) void {
const rc = pthread_rwlock_unlock(&rwl.rwlock);
- assert(rc == 0);
+ assert(rc == .SUCCESS);
}
pub fn tryLockShared(rwl: *PthreadRwLock) bool {
- return pthread_rwlock_tryrdlock(&rwl.rwlock) == 0;
+ return pthread_rwlock_tryrdlock(&rwl.rwlock) == .SUCCESS;
}
pub fn lockShared(rwl: *PthreadRwLock) void {
const rc = pthread_rwlock_rdlock(&rwl.rwlock);
- assert(rc == 0);
+ assert(rc == .SUCCESS);
}
pub fn unlockShared(rwl: *PthreadRwLock) void {
const rc = pthread_rwlock_unlock(&rwl.rwlock);
- assert(rc == 0);
+ assert(rc == .SUCCESS);
}
};