diff options
author | mtm <mtm@FreeBSD.org> | 2003-05-29 20:58:31 +0000 |
---|---|---|
committer | mtm <mtm@FreeBSD.org> | 2003-05-29 20:58:31 +0000 |
commit | 8c86272540080808f88917a48792b24b06cacedb (patch) | |
tree | 449facfaec28d3009404d0858597461a3872a0b0 /lib/libthr | |
parent | 238a1fc561ef47ef23d773be262045b7cdeb2be1 (diff) | |
download | FreeBSD-src-8c86272540080808f88917a48792b24b06cacedb.zip FreeBSD-src-8c86272540080808f88917a48792b24b06cacedb.tar.gz |
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
Diffstat (limited to 'lib/libthr')
-rw-r--r-- | lib/libthr/thread/thr_mutex.c | 44 |
1 files changed, 19 insertions, 25 deletions
diff --git a/lib/libthr/thread/thr_mutex.c b/lib/libthr/thread/thr_mutex.c index aa3a96f..5267a32 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); |