Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop HD prefix & hbool_t from H5TS #3180

Merged
merged 1 commit into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 30 additions & 50 deletions src/H5TS.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

/*
* Purpose: This file contains the framework for ensuring that the global
* library lock is held when an API routine is called. This
* framework works in concert with the FUNC_ENTER_API / FUNC_LEAVE_API
* macros defined in H5private.h.
* Purpose: This file contains the framework for ensuring that the global
* library lock is held when an API routine is called. This
* framework works in concert with the FUNC_ENTER_API / FUNC_LEAVE_API
* macros defined in H5private.h.
*
* Note: Because this threadsafety framework operates outside the library,
* it does not use the error stack and only uses the "namecheck only"
* FUNC_ENTER_* / FUNC_LEAVE_* macros.
* it does not use the error stack and only uses the "namecheck only"
* FUNC_ENTER_* / FUNC_LEAVE_* macros.
*/

/****************/
Expand Down Expand Up @@ -55,7 +55,7 @@ typedef void *(*H5TS_thread_cb_t)(void *);
/* Local Prototypes */
/********************/
static void H5TS__key_destructor(void *key_val);
static herr_t H5TS__mutex_acquire(H5TS_mutex_t *mutex, unsigned int lock_count, hbool_t *acquired);
static herr_t H5TS__mutex_acquire(H5TS_mutex_t *mutex, unsigned int lock_count, bool *acquired);
static herr_t H5TS__mutex_unlock(H5TS_mutex_t *mutex, unsigned int *lock_count);

/*********************/
Expand Down Expand Up @@ -148,20 +148,16 @@ static H5TS_key_t H5TS_tid_key;
* Frees the memory for a key. Called by each thread as it exits.
* Currently all the thread-specific information for all keys are simple
* structures allocated with malloc, so we can free them all uniformly.
*
* PROGRAMMER: Quincey Koziol
* February 7, 2003
*
*--------------------------------------------------------------------------
*/
static void
H5TS__key_destructor(void *key_val)
{
FUNC_ENTER_PACKAGE_NAMECHECK_ONLY

/* Use HDfree here instead of H5MM_xfree(), to avoid calling the H5CS routines */
/* Use free() here instead of H5MM_xfree(), to avoid calling the H5CS routines */
if (key_val != NULL)
HDfree(key_val);
free(key_val);

FUNC_LEAVE_NOAPI_VOID_NAMECHECK_ONLY
} /* end H5TS__key_destructor() */
Expand Down Expand Up @@ -270,7 +266,7 @@ H5TS_thread_id(void)

/* If a prototype ID record was established, copy it to the heap. */
if (tid == &proto_tid)
if ((tid = HDmalloc(sizeof(*tid))) != NULL)
if ((tid = malloc(sizeof(*tid))) != NULL)
*tid = proto_tid;

if (tid == NULL)
Expand Down Expand Up @@ -310,8 +306,8 @@ H5TS_thread_id(void)
void
H5TS_pthread_first_thread_init(void)
{
H5_g.H5_libinit_g = FALSE; /* Library hasn't been initialized */
H5_g.H5_libterm_g = FALSE; /* Library isn't being shutdown */
H5_g.H5_libinit_g = false; /* Library hasn't been initialized */
H5_g.H5_libterm_g = false; /* Library isn't being shutdown */

FUNC_ENTER_NOAPI_NAMECHECK_ONLY

Expand Down Expand Up @@ -361,22 +357,18 @@ H5TS_pthread_first_thread_init(void)
* Note: The Windows threads code is very likely bogus.
*
* Return: Non-negative on success / Negative on failure
*
* Programmer: Quincey Koziol
* Februrary 27, 2019
*
*--------------------------------------------------------------------------
*/
static herr_t
H5TS__mutex_acquire(H5TS_mutex_t *mutex, unsigned int lock_count, hbool_t *acquired)
H5TS__mutex_acquire(H5TS_mutex_t *mutex, unsigned int lock_count, bool *acquired)
{
herr_t ret_value = SUCCEED;

FUNC_ENTER_PACKAGE_NAMECHECK_ONLY

#ifdef H5_HAVE_WIN_THREADS
EnterCriticalSection(&mutex->CriticalSection);
*acquired = TRUE;
*acquired = true;
#else /* H5_HAVE_WIN_THREADS */
/* Attempt to acquire the mutex lock */
if (0 == pthread_mutex_lock(&mutex->atomic_lock)) {
Expand All @@ -388,21 +380,21 @@ H5TS__mutex_acquire(H5TS_mutex_t *mutex, unsigned int lock_count, hbool_t *acqui
if (pthread_equal(my_thread_id, mutex->owner_thread)) {
/* Already owned by self - increment count */
mutex->lock_count += lock_count;
*acquired = TRUE;
} /* end if */
*acquired = true;
}
else
*acquired = FALSE;
} /* end if */
*acquired = false;
}
else {
/* Take ownership of the mutex */
mutex->owner_thread = my_thread_id;
mutex->lock_count = lock_count;
*acquired = TRUE;
} /* end else */
*acquired = true;
}

if (0 != pthread_mutex_unlock(&mutex->atomic_lock))
ret_value = -1;
} /* end if */
}
else
ret_value = -1;
#endif /* H5_HAVE_WIN_THREADS */
Expand All @@ -419,14 +411,10 @@ H5TS__mutex_acquire(H5TS_mutex_t *mutex, unsigned int lock_count, hbool_t *acqui
* global lock was acquired.
*
* Return: Non-negative on success / Negative on failure
*
* Programmer: Quincey Koziol
* Februrary 27, 2019
*
*--------------------------------------------------------------------------
*/
herr_t
H5TSmutex_acquire(unsigned int lock_count, hbool_t *acquired){
H5TSmutex_acquire(unsigned int lock_count, bool *acquired){
FUNC_ENTER_API_NAMECHECK_ONLY

FUNC_LEAVE_API_NAMECHECK_ONLY(H5TS__mutex_acquire(&H5_g.init_lock, lock_count, acquired))}
Expand Down Expand Up @@ -487,7 +475,7 @@ herr_t H5TS_mutex_lock(H5TS_mutex_t *mutex)
/* After we've received the signal, take ownership of the mutex */
mutex->owner_thread = pthread_self();
mutex->lock_count = 1;
} /* end else */
}

/* Release the library lock */
ret_value = pthread_mutex_unlock(&mutex->atomic_lock);
Expand Down Expand Up @@ -545,7 +533,7 @@ H5TS__mutex_unlock(H5TS_mutex_t *mutex, unsigned int *lock_count)
err = pthread_cond_signal(&mutex->cond_var);
if (err != 0)
ret_value = err;
} /* end if */
}

done:
#endif /* H5_HAVE_WIN_THREADS */
Expand Down Expand Up @@ -600,7 +588,7 @@ H5TS_mutex_unlock(H5TS_mutex_t *mutex)
err = pthread_cond_signal(&mutex->cond_var);
if (err != 0)
ret_value = err;
} /* end if */
}

done:
#endif /* H5_HAVE_WIN_THREADS */
Expand All @@ -613,10 +601,6 @@ H5TS_mutex_unlock(H5TS_mutex_t *mutex)
* Purpose: Get the current count of the global lock attempt
*
* Return: Non-negative on success / Negative on failure
*
* Programmer: Houjun Tang
* June 24, 2019
*
*--------------------------------------------------------------------------
*/
herr_t
Expand Down Expand Up @@ -650,10 +634,6 @@ H5TSmutex_get_attempt_count(unsigned int *count)
* Purpose: Releases the HDF5 library global lock
*
* Return: Non-negative on success / Negative on failure
*
* Programmer: Quincey Koziol
* Februrary 27, 2019
*
*--------------------------------------------------------------------------
*/
herr_t
Expand Down Expand Up @@ -716,20 +696,20 @@ H5TS_cancel_count_inc(void)
* First time thread calls library - create new counter and associate
* with key.
*
* Don't use H5MM calls here since the destructor has to use HDfree in
* Don't use H5MM calls here since the destructor has to use free in
* order to avoid codestack calls.
*/
cancel_counter = (H5TS_cancel_t *)HDcalloc(1, sizeof(H5TS_cancel_t));
cancel_counter = (H5TS_cancel_t *)calloc(1, sizeof(H5TS_cancel_t));
if (NULL == cancel_counter)
HGOTO_DONE(FAIL);

/* Set the thread's cancellation counter with the new object */
ret_value = pthread_setspecific(H5TS_cancel_key_s, (void *)cancel_counter);
if (ret_value) {
HDfree(cancel_counter);
free(cancel_counter);
HGOTO_DONE(FAIL);
} /* end if */
} /* end if */
}
}

/* Check if thread entering library */
if (cancel_counter->cancel_count == 0)
Expand Down
2 changes: 1 addition & 1 deletion src/H5TSdevelop.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ extern "C" {
#endif

/* HDF5 global library lock routines */
H5_DLL herr_t H5TSmutex_acquire(unsigned int lock_count, hbool_t *acquired);
H5_DLL herr_t H5TSmutex_acquire(unsigned int lock_count, bool *acquired);
H5_DLL herr_t H5TSmutex_release(unsigned int *lock_count);
H5_DLL herr_t H5TSmutex_get_attempt_count(unsigned int *count);

Expand Down