summaryrefslogtreecommitdiff
path: root/src/thread/pthread_mutex_timedlock.c
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2014-08-25 20:16:26 -0400
committerRich Felker <dalias@aerifal.cx>2014-08-25 20:16:26 -0400
commit97a7512b6819014d15c679c8998caa0006d13c29 (patch)
tree0203f9cb4abd79be05dba04696903ef51e2dbc44 /src/thread/pthread_mutex_timedlock.c
parent2ff714c6138da8abb50fd532503fd8d68a18811a (diff)
downloadmusl-97a7512b6819014d15c679c8998caa0006d13c29.tar.gz
spin before waiting on futex in mutex and rwlock lock operations
Diffstat (limited to 'src/thread/pthread_mutex_timedlock.c')
-rw-r--r--src/thread/pthread_mutex_timedlock.c6
1 files changed, 6 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;