X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fthread%2Fpthread_mutex_lock.c;h=d0c93cab50119feee0741b14006f346f000b87c6;hb=e6def544358afd5648a428d2e02c147a1f901048;hp=477b3d808175164ed1c1c2b3460b7673d19dce71;hpb=047e434ef5fd5437a74f98f63c40a77a683f7f3f;p=musl diff --git a/src/thread/pthread_mutex_lock.c b/src/thread/pthread_mutex_lock.c index 477b3d80..d0c93cab 100644 --- a/src/thread/pthread_mutex_lock.c +++ b/src/thread/pthread_mutex_lock.c @@ -1,14 +1,14 @@ #include "pthread_impl.h" -int pthread_mutex_lock(pthread_mutex_t *m) +int __pthread_mutex_timedlock(pthread_mutex_t *restrict, const struct timespec *restrict); + +int __pthread_mutex_lock(pthread_mutex_t *m) { - int r; - while ((r=pthread_mutex_trylock(m)) == EBUSY) { - if (!(r=m->_m_lock) || (r&0x40000000)) continue; - if ((m->_m_type&3) == PTHREAD_MUTEX_ERRORCHECK - && (r&0x1fffffff) == pthread_self()->tid) - return EDEADLK; - __wait(&m->_m_lock, &m->_m_waiters, r, 0); - } - return r; + if ((m->_m_type&15) == PTHREAD_MUTEX_NORMAL + && !a_cas(&m->_m_lock, 0, EBUSY)) + return 0; + + return __pthread_mutex_timedlock(m, 0); } + +weak_alias(__pthread_mutex_lock, pthread_mutex_lock);