[COMMIT osv master] libc/pthread: Make pthread_rwlock_trywrlock/tryrdlock posix compatible

2 views
Skip to first unread message

Commit Bot

unread,
Jan 31, 2024, 12:43:10 PMJan 31
to osv...@googlegroups.com, Valentin Ghita
From: Valentin Ghita <val...@gmail.com>
Committer: WALDEMAR KOZACZUK <jwkoz...@gmail.com>
Branch: master

libc/pthread: Make pthread_rwlock_trywrlock/tryrdlock posix compatible

The current implementations of pthread_rwlock_trywrlock and pthread_rwlock_tryrdlock
don't follow the POSIX specification and return incorrect values.
Fix the return values to follow the specification.

Signed-off-by: Valentin Ghita <val...@gmail.com>

---
diff --git a/libc/pthread.cc b/libc/pthread.cc
--- a/libc/pthread.cc
+++ b/libc/pthread.cc
@@ -501,8 +501,10 @@ int pthread_rwlock_destroy(pthread_rwlock_t *rw)

int pthread_rwlock_trywrlock(pthread_rwlock_t *rw)
{
- from_libc(rw)->try_wlock();
- return 0;
+ if (from_libc(rw)->try_wlock()) {
+ return 0;
+ }
+ return EBUSY;
}

int pthread_rwlock_wrlock(pthread_rwlock_t *rw)
@@ -519,7 +521,10 @@ int pthread_rwlock_rdlock(pthread_rwlock_t *rw)

int pthread_rwlock_tryrdlock(pthread_rwlock_t *rw)
{
- return from_libc(rw)->try_rlock();
+ if (from_libc(rw)->try_rlock()) {
+ return 0;
+ }
+ return EBUSY;
}

int pthread_rwlockattr_destroy(pthread_rwlockattr_t *attr)
Reply all
Reply to author
Forward
0 new messages