Skip to content

Commit

Permalink
Split H5TS termination into threadlocal/thread-global parts (#4881)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattjala authored Oct 1, 2024
1 parent 35adecb commit 62e4777
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
40 changes: 31 additions & 9 deletions src/H5TSint.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,12 @@ H5TS__init(void)
/*-------------------------------------------------------------------------
* Function: H5TS_term_package
*
* Purpose: Terminate this interface.
* Purpose: Terminate this interface. Clean up global resources shared by
* all threads.
*
* Note: This function is currently registered via atexit() and is called
* AFTER H5_term_library().
* AFTER H5_term_library(). H5TS_top_term_package() is called at library
* termination to clean up per-thread resources.
*
* Return: void
*
Expand All @@ -151,9 +153,6 @@ H5TS_term_package(void)
H5TS_mutex_destroy(&H5TS_api_info_p.api_mutex);
H5TS_atomic_destroy_uint(&H5TS_api_info_p.attempt_lock_count);

/* Clean up per-thread library info */
H5TS__tinfo_term();

FUNC_LEAVE_NOAPI_VOID
} /* end H5TS_term_package() */

Expand Down Expand Up @@ -535,6 +534,30 @@ H5TS__tinfo_destroy(void *_tinfo_node)
FUNC_LEAVE_NOAPI_VOID_NAMECHECK_ONLY
}

/*--------------------------------------------------------------------------
* Function: H5TS_top_term_package
*
* Purpose: Terminate the threadlocal parts of the H5TS interface during library terminaton.
*
* Note: See H5TS_term_package for termination of the thread-global resources
*
* Return: Non-negative on success / Negative on failure
*
*--------------------------------------------------------------------------
*/
int
H5TS_top_term_package(void)
{
int n = 0;

FUNC_ENTER_NOAPI_NOINIT_NOERR

/* Clean up per-thread library info */
H5TS__tinfo_term();

FUNC_LEAVE_NOAPI(n)
}

/*--------------------------------------------------------------------------
* Function: H5TS__tinfo_term
*
Expand Down Expand Up @@ -562,14 +585,13 @@ H5TS__tinfo_term(void)
if (H5_UNLIKELY(H5TS_mutex_unlock(&H5TS_tinfo_mtx_s) < 0))
HGOTO_DONE(FAIL);

/* Release critical section / mutex for modifying the thread info globals */
if (H5_UNLIKELY(H5TS_mutex_destroy(&H5TS_tinfo_mtx_s) < 0))
HGOTO_DONE(FAIL);

/* Release key for thread-specific API contexts */
if (H5_UNLIKELY(H5TS_key_delete(H5TS_thrd_info_key_g) < 0))
HGOTO_DONE(FAIL);

/* Release critical section / mutex for modifying the thread info globals */
if (H5_UNLIKELY(H5TS_mutex_destroy(&H5TS_tinfo_mtx_s) < 0))
HGOTO_DONE(FAIL);
done:
FUNC_LEAVE_NOAPI_NAMECHECK_ONLY(ret_value)
} /* end H5TS__tinfo_term() */
Expand Down
1 change: 1 addition & 0 deletions src/H5TSprivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ typedef atomic_flag H5TS_spinlock_t;
#ifdef H5_HAVE_THREADSAFE
/* Library/thread init/term operations */
H5_DLL void H5TS_term_package(void);
H5_DLL int H5TS_top_term_package(void);

/* API locking */
H5_DLL herr_t H5TS_api_lock(void);
Expand Down

0 comments on commit 62e4777

Please sign in to comment.