diff --git a/include/pthread_np.h b/include/pthread_np.h index fdd497030f89..06b2f5fc66c7 100644 --- a/include/pthread_np.h +++ b/include/pthread_np.h @@ -53,6 +53,7 @@ int pthread_mutex_getspinloops_np(pthread_mutex_t *mutex, int *count); int pthread_mutex_setspinloops_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); int pthread_single_np(void); void pthread_suspend_all_np(void); int pthread_suspend_np(pthread_t); diff --git a/lib/libthr/pthread.map b/lib/libthr/pthread.map index c6e146b6dafe..dfd6c00590e4 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 6a977612a04e..032f2e34371d 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); +}