From 31f6d3ff92de773057286bc54965b8528af415ae Mon Sep 17 00:00:00 2001 From: mtm Date: Wed, 2 Jul 2003 02:05:23 +0000 Subject: Begin making libthr async signal safe. Create a private, single underscore, version of pthread_mutex_unlock for libc. pthread_mutex_lock already has one. These versions are different from the ones that applications will link against because they block all signals from the time a call to lock the mutex is made until it is successfully unlocked. --- lib/libthr/thread/thr_mutex.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'lib/libthr') diff --git a/lib/libthr/thread/thr_mutex.c b/lib/libthr/thread/thr_mutex.c index 3244158..ee615c3 100644 --- a/lib/libthr/thread/thr_mutex.c +++ b/lib/libthr/thread/thr_mutex.c @@ -85,11 +85,11 @@ static pthread_mutexattr_t static_mattr = &static_mutex_attr; /* Single underscore versions provided for libc internal usage: */ __weak_reference(__pthread_mutex_trylock, pthread_mutex_trylock); __weak_reference(__pthread_mutex_lock, pthread_mutex_lock); +__weak_reference(__pthread_mutex_unlock, pthread_mutex_unlock); /* No difference between libc and application usage of these: */ __weak_reference(_pthread_mutex_init, pthread_mutex_init); __weak_reference(_pthread_mutex_destroy, pthread_mutex_destroy); -__weak_reference(_pthread_mutex_unlock, pthread_mutex_unlock); /* @@ -505,6 +505,9 @@ __pthread_mutex_lock(pthread_mutex_t *mutex) return (ret); } +/* + * Libc internal. + */ int _pthread_mutex_lock(pthread_mutex_t *mutex) { @@ -513,6 +516,8 @@ _pthread_mutex_lock(pthread_mutex_t *mutex) if (_thread_initial == NULL) _thread_init(); + _thread_sigblock(); + if (mutex == NULL) ret = EINVAL; @@ -524,15 +529,30 @@ _pthread_mutex_lock(pthread_mutex_t *mutex) ((ret = mutex_init(mutex, 1)) == 0)) ret = mutex_lock_common(mutex, 0); + if (ret != 0) + _thread_sigunblock(); + return (ret); } int -_pthread_mutex_unlock(pthread_mutex_t * mutex) +__pthread_mutex_unlock(pthread_mutex_t * mutex) { return (mutex_unlock_common(mutex, /* add reference */ 0)); } +/* + * Libc internal + */ +int +_pthread_mutex_unlock(pthread_mutex_t * mutex) +{ + int error; + if ((error = mutex_unlock_common(mutex, /* add reference */ 0)) == 0) + _thread_sigunblock(); + return (error); +} + int _mutex_cv_unlock(pthread_mutex_t * mutex) { -- cgit v1.1