diff options
-rw-r--r-- | lib/libthr/thread/thr_mutex.c | 6 | ||||
-rw-r--r-- | lib/libthr/thread/thr_umtx.h | 8 |
2 files changed, 11 insertions, 3 deletions
diff --git a/lib/libthr/thread/thr_mutex.c b/lib/libthr/thread/thr_mutex.c index 46e516c..aae27aa 100644 --- a/lib/libthr/thread/thr_mutex.c +++ b/lib/libthr/thread/thr_mutex.c @@ -343,7 +343,7 @@ mutex_lock_common(struct pthread *curthread, pthread_mutex_t *mutex, id = TID(curthread); m = *mutex; - ret = _thr_umutex_trylock(&m->m_lock, id); + ret = _thr_umutex_trylock2(&m->m_lock, id); if (ret == 0) { m->m_owner = curthread; /* Add to the list of owned mutexes: */ @@ -356,7 +356,7 @@ mutex_lock_common(struct pthread *curthread, pthread_mutex_t *mutex, ret = mutex_self_lock(m, abstime); } else { if (abstime == NULL) { - ret = _thr_umutex_lock(&m->m_lock, id); + ret = __thr_umutex_lock(&m->m_lock); } else if (__predict_false( abstime->tv_sec < 0 || abstime->tv_nsec < 0 || abstime->tv_nsec >= 1000000000)) { @@ -364,7 +364,7 @@ mutex_lock_common(struct pthread *curthread, pthread_mutex_t *mutex, } else { clock_gettime(CLOCK_REALTIME, &ts); TIMESPEC_SUB(&ts2, abstime, &ts); - ret = _thr_umutex_timedlock(&m->m_lock, id, &ts2); + ret = __thr_umutex_timedlock(&m->m_lock, &ts2); /* * Timed out wait is not restarted if * it was interrupted, not worth to do it. diff --git a/lib/libthr/thread/thr_umtx.h b/lib/libthr/thread/thr_umtx.h index a0f331a..8696320 100644 --- a/lib/libthr/thread/thr_umtx.h +++ b/lib/libthr/thread/thr_umtx.h @@ -65,6 +65,14 @@ _thr_umutex_trylock(struct umutex *mtx, uint32_t id) } static inline int +_thr_umutex_trylock2(struct umutex *mtx, uint32_t id) +{ + if (atomic_cmpset_acq_32(&mtx->m_owner, UMUTEX_UNOWNED, id)) + return (0); + return (EBUSY); +} + +static inline int _thr_umutex_lock(struct umutex *mtx, uint32_t id) { if (atomic_cmpset_acq_32(&mtx->m_owner, UMUTEX_UNOWNED, id)) |