From 932fa5eba25d02e38e2712afcd3a6461324802ff Mon Sep 17 00:00:00 2001 From: Quincey Koziol Date: Wed, 27 Mar 2024 18:42:03 -0500 Subject: [PATCH] Delete old "exclusive" lock ahd switch to a recursive mutex. Signed-off-by: Quincey Koziol --- src/CMakeLists.txt | 1 - src/H5FDsubfiling/H5FDioc_threads.c | 2 +- src/H5TS.c | 3 +- src/H5TSexlock.c | 334 ---------------------------- src/H5TSint.c | 59 +++-- src/H5TSkey.c | 6 +- src/H5TSmutex.c | 18 +- src/H5TSpkg.h | 21 +- src/H5TSprivate.h | 4 +- src/H5TSthread.c | 2 +- src/Makefile.am | 2 +- 11 files changed, 62 insertions(+), 390 deletions(-) delete mode 100644 src/H5TSexlock.c diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8c900adf992..9b3729eda33 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -643,7 +643,6 @@ set (H5TS_SOURCES ${HDF5_SRC_DIR}/H5TSbarrier.c ${HDF5_SRC_DIR}/H5TSc11.c ${HDF5_SRC_DIR}/H5TScond.c - ${HDF5_SRC_DIR}/H5TSexlock.c ${HDF5_SRC_DIR}/H5TSint.c ${HDF5_SRC_DIR}/H5TSkey.c ${HDF5_SRC_DIR}/H5TSmutex.c diff --git a/src/H5FDsubfiling/H5FDioc_threads.c b/src/H5FDsubfiling/H5FDioc_threads.c index 1c468e2d771..23fa0ab6740 100644 --- a/src/H5FDsubfiling/H5FDioc_threads.c +++ b/src/H5FDsubfiling/H5FDioc_threads.c @@ -1400,7 +1400,7 @@ ioc_io_queue_dispatch_eligible_entries(ioc_data_t *ioc_data, bool try_lock) bool acquired; herr_t ret; - ret = H5TS_mutex_try_lock(&ioc_data->io_queue.q_mutex, &acquired); + ret = H5TS_mutex_trylock(&ioc_data->io_queue.q_mutex, &acquired); assert(SUCCEED == ret); if (!acquired) return; diff --git a/src/H5TS.c b/src/H5TS.c index 2ef9d9b91df..cc0acea0b68 100644 --- a/src/H5TS.c +++ b/src/H5TS.c @@ -83,7 +83,7 @@ H5TSmutex_acquire(unsigned lock_count, bool *acquired) FUNC_ENTER_API_NAMECHECK_ONLY - /* Acquire the "attempt" lock */ + /* Acquire the "API" lock */ if (H5_UNLIKELY(H5TS__mutex_acquire(lock_count, acquired) < 0)) HGOTO_DONE(FAIL); @@ -131,6 +131,7 @@ H5TSmutex_release(unsigned *lock_count) FUNC_ENTER_API_NAMECHECK_ONLY + /* Release the "API" lock */ *lock_count = 0; if (H5_UNLIKELY(H5TS__mutex_release(lock_count) < 0)) ret_value = FAIL; diff --git a/src/H5TSexlock.c b/src/H5TSexlock.c deleted file mode 100644 index a96612440af..00000000000 --- a/src/H5TSexlock.c +++ /dev/null @@ -1,334 +0,0 @@ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - * Copyright by The HDF Group. * - * All rights reserved. * - * * - * This file is part of HDF5. The full HDF5 copyright notice, including * - * terms governing use, modification, and redistribution, is contained in * - * the COPYING file, which can be found at the root of the source code * - * distribution tree, or in https://www.hdfgroup.org/licenses. * - * If you do not have access to either file, you may request a copy from * - * help@hdfgroup.org. * - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - -/* - * Purpose: This file contains support for recursive exclusive locks, equivalent to - * the pthread 'pthread_mutex_t' type and capabilities, except that - * threads that hold the lock are allowed to acquire access again - * (and must match each lock with an unlock operation). - * - * Note: Because this threadsafety framework operates outside the library, - * it does not use the error stack (although it does use error macros - * that don't push errors on a stack) and only uses the "namecheck only" - * FUNC_ENTER_* / FUNC_LEAVE_* macros. - */ - -/****************/ -/* Module Setup */ -/****************/ - -#include "H5TSmodule.h" /* This source code file is part of the H5TS module */ - -/***********/ -/* Headers */ -/***********/ -#include "H5private.h" /* Generic Functions */ -#include "H5Eprivate.h" /* Error handling */ -#include "H5TSpkg.h" /* Threadsafety */ - -#ifdef H5_HAVE_THREADSAFE - -/****************/ -/* Local Macros */ -/****************/ - -/******************/ -/* Local Typedefs */ -/******************/ - -/********************/ -/* Local Prototypes */ -/********************/ - -/*********************/ -/* Package Variables */ -/*********************/ - -/*****************************/ -/* Library Private Variables */ -/*****************************/ - -/*******************/ -/* Local Variables */ -/*******************/ - -/*-------------------------------------------------------------------------- - * Function: H5TS__ex_lock_init - * - * Purpose: Initialize the supplied instance of H5TS_ex_lock_t. - * - * Return: Non-negative on success / Negative on failure - * - *-------------------------------------------------------------------------- - */ -herr_t -H5TS__ex_lock_init(H5TS_ex_lock_t *lock) -{ - herr_t ret_value = SUCCEED; - - FUNC_ENTER_PACKAGE_NAMECHECK_ONLY - - if (H5_UNLIKELY(NULL == lock)) - HGOTO_DONE(FAIL); - - /* Initialize the lock */ - memset(lock, 0, sizeof(*lock)); - if (H5_UNLIKELY(H5TS_mutex_init(&lock->mutex, H5TS_MUTEX_TYPE_PLAIN) < 0)) - HGOTO_DONE(FAIL); - if (H5_UNLIKELY(H5TS_cond_init(&lock->cond_var) < 0)) - HGOTO_DONE(FAIL); - -done: - FUNC_LEAVE_NOAPI_NAMECHECK_ONLY(ret_value) -} /* end H5TS__ex_lock_init() */ - -/*-------------------------------------------------------------------------- - * Function: H5TS__ex_lock - * - * Purpose: Acquire a lock on the associated recursive exclusive lock. - * - * Return: Non-negative on success / Negative on failure - * - *-------------------------------------------------------------------------- - */ -herr_t -H5TS__ex_lock(H5TS_ex_lock_t *lock) -{ - H5TS_thread_t my_thread_id = H5TS_thread_self(); - bool have_mutex = false; - herr_t ret_value = SUCCEED; - - FUNC_ENTER_NOAPI_NAMECHECK_ONLY - - /* Acquire the mutex for the lock */ - if (H5_UNLIKELY(H5TS_mutex_lock(&lock->mutex) < 0)) - HGOTO_DONE(FAIL); - have_mutex = true; - - /* Check if the lock is already owned */ - if (lock->lock_count) { - /* Does this thread already own the lock? */ - if (H5TS_thread_equal(my_thread_id, lock->owner_thread)) { - /* Already owned by self - increment count */ - lock->lock_count++; - - /* Leave now, we already own this lock */ - HGOTO_DONE(SUCCEED); - } - else { - /* Wait until the mutex is released by current owner thread */ - do { - if (H5_UNLIKELY(H5TS_cond_wait(&lock->cond_var, &lock->mutex) < 0)) - HGOTO_DONE(FAIL); - } while (lock->lock_count); - } - } - - /* Take ownership of the lock */ - lock->owner_thread = my_thread_id; - lock->lock_count = 1; - -done: - if (H5_LIKELY(have_mutex)) - if (H5_UNLIKELY(H5TS_mutex_unlock(&lock->mutex) < 0)) - ret_value = FAIL; - - FUNC_LEAVE_NOAPI_NAMECHECK_ONLY(ret_value) -} /* end H5TS__ex_lock() */ - -/*-------------------------------------------------------------------------- - * Function: H5TS__ex_acquire - * - * Purpose: Attempts to acquire an exclusive lock, without blocking - * - * Note: On success, the 'acquired' flag indicates if lock was acquired. - * - * Return: Non-negative on success / Negative on failure - * - *-------------------------------------------------------------------------- - */ -herr_t -H5TS__ex_acquire(H5TS_ex_lock_t *lock, unsigned lock_count, bool *acquired) -{ - bool have_mutex = false; - H5TS_thread_t my_thread_id = H5TS_thread_self(); - herr_t ret_value = SUCCEED; - - FUNC_ENTER_PACKAGE_NAMECHECK_ONLY - - /* Attempt to acquire the lock's mutex */ - if (H5_UNLIKELY(H5TS_mutex_lock(&lock->mutex) < 0)) - HGOTO_DONE(FAIL); - have_mutex = true; - - /* Check if locked already */ - if (lock->lock_count) { - /* Check for this thread already owning the lock */ - if (H5TS_thread_equal(my_thread_id, lock->owner_thread)) { - /* Already owned by self - increment count */ - lock->lock_count += lock_count; - *acquired = true; - } - else - *acquired = false; - } - else { - /* Take ownership of the lock */ - lock->owner_thread = my_thread_id; - lock->lock_count = lock_count; - *acquired = true; - } - -done: - /* Release the mutex, if acquired */ - if (H5_LIKELY(have_mutex)) - if (H5_UNLIKELY(H5TS_mutex_unlock(&lock->mutex) < 0)) - ret_value = FAIL; - - FUNC_LEAVE_NOAPI_NAMECHECK_ONLY(ret_value) -} /* end H5TS__ex_acquire() */ - -/*-------------------------------------------------------------------------- - * Function: H5TS__ex_release - * - * Purpose: Release an exclusive lock. Passes back the previous lock count - * to the caller in a parameter. - * - * Return: Non-negative on success / Negative on failure - * - *-------------------------------------------------------------------------- - */ -herr_t -H5TS__ex_release(H5TS_ex_lock_t *lock, unsigned int *lock_count) -{ - bool have_mutex = false; - herr_t ret_value = SUCCEED; - - FUNC_ENTER_NOAPI_NAMECHECK_ONLY - - /* Attempt to acquire the lock's mutex */ - if (H5_UNLIKELY(H5TS_mutex_lock(&lock->mutex) < 0)) - HGOTO_DONE(FAIL); - have_mutex = true; - - /* Reset the lock count for this thread */ - *lock_count = lock->lock_count; - lock->lock_count = 0; - - /* Signal the condition variable, to wake any thread waiting on the lock */ - if (H5_UNLIKELY(H5TS_cond_signal(&lock->cond_var) < 0)) - HGOTO_DONE(FAIL); - -done: - if (H5_LIKELY(have_mutex)) - if (H5_UNLIKELY(H5TS_mutex_unlock(&lock->mutex) < 0)) - ret_value = FAIL; - - FUNC_LEAVE_NOAPI_NAMECHECK_ONLY(ret_value) -} /* H5TS__ex_release */ - -/*-------------------------------------------------------------------------- - * Function: H5TS__ex_unlock - * - * Purpose: Decrements the lock counter, releasing the lock when the counter - * reaches 0. - * - * Return: Non-negative on success / Negative on failure - * - *-------------------------------------------------------------------------- - */ -herr_t -H5TS__ex_unlock(H5TS_ex_lock_t *lock) -{ - bool have_mutex = false; - herr_t ret_value = SUCCEED; - - FUNC_ENTER_NOAPI_NAMECHECK_ONLY - - /* Acquire the mutex for the lock */ - if (H5_UNLIKELY(H5TS_mutex_lock(&lock->mutex) < 0)) - HGOTO_DONE(FAIL); - have_mutex = true; - - /* Decrement the lock count for this thread */ - lock->lock_count--; - - if (0 == lock->lock_count) { - /* If the lock count drops to zero, signal the condition variable to - * wake any thread waiting on the lock. - */ - if (H5_UNLIKELY(H5TS_cond_signal(&lock->cond_var) < 0)) - HGOTO_DONE(FAIL); - } - -done: - if (H5_LIKELY(have_mutex)) - if (H5_UNLIKELY(H5TS_mutex_unlock(&lock->mutex) < 0)) - ret_value = FAIL; - - FUNC_LEAVE_NOAPI_NAMECHECK_ONLY(ret_value) -} /* H5TS__ex_unlock */ - -/*-------------------------------------------------------------------------- - * Function: H5TS__ex_lock_destroy - * - * Purpose: Destroy an exlusive lock. All mutex, condition variables, - * etc. are destroyed. However, the instance of H5TS_ex_lock_t - * is not freed. - * - * Return: Non-negative on success / Negative on failure - * - *-------------------------------------------------------------------------- - */ -herr_t -H5TS__ex_lock_destroy(H5TS_ex_lock_t *lock) -{ - bool have_mutex = false; - herr_t ret_value = SUCCEED; - - FUNC_ENTER_PACKAGE_NAMECHECK_ONLY - - if (H5_UNLIKELY(NULL == lock)) - HGOTO_DONE(FAIL); - - /* Acquire the mutex for the lock */ - if (H5_UNLIKELY(H5TS_mutex_lock(&lock->mutex) < 0)) - HGOTO_DONE(FAIL); - have_mutex = true; - - /* Fail if this thread owns the lock */ - if (lock->lock_count && H5TS_thread_equal(H5TS_thread_self(), lock->owner_thread)) - HGOTO_DONE(FAIL); - - /* Release the mutex for the lock */ - if (H5_UNLIKELY(H5TS_mutex_unlock(&lock->mutex) < 0)) - HGOTO_DONE(FAIL); - have_mutex = false; - - /* Call the appropriate destroy routines. We are committed - * to the destroy at this point, so call them all, even if one fails - * along the way. - */ - if (H5_UNLIKELY(H5TS_mutex_destroy(&lock->mutex) < 0)) - ret_value = FAIL; - if (H5_UNLIKELY(H5TS_cond_destroy(&lock->cond_var) < 0)) - ret_value = FAIL; - -done: - if (H5_UNLIKELY(have_mutex)) - if (H5_UNLIKELY(H5TS_mutex_unlock(&lock->mutex) < 0)) - ret_value = FAIL; - - FUNC_LEAVE_NOAPI_NAMECHECK_ONLY(ret_value) -} /* end H5TS__ex_lock_destroy() */ - -#endif /* H5_HAVE_THREADSAFE */ diff --git a/src/H5TSint.c b/src/H5TSint.c index 95bbcbcff96..92723741871 100644 --- a/src/H5TSint.c +++ b/src/H5TSint.c @@ -116,9 +116,10 @@ H5TS__init(void) FUNC_ENTER_PACKAGE_NAMECHECK_ONLY - /* Initialize the global API lock */ - if (H5_UNLIKELY(H5TS__ex_lock_init(&H5TS_api_info_p.api_lock) < 0)) + /* Initialize the global API lock info */ + if (H5_UNLIKELY(H5TS_mutex_init(&H5TS_api_info_p.api_mutex, H5TS_MUTEX_TYPE_RECURSIVE) < 0)) HGOTO_DONE(FAIL); + H5TS_api_info_p.lock_count = 0; H5TS_atomic_init_uint(&H5TS_api_info_p.attempt_lock_count, 0); /* Initialize per-thread library info */ @@ -146,13 +147,11 @@ H5TS_term_package(void) { FUNC_ENTER_NOAPI_NOINIT_NOERR - /* Destroy global API lock */ - H5TS__ex_lock_destroy(&H5TS_api_info_p.api_lock); - - /* Destroy the "lock acquisition attempt" atomic */ + /* Reset global API lock info */ + H5TS_mutex_destroy(&H5TS_api_info_p.api_mutex); H5TS_atomic_destroy_uint(&H5TS_api_info_p.attempt_lock_count); - /* Clean up per-process thread local storage */ + /* Clean up per-thread library info */ H5TS__tinfo_term(); FUNC_LEAVE_NOAPI_VOID @@ -166,23 +165,29 @@ H5TS_term_package(void) * Note: On success, the 'acquired' flag indicates if the HDF5 library * global lock was acquired. * - * Note: The Windows threads code is very likely bogus. - * * Return: Non-negative on success / Negative on failure * *-------------------------------------------------------------------------- */ herr_t -H5TS__mutex_acquire(unsigned int lock_count, bool *acquired) +H5TS__mutex_acquire(unsigned lock_count, bool *acquired) { herr_t ret_value = SUCCEED; FUNC_ENTER_PACKAGE_NAMECHECK_ONLY /* Attempt to acquire the lock */ - if (H5_UNLIKELY(H5TS__ex_acquire(&H5TS_api_info_p.api_lock, lock_count, acquired) < 0)) + if (H5_UNLIKELY(H5TS_mutex_trylock(&H5TS_api_info_p.api_mutex, acquired) < 0)) HGOTO_DONE(FAIL); + /* If acquired, increment the levels of recursion by 'lock_count' - 1 */ + if (*acquired) { + for(unsigned u = 0; u < (lock_count - 1); u++) + if (H5_UNLIKELY(H5TS_mutex_lock(&H5TS_api_info_p.api_mutex) < 0)) + HGOTO_DONE(FAIL); + H5TS_api_info_p.lock_count += lock_count; + } + done: FUNC_LEAVE_NOAPI_NAMECHECK_ONLY(ret_value) } /* end H5TS__mutex_acquire() */ @@ -217,10 +222,13 @@ H5TS_api_lock(void) /* Increment the attempt lock count */ H5TS_atomic_fetch_add_uint(&H5TS_api_info_p.attempt_lock_count, 1); - /* Acquire the library's exclusive API lock */ - if (H5_UNLIKELY(H5TS__ex_lock(&H5TS_api_info_p.api_lock) < 0)) + /* Acquire the library's API lock */ + if (H5_UNLIKELY(H5TS_mutex_lock(&H5TS_api_info_p.api_mutex) < 0)) HGOTO_DONE(FAIL); + /* Increment the lock count for this thread */ + H5TS_api_info_p.lock_count++; + done: FUNC_LEAVE_NOAPI_NAMECHECK_ONLY(ret_value) } /* end H5TS_api_lock() */ @@ -243,9 +251,16 @@ H5TS__mutex_release(unsigned *lock_count) FUNC_ENTER_NOAPI_NAMECHECK_ONLY - /* Release the library's exclusive API lock */ - if (H5_UNLIKELY(H5TS__ex_release(&H5TS_api_info_p.api_lock, lock_count) < 0)) - HGOTO_DONE(FAIL); + /* Return the current lock count */ + *lock_count = H5TS_api_info_p.lock_count; + + /* Reset recursive lock count */ + H5TS_api_info_p.lock_count = 0; + + /* Release the library's API lock 'lock_count' times */ + for(unsigned u = 0; u < *lock_count; u++) + if (H5_UNLIKELY(H5TS_mutex_unlock(&H5TS_api_info_p.api_mutex) < 0)) + HGOTO_DONE(FAIL); done: FUNC_LEAVE_NOAPI_NAMECHECK_ONLY(ret_value) @@ -254,8 +269,9 @@ H5TS__mutex_release(unsigned *lock_count) /*-------------------------------------------------------------------------- * Function: H5TS_api_unlock * - * Purpose: Decrements the global "API" lock counter for accessing the - * HDF5 library, releasing the lock when the counter reaches 0. + * Purpose: Decrements the global "API" lock for accessing the + * HDF5 library, releasing the lock when it's been unlocked as + * many times as it was locked. * * Return: Non-negative on success / Negative on failure * @@ -268,8 +284,11 @@ H5TS_api_unlock(void) FUNC_ENTER_NOAPI_NAMECHECK_ONLY - /* Release the library's exclusive API lock */ - if (H5_UNLIKELY(H5TS__ex_unlock(&H5TS_api_info_p.api_lock) < 0)) + /* Decrement the lock count for this thread */ + H5TS_api_info_p.lock_count--; + + /* Release the library's API lock */ + if (H5_UNLIKELY(H5TS_mutex_unlock(&H5TS_api_info_p.api_mutex) < 0)) HGOTO_DONE(FAIL); done: diff --git a/src/H5TSkey.c b/src/H5TSkey.c index 27449e26f64..2273ac2b9f5 100644 --- a/src/H5TSkey.c +++ b/src/H5TSkey.c @@ -98,7 +98,7 @@ H5TS_key_create(H5TS_key_t *key, H5TS_key_destructor_func_t dtor) *------------------------------------------------------------------------- */ herr_t -H5TS_key_set_value(H5TS_key_t key, const void *value) +H5TS_key_set_value(H5TS_key_t key, void *value) { herr_t ret_value = SUCCEED; @@ -198,7 +198,7 @@ H5TS_key_create(H5TS_key_t *key, H5TS_key_destructor_func_t dtor) *------------------------------------------------------------------------- */ herr_t -H5TS_key_set_value(H5TS_key_t key, const void *value) +H5TS_key_set_value(H5TS_key_t key, void *value) { herr_t ret_value = SUCCEED; @@ -302,7 +302,7 @@ H5TS_key_create(H5TS_key_t *key, H5TS_key_destructor_func_t dtor) *------------------------------------------------------------------------- */ herr_t -H5TS_key_set_value(H5TS_key_t key, const void *value) +H5TS_key_set_value(H5TS_key_t key, void *value) { herr_t ret_value = SUCCEED; diff --git a/src/H5TSmutex.c b/src/H5TSmutex.c index 6b29ee656e9..3a1bff2a1d7 100644 --- a/src/H5TSmutex.c +++ b/src/H5TSmutex.c @@ -108,7 +108,7 @@ H5TS_mutex_lock(H5TS_mutex_t *mutex) H5TS_NO_THREAD_SAFETY_ANALYSIS } /* end H5TS_mutex_lock() */ /*------------------------------------------------------------------------- - * Function: H5TS_mutex_try_lock + * Function: H5TS_mutex_trylock * * Purpose: Attempt to lock a H5TS_mutex_t, sets *acquired to TRUE if so * @@ -117,7 +117,7 @@ H5TS_mutex_lock(H5TS_mutex_t *mutex) H5TS_NO_THREAD_SAFETY_ANALYSIS *------------------------------------------------------------------------- */ herr_t -H5TS_mutex_try_lock(H5TS_mutex_t *mutex, bool *acquired) H5TS_NO_THREAD_SAFETY_ANALYSIS +H5TS_mutex_trylock(H5TS_mutex_t *mutex, bool *acquired) H5TS_NO_THREAD_SAFETY_ANALYSIS { int rc; herr_t ret_value = SUCCEED; @@ -134,7 +134,7 @@ H5TS_mutex_try_lock(H5TS_mutex_t *mutex, bool *acquired) H5TS_NO_THREAD_SAFETY_A done: FUNC_LEAVE_NOAPI_NAMECHECK_ONLY(ret_value) -} /* end H5TS_mutex_try_lock() */ +} /* end H5TS_mutex_trylock() */ /*------------------------------------------------------------------------- * Function: H5TS_mutex_unlock @@ -221,7 +221,7 @@ H5TS_mutex_lock(H5TS_mutex_t *mutex) H5TS_NO_THREAD_SAFETY_ANALYSIS } /* end H5TS_mutex_lock() */ /*------------------------------------------------------------------------- - * Function: H5TS_mutex_try_lock + * Function: H5TS_mutex_trylock * * Purpose: Attempt to lock a H5TS_mutex_t, sets *acquired to TRUE if so * @@ -230,14 +230,14 @@ H5TS_mutex_lock(H5TS_mutex_t *mutex) H5TS_NO_THREAD_SAFETY_ANALYSIS *------------------------------------------------------------------------- */ herr_t -H5TS_mutex_try_lock(H5TS_mutex_t *mutex, bool *acquired) H5TS_NO_THREAD_SAFETY_ANALYSIS +H5TS_mutex_trylock(H5TS_mutex_t *mutex, bool *acquired) H5TS_NO_THREAD_SAFETY_ANALYSIS { FUNC_ENTER_NOAPI_NAMECHECK_ONLY *acquired = TryEnterCriticalSection(mutex); FUNC_LEAVE_NOAPI_NAMECHECK_ONLY(SUCCEED) -} /* end H5TS_mutex_try_lock() */ +} /* end H5TS_mutex_trylock() */ /*------------------------------------------------------------------------- * Function: H5TS_mutex_unlock @@ -341,7 +341,7 @@ H5TS_mutex_lock(H5TS_mutex_t *mutex) H5TS_NO_THREAD_SAFETY_ANALYSIS } /* end H5TS_mutex_lock() */ /*------------------------------------------------------------------------- - * Function: H5TS_mutex_try_lock + * Function: H5TS_mutex_trylock * * Purpose: Attempt to lock a H5TS_mutex_t, sets *acquired to TRUE if so * @@ -350,7 +350,7 @@ H5TS_mutex_lock(H5TS_mutex_t *mutex) H5TS_NO_THREAD_SAFETY_ANALYSIS *------------------------------------------------------------------------- */ herr_t -H5TS_mutex_try_lock(H5TS_mutex_t *mutex, bool *acquired) H5TS_NO_THREAD_SAFETY_ANALYSIS +H5TS_mutex_trylock(H5TS_mutex_t *mutex, bool *acquired) H5TS_NO_THREAD_SAFETY_ANALYSIS { int rc; herr_t ret_value = SUCCEED; @@ -367,7 +367,7 @@ H5TS_mutex_try_lock(H5TS_mutex_t *mutex, bool *acquired) H5TS_NO_THREAD_SAFETY_A done: FUNC_LEAVE_NOAPI_NAMECHECK_ONLY(ret_value) -} /* end H5TS_mutex_try_lock() */ +} /* end H5TS_mutex_trylock() */ /*------------------------------------------------------------------------- * Function: H5TS_mutex_unlock diff --git a/src/H5TSpkg.h b/src/H5TSpkg.h index b43e9f1ba2c..d86413e87da 100644 --- a/src/H5TSpkg.h +++ b/src/H5TSpkg.h @@ -43,14 +43,6 @@ /* Package Private Typedefs */ /****************************/ -/* Recursive exclusive locks */ -typedef struct H5TS_ex_lock_t { - H5TS_mutex_t mutex; - H5TS_cond_t cond_var; - H5TS_thread_t owner_thread; - unsigned lock_count; -} H5TS_ex_lock_t; - /* Thread Barrier */ #ifdef H5_HAVE_PTHREAD_BARRIER typedef pthread_barrier_t H5TS_barrier_t; @@ -67,7 +59,10 @@ typedef struct H5TS_barrier_t { /* Info for the global API lock */ typedef struct H5TS_api_info_t { /* API lock */ - H5TS_ex_lock_t api_lock; + H5TS_mutex_t api_mutex; + + /* Count of recursive API calls by the same thread */ + unsigned lock_count; /* Count of # of attempts to acquire API lock */ H5TS_atomic_uint_t attempt_lock_count; @@ -255,14 +250,6 @@ H5_DLL herr_t H5TS__rw_wrlock(H5TS_rw_lock_t *rw_lock); H5_DLL herr_t H5TS__rw_unlock(H5TS_rw_lock_t *rw_lock); H5_DLL herr_t H5TS__rw_lock_destroy(H5TS_rw_lock_t *rw_lock); -/* Recursive exclusive lock related function declarations */ -H5_DLL herr_t H5TS__ex_lock_init(H5TS_ex_lock_t *lock); -H5_DLL herr_t H5TS__ex_lock(H5TS_ex_lock_t *lock); -H5_DLL herr_t H5TS__ex_acquire(H5TS_ex_lock_t *lock, unsigned lock_count, bool *acquired); -H5_DLL herr_t H5TS__ex_release(H5TS_ex_lock_t *lock, unsigned int *lock_count); -H5_DLL herr_t H5TS__ex_unlock(H5TS_ex_lock_t *lock); -H5_DLL herr_t H5TS__ex_lock_destroy(H5TS_ex_lock_t *lock); - /* Barrier related function declarations */ H5_DLL herr_t H5TS__barrier_init(H5TS_barrier_t *barrier, uint64_t count); H5_DLL herr_t H5TS__barrier_wait(H5TS_barrier_t *barrier); diff --git a/src/H5TSprivate.h b/src/H5TSprivate.h index bb43e31aeeb..a4d3ae5d422 100644 --- a/src/H5TSprivate.h +++ b/src/H5TSprivate.h @@ -183,7 +183,7 @@ H5_DLL herr_t H5TS_once(H5TS_once_t *once, H5TS_once_init_func_t func); /* Mutex operations */ H5_DLL herr_t H5TS_mutex_init(H5TS_mutex_t *mutex, int type); H5_DLL herr_t H5TS_mutex_lock(H5TS_mutex_t *mutex) H5TS_ACQUIRE(*mutex); -H5_DLL herr_t H5TS_mutex_try_lock(H5TS_mutex_t *mutex, bool *acquired) H5TS_TRY_ACQUIRE(SUCCEED, *mutex); +H5_DLL herr_t H5TS_mutex_trylock(H5TS_mutex_t *mutex, bool *acquired) H5TS_TRY_ACQUIRE(SUCCEED, *mutex); H5_DLL herr_t H5TS_mutex_unlock(H5TS_mutex_t *mutex) H5TS_RELEASE(*mutex); H5_DLL herr_t H5TS_mutex_destroy(H5TS_mutex_t *mutex); @@ -196,7 +196,7 @@ H5_DLL herr_t H5TS_cond_destroy(H5TS_cond_t *cond); /* Thread-specific keys */ H5_DLL herr_t H5TS_key_create(H5TS_key_t *key, H5TS_key_destructor_func_t dtor); -H5_DLL herr_t H5TS_key_set_value(H5TS_key_t key, const void *value); +H5_DLL herr_t H5TS_key_set_value(H5TS_key_t key, void *value); H5_DLL herr_t H5TS_key_get_value(H5TS_key_t key, void **value); H5_DLL herr_t H5TS_key_delete(H5TS_key_t key); diff --git a/src/H5TSthread.c b/src/H5TSthread.c index 2eadf062922..cd6b0ea23b2 100644 --- a/src/H5TSthread.c +++ b/src/H5TSthread.c @@ -139,7 +139,7 @@ H5TS_thread_detach(H5TS_thread_t thread) *-------------------------------------------------------------------------- */ herr_t -H5TS_thread_setcancelstate(int state, int *oldstate) +H5TS_thread_setcancelstate(int H5_ATTR_UNUSED state, int H5_ATTR_UNUSED *oldstate) { FUNC_ENTER_NOAPI_NAMECHECK_ONLY diff --git a/src/Makefile.am b/src/Makefile.am index d014d9a60e7..8e0a40cac0a 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -96,7 +96,7 @@ libhdf5_la_SOURCES= H5.c H5build_settings.c H5checksum.c H5dbg.c H5system.c \ H5Tfloat.c H5Tinit_float.c H5Tnative.c H5Toffset.c H5Toh.c H5Topaque.c \ H5Torder.c H5Tref.c H5Tpad.c H5Tprecis.c H5Tstrpad.c H5Tvisit.c \ H5Tvlen.c \ - H5TS.c H5TSatomic.c H5TSbarrier.c H5TSc11.c H5TScond.c H5TSexlock.c \ + H5TS.c H5TSatomic.c H5TSbarrier.c H5TSc11.c H5TScond.c \ H5TSint.c H5TSkey.c H5TSmutex.c H5TSonce.c H5TSpool.c H5TSpthread.c \ H5TSrwlock.c H5TSthread.c H5TSwin.c \ H5VL.c H5VLcallback.c H5VLdyn_ops.c H5VLint.c H5VLnative.c \