From ff9af45a01e0312f2d252d06cdfefa08a2abcb37 Mon Sep 17 00:00:00 2001 From: Mike Makonnen Date: Wed, 22 Sep 2004 16:53:23 +0000 Subject: [PATCH] The SUSv3 function say that the affected functions MAY FAIL, if the specified mutex is invalid. In spec parlance 'MAY FAIL' means it's up to the implementor. So, remove the check for NULL pointers for two reasons: 1. A mutex may be invalid without necessarily being NULL. 2. If the pointer to the mutex is NULL core-dumping in the vicinity of the problem is much much much better than failing in some other part of the code (especially when the application doesn't check the return value of the function that you oh so helpfully set to EINVAL). --- lib/libthr/thread/thr_mutex.c | 33 ++++++--------------------------- 1 file changed, 6 insertions(+), 27 deletions(-) diff --git a/lib/libthr/thread/thr_mutex.c b/lib/libthr/thread/thr_mutex.c index 2771a65d04d5..ae6e406164a3 100644 --- a/lib/libthr/thread/thr_mutex.c +++ b/lib/libthr/thread/thr_mutex.c @@ -105,9 +105,7 @@ _mutex_reinit(pthread_mutex_t * mutex) { int ret = 0; - if (mutex == NULL) - ret = EINVAL; - else if (*mutex == PTHREAD_MUTEX_INITIALIZER) + if (*mutex == PTHREAD_MUTEX_INITIALIZER) ret = _pthread_mutex_init(mutex, NULL); else { /* @@ -169,9 +167,6 @@ _pthread_mutex_init(pthread_mutex_t * mutex, int _pthread_mutex_destroy(pthread_mutex_t * mutex) { - if (mutex == NULL) - return (EINVAL); - /* * If this mutex was statically initialized, don't bother * initializing it in order to destroy it immediately. @@ -271,14 +266,11 @@ __pthread_mutex_trylock(pthread_mutex_t *mutex) { int ret = 0; - if (mutex == NULL) - ret = EINVAL; - /* * If the mutex is statically initialized, perform the dynamic * initialization: */ - else if ((*mutex != PTHREAD_MUTEX_INITIALIZER) || + if ((*mutex != PTHREAD_MUTEX_INITIALIZER) || (ret = mutex_init(mutex, 0)) == 0) ret = mutex_lock_common(mutex, 1, NULL); @@ -295,14 +287,11 @@ _pthread_mutex_trylock(pthread_mutex_t *mutex) _thread_sigblock(); - if (mutex == NULL) - ret = EINVAL; - /* * If the mutex is statically initialized, perform the dynamic * initialization marking the mutex private (delete safe): */ - else if ((*mutex != PTHREAD_MUTEX_INITIALIZER) || + if ((*mutex != PTHREAD_MUTEX_INITIALIZER) || (ret = mutex_init(mutex, 1)) == 0) ret = mutex_lock_common(mutex, 1, NULL); @@ -518,14 +507,11 @@ __pthread_mutex_lock(pthread_mutex_t *mutex) if (_thread_initial == NULL) _thread_init(); - if (mutex == NULL) - ret = EINVAL; - /* * If the mutex is statically initialized, perform the dynamic * initialization: */ - else if ((*mutex != PTHREAD_MUTEX_INITIALIZER) || + if ((*mutex != PTHREAD_MUTEX_INITIALIZER) || ((ret = mutex_init(mutex, 0)) == 0)) ret = mutex_lock_common(mutex, 0, NULL); @@ -545,14 +531,11 @@ _pthread_mutex_lock(pthread_mutex_t *mutex) _thread_sigblock(); - if (mutex == NULL) - ret = EINVAL; - /* * If the mutex is statically initialized, perform the dynamic * initialization marking it private (delete safe): */ - else if ((*mutex != PTHREAD_MUTEX_INITIALIZER) || + if ((*mutex != PTHREAD_MUTEX_INITIALIZER) || ((ret = mutex_init(mutex, 1)) == 0)) ret = mutex_lock_common(mutex, 0, NULL); @@ -574,9 +557,7 @@ _pthread_mutex_timedlock(pthread_mutex_t *mutex, const struct timespec *abstime) /* * Initialize it if it's a valid statically inited mutex. */ - if (mutex == NULL) - error = EINVAL; - else if ((*mutex != PTHREAD_MUTEX_INITIALIZER) || + if ((*mutex != PTHREAD_MUTEX_INITIALIZER) || ((error = mutex_init(mutex, 0)) == 0)) error = mutex_lock_common(mutex, 0, abstime); @@ -660,8 +641,6 @@ mutex_unlock_common(pthread_mutex_t * mutex, int add_reference) /* * Error checking. */ - if (*mutex == NULL) - return (EINVAL); if ((*mutex)->m_owner != curthread) return (EPERM); PTHREAD_ASSERT(((*mutex)->m_protocol >= PTHREAD_PRIO_NONE &&