From 170d8032b2fd55450e4533357f4de118b619a8e8 Mon Sep 17 00:00:00 2001 From: rpj Date: Fri, 18 Aug 2000 14:17:28 +0000 Subject: 2000-08-18 Ross Johnson * mutex.c (pthread_mutex_destroy): Check that the mutex isn't held; invalidate the mutex as early as possible to avoid contention; not perfect - FIXME! * rwlock.c (pthread_rwlock_init): Remove redundant assignment to "rw". (pthread_rwlock_destroy): Invalidate the rwlock before freeing up any of it's resources - to avoid contention. * private.c (ptw32_tkAssocCreate): Change assoc->lock to use a dynamically initialised mutex - only consumes a W32 mutex or critical section when first used, not before. * mutex.c (pthread_mutex_init): Remove redundant assignment to "mx". (pthread_mutexattr_destroy): Set attribute to NULL before freeing it's memory - to avoid contention. --- rwlock.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'rwlock.c') diff --git a/rwlock.c b/rwlock.c index d02461c..4353847 100644 --- a/rwlock.c +++ b/rwlock.c @@ -94,8 +94,6 @@ pthread_rwlock_init(pthread_rwlock_t *rwlock, const pthread_rwlockattr_t *attr) return EINVAL; } - rw = *rwlock; - rw = (pthread_rwlock_t) calloc(1, sizeof(*rw)); if (rw == NULL) @@ -182,14 +180,19 @@ pthread_rwlock_destroy(pthread_rwlock_t *rwlock) } else { + /* + * Need to NULL this before we start freeing up + * and destroying it's components. + */ + *rwlock = NULL; rw->rw_magic = 0; + (void) pthread_mutex_unlock(&(rw->rw_lock)); + (void) pthread_cond_destroy(&(rw->rw_condreaders)); (void) pthread_cond_destroy(&(rw->rw_condwriters)); (void) pthread_mutex_destroy(&(rw->rw_lock)); - free(rw); - *rwlock = NULL; } } else -- cgit v1.2.3