about summary refs log tree commit diff
path: root/src/thread/pthread_rwlock_trywrlock.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/thread/pthread_rwlock_trywrlock.c')
-rw-r--r--src/thread/pthread_rwlock_trywrlock.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/thread/pthread_rwlock_trywrlock.c b/src/thread/pthread_rwlock_trywrlock.c
new file mode 100644
index 00000000..c029b874
--- /dev/null
+++ b/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->__wrlock, 1))
+		return EAGAIN;
+	if (rw->__readers) {
+		a_store(&rw->__wrlock, 0);
+		return EAGAIN;
+	}
+	rw->__owner = pthread_self()->tid;
+	return 0;
+}