diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2005-11-16 01:01:37 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2005-11-16 01:01:37 (GMT) |
commit | 671187fd2b53c916f444e849a2fd57bac06552f8 (patch) | |
tree | a1a723b81dda3c967a597a9d7477806e4fcfa706 /src/H5TS.c | |
parent | e70783203ab603627147c565d0fe08ddbe103981 (diff) | |
download | hdf5-671187fd2b53c916f444e849a2fd57bac06552f8.zip hdf5-671187fd2b53c916f444e849a2fd57bac06552f8.tar.gz hdf5-671187fd2b53c916f444e849a2fd57bac06552f8.tar.bz2 |
[svn-r11733] Purpose:
Code cleanup
Description:
Added some comments about the thread-specific memory for the error and
function stacks.
Changed H5close() to not use the function stack (since it causes it to
be re-enabled after shutting it down)
Changed thread-safe semaphore code to not use dynamicly allocated memory.
Platforms tested:
FreeBSD 4.11 (sleipnir)
Linux 2.4
Too minor to require h5committest
Diffstat (limited to 'src/H5TS.c')
-rw-r--r-- | src/H5TS.c | 36 |
1 files changed, 11 insertions, 25 deletions
@@ -95,8 +95,9 @@ H5TS_first_thread_init(void) { H5_g.H5_libinit_g = FALSE; - /* set the two pthread_t objects to ``null'' */ - H5_g.init_lock.owner_thread = NULL; + /* 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); @@ -148,36 +149,22 @@ H5TS_mutex_lock(H5TS_mutex_t *mutex) if (ret_value) return ret_value; - if (mutex->owner_thread && pthread_equal(pthread_self(), *mutex->owner_thread)) { + if (mutex->owner_valid && pthread_equal(pthread_self(), mutex->owner_thread)) { /* already owned by self - increment count */ mutex->lock_count++; - } else if (!mutex->owner_thread) { + } else if (!mutex->owner_valid) { /* no one else has locked it - set owner and grab lock */ - mutex->owner_thread = H5MM_malloc(sizeof(pthread_t)); - - if (!mutex->owner_thread) { - H5E_push_stack(NULL, "H5TS_mutex_lock", __FILE__, __LINE__, - H5E_ERR_CLS_g, H5E_RESOURCE, H5E_NOSPACE, "memory allocation failed"); - return FAIL; - } - - *mutex->owner_thread = pthread_self(); + 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_thread) { - mutex->owner_thread = H5MM_malloc(sizeof(pthread_t)); - - if (!mutex->owner_thread) { - H5E_push_stack(NULL, "H5TS_mutex_lock", - __FILE__, __LINE__, H5E_ERR_CLS_g, H5E_RESOURCE, H5E_NOSPACE, "memory allocation failed"); - return FAIL; - } - - *mutex->owner_thread = pthread_self(); + if (!mutex->owner_valid) { + mutex->owner_thread = pthread_self(); + mutex->owner_valid = TRUE; mutex->lock_count = 1; break; } @@ -226,8 +213,7 @@ H5TS_mutex_unlock(H5TS_mutex_t *mutex) mutex->lock_count--; if (mutex->lock_count == 0) { - H5MM_xfree(mutex->owner_thread); - mutex->owner_thread = NULL; + mutex->owner_valid = FALSE; ret_value = pthread_cond_signal(&mutex->cond_var); if (ret_value) { |