From 1b2a19ce0e59a7ed116975bc4c27d7f939c6da8c Mon Sep 17 00:00:00 2001 From: Mike Makonnen Date: Thu, 29 May 2003 20:58:31 +0000 Subject: [PATCH] Make the mutex static initializers look more like the one for condition variables. Cosmetic. Explicitly compare against PTHREAD_MUTEX_INITIALIZER. We shouldn't encourage calls to the mutex functions with null pointers to mutexes. Approved by: re/jhb --- lib/libthr/thread/thr_mutex.c | 44 +++++++++++++++-------------------- 1 file changed, 19 insertions(+), 25 deletions(-) diff --git a/lib/libthr/thread/thr_mutex.c b/lib/libthr/thread/thr_mutex.c index aa3a96fe62b2..5267a32b83d0 100644 --- a/lib/libthr/thread/thr_mutex.c +++ b/lib/libthr/thread/thr_mutex.c @@ -101,7 +101,7 @@ _mutex_reinit(pthread_mutex_t * mutex) if (mutex == NULL) ret = EINVAL; - else if (*mutex == NULL) + else if (*mutex == PTHREAD_MUTEX_INITIALIZER) ret = _pthread_mutex_init(mutex, NULL); else { /* @@ -269,35 +269,25 @@ _pthread_mutex_destroy(pthread_mutex_t * mutex) static int init_static(pthread_mutex_t *mutex) { - int ret; - _SPINLOCK(&static_init_lock); - - if (*mutex == NULL) - ret = _pthread_mutex_init(mutex, NULL); - else - ret = 0; - + if (*mutex == PTHREAD_MUTEX_INITIALIZER) { + _SPINUNLOCK(&static_init_lock); + return(_pthread_mutex_init(mutex, NULL)); + } _SPINUNLOCK(&static_init_lock); - - return (ret); + return (0); } static int init_static_private(pthread_mutex_t *mutex) { - int ret; - _SPINLOCK(&static_init_lock); - - if (*mutex == NULL) - ret = _pthread_mutex_init(mutex, &static_mattr); - else - ret = 0; - + if (*mutex == PTHREAD_MUTEX_INITIALIZER) { + _SPINUNLOCK(&static_init_lock); + return (_pthread_mutex_init(mutex, &static_mattr)); + } _SPINUNLOCK(&static_init_lock); - - return (ret); + return (0); } int @@ -312,7 +302,8 @@ __pthread_mutex_trylock(pthread_mutex_t *mutex) * If the mutex is statically initialized, perform the dynamic * initialization: */ - else if ((*mutex != NULL) || (ret = init_static(mutex)) == 0) + else if ((*mutex != PTHREAD_MUTEX_INITIALIZER) || + (ret = init_static(mutex)) == 0) ret = mutex_lock_common(mutex, 1); return (ret); @@ -330,7 +321,8 @@ _pthread_mutex_trylock(pthread_mutex_t *mutex) * If the mutex is statically initialized, perform the dynamic * initialization marking the mutex private (delete safe): */ - else if ((*mutex != NULL) || (ret = init_static_private(mutex)) == 0) + else if ((*mutex != PTHREAD_MUTEX_INITIALIZER) || + (ret = init_static_private(mutex)) == 0) ret = mutex_lock_common(mutex, 1); return (ret); @@ -514,7 +506,8 @@ __pthread_mutex_lock(pthread_mutex_t *mutex) * If the mutex is statically initialized, perform the dynamic * initialization: */ - else if ((*mutex != NULL) || ((ret = init_static(mutex)) == 0)) + else if ((*mutex != PTHREAD_MUTEX_INITIALIZER) || + ((ret = init_static(mutex)) == 0)) ret = mutex_lock_common(mutex, 0); return (ret); @@ -535,7 +528,8 @@ _pthread_mutex_lock(pthread_mutex_t *mutex) * If the mutex is statically initialized, perform the dynamic * initialization marking it private (delete safe): */ - else if ((*mutex != NULL) || ((ret = init_static_private(mutex)) == 0)) + else if ((*mutex != PTHREAD_MUTEX_INITIALIZER) || + ((ret = init_static_private(mutex)) == 0)) ret = mutex_lock_common(mutex, 0); return (ret);