diff options
author | rpj <rpj> | 1999-09-16 13:21:21 +0000 |
---|---|---|
committer | rpj <rpj> | 1999-09-16 13:21:21 +0000 |
commit | f20ec5ec3497e7d1a8301d3c7ec6652dab1c3247 (patch) | |
tree | f7e2090fa5da2196b5bd4b575f1520b18051a0d0 /mutex.c | |
parent | 70597d7147b86dd972a803e185f05c0e7de80586 (diff) |
Thu Sep 16 1999 Ross Johnson <rpj@swan.canberra.edu.au>
* rwlock.c (pthread_rwlock_destroy): Add serialisation.
(_rwlock_check_need_init): Check for detroyed rwlock.
* rwlock.c: Check return codes from _rwlock_check_need_init();
modify comments; serialise access to rwlock objects during
operations; rename rw_mutex to rw_lock.
* implement.h: Rename rw_mutex to rw_lock.
* mutex.c (pthread_mutex_destroy): Add serialisation.
(_mutex_check_need_init): Check for detroyed mutex.
* condvar.c (pthread_cond_destroy): Add serialisation.
(_cond_check_need_init): Check for detroyed condvar.
* mutex.c: Modify comments.
* condvar.c: Modify comments.
Diffstat (limited to 'mutex.c')
-rw-r--r-- | mutex.c | 44 |
1 files changed, 38 insertions, 6 deletions
@@ -69,6 +69,15 @@ _mutex_check_need_init(pthread_mutex_t *mutex) { result = pthread_mutex_init(mutex, NULL); } + else if (*mutex == NULL) + { + /* + * The mutex has been destroyed while we were waiting to + * initialise it, so the operation that caused the + * auto-initialisation should fail. + */ + result = EINVAL; + } LeaveCriticalSection(&_pthread_mutex_test_init_lock); @@ -177,13 +186,13 @@ pthread_mutex_destroy(pthread_mutex_t *mutex) return EINVAL; } - mx = *mutex; - /* * Check to see if we have something to delete. */ - if (mx != (pthread_mutex_t) _PTHREAD_OBJECT_AUTO_INIT) + if (*mutex != (pthread_mutex_t) _PTHREAD_OBJECT_AUTO_INIT) { + mx = *mutex; + if (mx->mutex == 0) { DeleteCriticalSection(&mx->cs); @@ -203,10 +212,33 @@ pthread_mutex_destroy(pthread_mutex_t *mutex) else { /* - * This is all we need to do to destroy a statically - * initialised mutex that has not yet been used (initialised). + * See notes in _mutex_check_need_init() above also. */ - *mutex = NULL; + EnterCriticalSection(&_pthread_mutex_test_init_lock); + + /* + * Check again. + */ + if (*mutex == (pthread_mutex_t) _PTHREAD_OBJECT_AUTO_INIT) + { + /* + * This is all we need to do to destroy a statically + * initialised mutex that has not yet been used (initialised). + * If we get to here, another thread + * waiting to initialise this mutex will get an EINVAL. + */ + *mutex = NULL; + } + else + { + /* + * The mutex has been initialised while we were waiting + * so assume it's in use. + */ + result = EBUSY; + } + + LeaveCriticalSection(&_pthread_mutex_test_init_lock); } return(result); |