summaryrefslogtreecommitdiff
path: root/05/musl-0.6.0/src/thread/pthread_rwlock_trywrlock.c
diff options
context:
space:
mode:
Diffstat (limited to '05/musl-0.6.0/src/thread/pthread_rwlock_trywrlock.c')
-rw-r--r--05/musl-0.6.0/src/thread/pthread_rwlock_trywrlock.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/05/musl-0.6.0/src/thread/pthread_rwlock_trywrlock.c b/05/musl-0.6.0/src/thread/pthread_rwlock_trywrlock.c
new file mode 100644
index 0000000..1bcf7c9
--- /dev/null
+++ b/05/musl-0.6.0/src/thread/pthread_rwlock_trywrlock.c
@@ -0,0 +1,13 @@
+#include "pthread_impl.h"
+
+int pthread_rwlock_trywrlock(pthread_rwlock_t *rw)
+{
+ if (a_xchg(&rw->_rw_wrlock, 1))
+ return EAGAIN;
+ if (rw->_rw_readers) {
+ a_store(&rw->_rw_wrlock, 0);
+ return EAGAIN;
+ }
+ rw->_rw_owner = pthread_self()->tid;
+ return 0;
+}