diff options
author | Rich Felker <dalias@aerifal.cx> | 2014-08-25 20:16:26 -0400 |
---|---|---|
committer | Rich Felker <dalias@aerifal.cx> | 2014-08-25 20:16:26 -0400 |
commit | 97a7512b6819014d15c679c8998caa0006d13c29 (patch) | |
tree | 0203f9cb4abd79be05dba04696903ef51e2dbc44 /src | |
parent | 2ff714c6138da8abb50fd532503fd8d68a18811a (diff) | |
download | musl-97a7512b6819014d15c679c8998caa0006d13c29.tar.gz musl-97a7512b6819014d15c679c8998caa0006d13c29.tar.bz2 musl-97a7512b6819014d15c679c8998caa0006d13c29.tar.xz musl-97a7512b6819014d15c679c8998caa0006d13c29.zip |
spin before waiting on futex in mutex and rwlock lock operations
Diffstat (limited to 'src')
-rw-r--r-- | src/thread/pthread_mutex_timedlock.c | 6 | ||||
-rw-r--r-- | src/thread/pthread_rwlock_timedrdlock.c | 7 | ||||
-rw-r--r-- | src/thread/pthread_rwlock_timedwrlock.c | 7 |
3 files changed, 20 insertions, 0 deletions
diff --git a/src/thread/pthread_mutex_timedlock.c b/src/thread/pthread_mutex_timedlock.c index 2a959d25..116a8b7b 100644 --- a/src/thread/pthread_mutex_timedlock.c +++ b/src/thread/pthread_mutex_timedlock.c @@ -8,6 +8,12 @@ int pthread_mutex_timedlock(pthread_mutex_t *restrict m, const struct timespec * int r, t, priv = (m->_m_type & 128) ^ 128; + r = pthread_mutex_trylock(m); + if (r != EBUSY) return r; + + int spins = 100; + while (spins-- && m->_m_lock) a_spin(); + while ((r=pthread_mutex_trylock(m)) == EBUSY) { if (!(r=m->_m_lock) || ((r&0x40000000) && (m->_m_type&4))) continue; diff --git a/src/thread/pthread_rwlock_timedrdlock.c b/src/thread/pthread_rwlock_timedrdlock.c index a2b4d446..884b7a1e 100644 --- a/src/thread/pthread_rwlock_timedrdlock.c +++ b/src/thread/pthread_rwlock_timedrdlock.c @@ -3,6 +3,13 @@ int pthread_rwlock_timedrdlock(pthread_rwlock_t *restrict rw, const struct timespec *restrict at) { int r, t; + + r = pthread_rwlock_tryrdlock(rw); + if (r != EBUSY) return r; + + int spins = 100; + while (spins-- && rw->_rw_lock) a_spin(); + while ((r=pthread_rwlock_tryrdlock(rw))==EBUSY) { if (!(r=rw->_rw_lock) || (r&0x7fffffff)!=0x7fffffff) continue; t = r | 0x80000000; 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; |