authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-05-08 00:29:57 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-05-08 00:29:57 -07:00
log1d4b3cc3a4a2d7847b607caf3914d1efd2588850
treeb7de8b742b1382e9f5cd14f9d4d62837b3aff3de
parentd5644cedf60338f1dc23e33c7167112a46ede854
signaturebadge-check Signed by SSH key SHA256:4hHJbtBRU58AYXwjL7fkz2fnQHdiye8x1QpTCQ0sHNw

add pthread_rwlock


2 files changed, 65 insertions(+), 0 deletions(-)

mod.zig+58
......@@ -2266,6 +2266,34 @@ pub const libc = struct {
22662266 /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/pthread_mutexattr_init.html
22672267 pub extern fn pthread_mutexattr_init(attr: *pthread_mutexattr_t) c_int;
22682268
2269 /// int pthread_rwlock_destroy(pthread_rwlock_t *rwlock);
2270 /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/pthread_rwlock_destroy.html
2271 pub extern fn pthread_rwlock_destroy(rwlock: *pthread_rwlock_t) c_int;
2272
2273 /// int pthread_rwlock_init(pthread_rwlock_t *restrict rwlock, const pthread_rwlockattr_t *restrict attr);
2274 /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/pthread_rwlock_init.html
2275 pub extern fn pthread_rwlock_init(noalias rwlock: *pthread_rwlock_t, noalias attr: ?*const pthread_rwlockattr_t) c_int;
2276
2277 /// int pthread_rwlock_rdlock(pthread_rwlock_t *rwlock);
2278 /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/pthread_rwlock_rdlock.html
2279 pub extern fn pthread_rwlock_rdlock(rwlock: *pthread_rwlock_t) c_int;
2280
2281 /// int pthread_rwlock_tryrdlock(pthread_rwlock_t *rwlock);
2282 /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/pthread_rwlock_tryrdlock.html
2283 pub extern fn pthread_rwlock_tryrdlock(rwlock: *pthread_rwlock_t) c_int;
2284
2285 /// int pthread_rwlock_trywrlock(pthread_rwlock_t *rwlock);
2286 /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/pthread_rwlock_trywrlock.html
2287 pub extern fn pthread_rwlock_trywrlock(rwlock: *pthread_rwlock_t) c_int;
2288
2289 /// int pthread_rwlock_unlock(pthread_rwlock_t *rwlock);
2290 /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/pthread_rwlock_unlock.html
2291 pub extern fn pthread_rwlock_unlock(rwlock: *pthread_rwlock_t) c_int;
2292
2293 /// int pthread_rwlock_wrlock(pthread_rwlock_t *rwlock);
2294 /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/pthread_rwlock_wrlock.html
2295 pub extern fn pthread_rwlock_wrlock(rwlock: *pthread_rwlock_t) c_int;
2296
22692297 /// pthread_t pthread_self(void);
22702298 /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/pthread_self.html
22712299 pub extern fn pthread_self() pthread_t;
......@@ -2806,6 +2834,8 @@ pub const pthread_mutexattr_t = impdef.pthread_mutexattr_t;
28062834pub const pthread_mutex_t = impdef.pthread_mutex_t;
28072835pub const pthread_condattr_t = impdef.pthread_condattr_t;
28082836pub const pthread_cond_t = impdef.pthread_cond_t;
2837pub const pthread_rwlockattr_t = impdef.pthread_rwlockattr_t;
2838pub const pthread_rwlock_t = impdef.pthread_rwlock_t;
28092839
28102840pub const AT = struct {
28112841 pub const FDCWD = -100;
......@@ -3522,3 +3552,31 @@ pub fn faccessat(fd: c_int, path: [*:0]const u8, amode: c_int, flag: c_int) !voi
35223552 if (rc == -1) return errno.fromInt(errno.fromLibC());
35233553 std.debug.assert(rc == 0);
35243554}
3555pub fn pthread_rwlock_init(noalias rwlock: *pthread_rwlock_t, noalias attr: ?*const pthread_rwlockattr_t) !void {
3556 const rc = libc.pthread_rwlock_init(rwlock, attr);
3557 if (rc != 0) return errno.fromInt(rc);
3558}
3559pub fn pthread_rwlock_destroy(rwlock: *pthread_rwlock_t) !void {
3560 const rc = libc.pthread_rwlock_destroy(rwlock);
3561 if (rc != 0) return errno.fromInt(rc);
3562}
3563pub fn pthread_rwlock_rdlock(rwlock: *pthread_rwlock_t) !void {
3564 const rc = libc.pthread_rwlock_rdlock(rwlock);
3565 if (rc != 0) return errno.fromInt(rc);
3566}
3567pub fn pthread_rwlock_tryrdlock(rwlock: *pthread_rwlock_t) !void {
3568 const rc = libc.pthread_rwlock_tryrdlock(rwlock);
3569 if (rc != 0) return errno.fromInt(rc);
3570}
3571pub fn pthread_rwlock_wrlock(rwlock: *pthread_rwlock_t) !void {
3572 const rc = libc.pthread_rwlock_wrlock(rwlock);
3573 if (rc != 0) return errno.fromInt(rc);
3574}
3575pub fn pthread_rwlock_trywrlock(rwlock: *pthread_rwlock_t) !void {
3576 const rc = libc.pthread_rwlock_trywrlock(rwlock);
3577 if (rc != 0) return errno.fromInt(rc);
3578}
3579pub fn pthread_rwlock_unlock(rwlock: *pthread_rwlock_t) !void {
3580 const rc = libc.pthread_rwlock_unlock(rwlock);
3581 if (rc != 0) return errno.fromInt(rc);
3582}
test.zig+7
......@@ -63,4 +63,11 @@ test {
6363 _ = &linux.flock;
6464 _ = &linux.futimens;
6565 _ = &linux.faccessat;
66 _ = &linux.pthread_rwlock_init;
67 _ = &linux.pthread_rwlock_destroy;
68 _ = &linux.pthread_rwlock_rdlock;
69 _ = &linux.pthread_rwlock_tryrdlock;
70 _ = &linux.pthread_rwlock_wrlock;
71 _ = &linux.pthread_rwlock_trywrlock;
72 _ = &linux.pthread_rwlock_unlock;
6673}