diff options
author | des <des@FreeBSD.org> | 2008-02-03 22:38:10 +0000 |
---|---|---|
committer | des <des@FreeBSD.org> | 2008-02-03 22:38:10 +0000 |
commit | 72d185548f88b6924d5a926aa9b6877ebe113169 (patch) | |
tree | 79362381794d659312db4ce0c9cff22878c851bf /lib/libthr/thread/thr_mutex.c | |
parent | d645bec45a695d4bcad9263c30977af43db44b19 (diff) | |
download | FreeBSD-src-72d185548f88b6924d5a926aa9b6877ebe113169.zip FreeBSD-src-72d185548f88b6924d5a926aa9b6877ebe113169.tar.gz |
Add pthread_mutex_islocked_np(), a cheap way to verify that a mutex is
locked. This is intended primarily to support the userland equivalent
of the various *_ASSERT_LOCKED() macros we have in the kernel.
MFC after: 2 weeks
Diffstat (limited to 'lib/libthr/thread/thr_mutex.c')
-rw-r--r-- | lib/libthr/thread/thr_mutex.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/libthr/thread/thr_mutex.c b/lib/libthr/thread/thr_mutex.c index 6a97761..032f2e3 100644 --- a/lib/libthr/thread/thr_mutex.c +++ b/lib/libthr/thread/thr_mutex.c @@ -87,6 +87,7 @@ int __pthread_mutex_setspinloops_np(pthread_mutex_t *mutex, int count); int _pthread_mutex_setyieldloops_np(pthread_mutex_t *mutex, int count); int _pthread_mutex_getyieldloops_np(pthread_mutex_t *mutex, int *count); int __pthread_mutex_setyieldloops_np(pthread_mutex_t *mutex, int count); +int _pthread_mutex_islocked_np(pthread_mutex_t *mutex); static int mutex_self_trylock(pthread_mutex_t); static int mutex_self_lock(pthread_mutex_t, @@ -111,6 +112,7 @@ __weak_reference(_pthread_mutex_getspinloops_np, pthread_mutex_getspinloops_np); __weak_reference(__pthread_mutex_setyieldloops_np, pthread_mutex_setyieldloops_np); __weak_reference(_pthread_mutex_getyieldloops_np, pthread_mutex_getyieldloops_np); +__weak_reference(_pthread_mutex_islocked_np, pthread_mutex_islocked_np); static int mutex_init(pthread_mutex_t *mutex, @@ -863,3 +865,17 @@ __pthread_mutex_setyieldloops_np(pthread_mutex_t *mutex, int count) (*mutex)->m_yieldloops = count; return (0); } + +int +_pthread_mutex_islocked_np(pthread_mutex_t *mutex) +{ + struct pthread *curthread = _get_curthread(); + int ret; + + if (__predict_false(*mutex == NULL)) { + ret = init_static(curthread, mutex); + if (__predict_false(ret)) + return (ret); + } + return ((*mutex)->m_qe.tqe_prev != NULL); +} |