From 72d185548f88b6924d5a926aa9b6877ebe113169 Mon Sep 17 00:00:00 2001 From: des Date: Sun, 3 Feb 2008 22:38:10 +0000 Subject: 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 --- lib/libthr/pthread.map | 15 +++++++++++++++ lib/libthr/thread/thr_mutex.c | 16 ++++++++++++++++ 2 files changed, 31 insertions(+) (limited to 'lib/libthr') diff --git a/lib/libthr/pthread.map b/lib/libthr/pthread.map index c6e146b..dfd6c00 100644 --- a/lib/libthr/pthread.map +++ b/lib/libthr/pthread.map @@ -395,3 +395,18 @@ global: local: *; }; + +FBSD_1.1 { +global: + pthread_mutex_islocked_np; +local: + *; +} FBSD_1.0; + +FBSDprivate_1.1 { +global: + _pthread_mutex_islocked_np; +local: + *; +} FBSDprivate_1.0; + 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); +} -- cgit v1.1