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

Split H5TS termination into threadlocal/thread-global parts #4881

Merged
merged 3 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 4 additions & 1 deletion src/H5.c
Original file line number Diff line number Diff line change
Expand Up @@ -433,11 +433,14 @@ H5_term_library(void)
/* Shut down the following packages in strictly the order given
* by the table.
*/
, TERMINATOR(CX, true)
qkoziol marked this conversation as resolved.
Show resolved Hide resolved
#ifdef H5_HAVE_THREADSAFE
, TERMINATOR(TS_top, true)
#endif
, TERMINATOR(E, true)
, TERMINATOR(I, true)
, TERMINATOR(SL, true)
, TERMINATOR(FL, true)
, TERMINATOR(CX, true)
};

do {
Expand Down
38 changes: 30 additions & 8 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,8 +153,8 @@ 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();
/* Release critical section / mutex for modifying the thread info globals */
H5TS_mutex_destroy(&H5TS_tinfo_mtx_s);
mattjala marked this conversation as resolved.
Show resolved Hide resolved

FUNC_LEAVE_NOAPI_VOID
} /* end H5TS_term_package() */
Expand Down Expand Up @@ -535,6 +537,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,10 +588,6 @@ 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);
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
Loading