about summary refs log tree commit diff
path: root/src/thread/pthread_rwlock_timedwrlock.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/thread/pthread_rwlock_timedwrlock.c')
-rw-r--r--src/thread/pthread_rwlock_timedwrlock.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/thread/pthread_rwlock_timedwrlock.c b/src/thread/pthread_rwlock_timedwrlock.c
index 63a32ecb..f02b174b 100644
--- a/src/thread/pthread_rwlock_timedwrlock.c
+++ b/src/thread/pthread_rwlock_timedwrlock.c
@@ -3,6 +3,13 @@
 int pthread_rwlock_timedwrlock(pthread_rwlock_t *restrict rw, const struct timespec *restrict at)
 {
 	int r, t;
+	
+	r = pthread_rwlock_trywrlock(rw);
+	if (r != EBUSY) return r;
+	
+	int spins = 100;
+	while (spins-- && rw->_rw_lock) a_spin();
+
 	while ((r=pthread_rwlock_trywrlock(rw))==EBUSY) {
 		if (!(r=rw->_rw_lock)) continue;
 		t = r | 0x80000000;