From 97a7512b6819014d15c679c8998caa0006d13c29 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Mon, 25 Aug 2014 20:16:26 -0400 Subject: spin before waiting on futex in mutex and rwlock lock operations --- src/thread/pthread_rwlock_timedwrlock.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/thread/pthread_rwlock_timedwrlock.c') 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; -- cgit v1.2.1