about summary refs log tree commit diff
path: root/src/thread/pthread_rwlock_timedrdlock.c
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2014-08-25 20:24:07 -0400
committerRich Felker <dalias@aerifal.cx>2014-08-25 20:24:07 -0400
commitf5fb20b0e934770c37093105524ea644dcaba5e2 (patch)
treedcf0555f52553e2ef67b6aef1d8de05b5c89bd8a /src/thread/pthread_rwlock_timedrdlock.c
parent97a7512b6819014d15c679c8998caa0006d13c29 (diff)
downloadmusl-f5fb20b0e934770c37093105524ea644dcaba5e2.tar.gz
musl-f5fb20b0e934770c37093105524ea644dcaba5e2.tar.xz
musl-f5fb20b0e934770c37093105524ea644dcaba5e2.zip
refrain from spinning on locks when there is already a waiter
if there is already a waiter for a lock, spinning on the lock is
essentially an attempt to steal it from whichever waiter would obtain
it via any priority rules in place, and is therefore undesirable. in
the current implementation, there is always an inherent race window at
unlock during which a newly-arriving thread may steal the lock from
the existing waiters, but we should aim to keep this window minimal
rather than enlarging it.
Diffstat (limited to 'src/thread/pthread_rwlock_timedrdlock.c')
-rw-r--r--src/thread/pthread_rwlock_timedrdlock.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/thread/pthread_rwlock_timedrdlock.c b/src/thread/pthread_rwlock_timedrdlock.c
index 884b7a1e..ea50da4a 100644
--- a/src/thread/pthread_rwlock_timedrdlock.c
+++ b/src/thread/pthread_rwlock_timedrdlock.c
@@ -8,7 +8,7 @@ int pthread_rwlock_timedrdlock(pthread_rwlock_t *restrict rw, const struct times
 	if (r != EBUSY) return r;
 	
 	int spins = 100;
-	while (spins-- && rw->_rw_lock) a_spin();
+	while (spins-- && rw->_rw_lock && !rw->_rw_waiters) a_spin();
 
 	while ((r=pthread_rwlock_tryrdlock(rw))==EBUSY) {
 		if (!(r=rw->_rw_lock) || (r&0x7fffffff)!=0x7fffffff) continue;