diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2008-06-16 22:17:29 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2008-06-16 22:17:29 (GMT) |
commit | db2c4c497abab139485dbf6797e56b1340e4577d (patch) | |
tree | f7dfb321a3643658ed24aaf776ec4c1e48bc76a3 /src/H5TS.c | |
parent | 55af47c47c3c0c7bc17266968f5e0e782189e819 (diff) | |
download | hdf5-db2c4c497abab139485dbf6797e56b1340e4577d.zip hdf5-db2c4c497abab139485dbf6797e56b1340e4577d.tar.gz hdf5-db2c4c497abab139485dbf6797e56b1340e4577d.tar.bz2 |
[svn-r15221] Description:
Bring changes from trunk from the time the branch was created (r14280)
up to the 1.8.0 release (r14525) back into the metadata journaling branch.
Tested on:
FreeBSD/32 6.2 (duty) in debug mode
FreeBSD/64 6.2 (liberty) w/C++ & FORTRAN, in debug mode
Linux/32 2.6 (kagiso) w/PGI compilers, w/C++ & FORTRAN, w/threadsafe,
in debug mode
Linux/64-amd64 2.6 (smirom) w/default API=1.6.x, w/C++ & FORTRAN,
in production mode
Linux/64-ia64 2.6 (cobalt) w/Intel compilers, w/C++ & FORTRAN,
in production mode
Solaris/32 2.10 (linew) w/deprecated symbols disabled, w/C++ & FORTRAN,
w/szip filter, in production mode
Linux/64-ia64 2.4 (tg-login3) w/parallel, w/FORTRAN, in production mode
Diffstat (limited to 'src/H5TS.c')
-rw-r--r-- | src/H5TS.c | 51 |
1 files changed, 19 insertions, 32 deletions
@@ -96,10 +96,6 @@ H5TS_first_thread_init(void) { H5_g.H5_libinit_g = FALSE; - /* set the owner objects to initial values */ - H5_g.init_lock.owner_thread = pthread_self(); - H5_g.init_lock.owner_valid = FALSE; - /* initialize global API mutex lock */ pthread_mutex_init(&H5_g.init_lock.atomic_lock, NULL); pthread_cond_init(&H5_g.init_lock.cond_var, NULL); @@ -150,26 +146,17 @@ H5TS_mutex_lock(H5TS_mutex_t *mutex) if (ret_value) return ret_value; - if (mutex->owner_valid && pthread_equal(pthread_self(), mutex->owner_thread)) { + if(mutex->lock_count && pthread_equal(pthread_self(), mutex->owner_thread)) { /* already owned by self - increment count */ mutex->lock_count++; - } else if (!mutex->owner_valid) { - /* no one else has locked it - set owner and grab lock */ + } else { + /* if owned by other thread, wait for condition signal */ + while(mutex->lock_count) + pthread_cond_wait(&mutex->cond_var, &mutex->atomic_lock); + + /* After we've received the signal, take ownership of the mutex */ mutex->owner_thread = pthread_self(); - mutex->owner_valid = TRUE; mutex->lock_count = 1; - } else { - /* if already locked by someone else */ - for (;;) { - pthread_cond_wait(&mutex->cond_var, &mutex->atomic_lock); - - if (!mutex->owner_valid) { - mutex->owner_thread = pthread_self(); - mutex->owner_valid = TRUE; - mutex->lock_count = 1; - break; - } - } } return pthread_mutex_unlock(&mutex->atomic_lock); @@ -204,26 +191,26 @@ H5TS_mutex_lock(H5TS_mutex_t *mutex) herr_t H5TS_mutex_unlock(H5TS_mutex_t *mutex) { - herr_t ret_value; + herr_t ret_value; /* Return value */ ret_value = pthread_mutex_lock(&mutex->atomic_lock); - if (ret_value) - return ret_value; + if(ret_value) + return ret_value; mutex->lock_count--; - if (mutex->lock_count == 0) { - mutex->owner_valid = FALSE; - ret_value = pthread_cond_signal(&mutex->cond_var); + ret_value = pthread_mutex_unlock(&mutex->atomic_lock); - if (ret_value) { - pthread_mutex_unlock(&mutex->atomic_lock); - return ret_value; - } - } + if(mutex->lock_count == 0) { + int err; - return pthread_mutex_unlock(&mutex->atomic_lock); + err = pthread_cond_signal(&mutex->cond_var); + if(err != 0) + ret_value = err; + } /* end if */ + + return ret_value; } /*-------------------------------------------------------------------------- |