diff options
author | davidxu <davidxu@FreeBSD.org> | 2006-12-14 13:22:02 +0000 |
---|---|---|
committer | davidxu <davidxu@FreeBSD.org> | 2006-12-14 13:22:02 +0000 |
commit | 26cbb63b3f17779de69c66b42a44cfe79fac3326 (patch) | |
tree | 638b9f42bad289d72e784a9d258f1e7e1eee2eb2 /lib/libthr/thread/thr_umtx.h | |
parent | 5cd76c6b3834f2ab00f2953bd3d1180427dd8995 (diff) | |
download | FreeBSD-src-26cbb63b3f17779de69c66b42a44cfe79fac3326.zip FreeBSD-src-26cbb63b3f17779de69c66b42a44cfe79fac3326.tar.gz |
Create inline function _thr_umutex_trylock2 to only try one atomic
operation, if it is failed, we call syscall directly, this saves
one atomic operation per lock contention.
Diffstat (limited to 'lib/libthr/thread/thr_umtx.h')
-rw-r--r-- | lib/libthr/thread/thr_umtx.h | 8 |
1 files changed, 8 insertions, 0 deletions
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)) |