mirror of
https://github.com/fluencelabs/musl
synced 2025-07-04 00:51:59 +00:00
spin before waiting on futex in mutex and rwlock lock operations
This commit is contained in:
@ -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;
|
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) {
|
while ((r=pthread_mutex_trylock(m)) == EBUSY) {
|
||||||
if (!(r=m->_m_lock) || ((r&0x40000000) && (m->_m_type&4)))
|
if (!(r=m->_m_lock) || ((r&0x40000000) && (m->_m_type&4)))
|
||||||
continue;
|
continue;
|
||||||
|
@ -3,6 +3,13 @@
|
|||||||
int pthread_rwlock_timedrdlock(pthread_rwlock_t *restrict rw, const struct timespec *restrict at)
|
int pthread_rwlock_timedrdlock(pthread_rwlock_t *restrict rw, const struct timespec *restrict at)
|
||||||
{
|
{
|
||||||
int r, t;
|
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) {
|
while ((r=pthread_rwlock_tryrdlock(rw))==EBUSY) {
|
||||||
if (!(r=rw->_rw_lock) || (r&0x7fffffff)!=0x7fffffff) continue;
|
if (!(r=rw->_rw_lock) || (r&0x7fffffff)!=0x7fffffff) continue;
|
||||||
t = r | 0x80000000;
|
t = r | 0x80000000;
|
||||||
|
@ -3,6 +3,13 @@
|
|||||||
int pthread_rwlock_timedwrlock(pthread_rwlock_t *restrict rw, const struct timespec *restrict at)
|
int pthread_rwlock_timedwrlock(pthread_rwlock_t *restrict rw, const struct timespec *restrict at)
|
||||||
{
|
{
|
||||||
int r, t;
|
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) {
|
while ((r=pthread_rwlock_trywrlock(rw))==EBUSY) {
|
||||||
if (!(r=rw->_rw_lock)) continue;
|
if (!(r=rw->_rw_lock)) continue;
|
||||||
t = r | 0x80000000;
|
t = r | 0x80000000;
|
||||||
|
Reference in New Issue
Block a user