From 883cbbee35c60a803cb9f2ca3df472fbd5db46ff Mon Sep 17 00:00:00 2001 From: Quincey Koziol Date: Wed, 20 Nov 2024 16:52:07 -0500 Subject: [PATCH] Revert changes for detecting C11 threads Signed-off-by: Quincey Koziol --- CMakeLists.txt | 52 ++++++++++++++++++++-------------------------- configure.ac | 2 +- src/CMakeLists.txt | 5 +++-- 3 files changed, 26 insertions(+), 33 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c6cc25468dc..73dc2d3ee28 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -794,43 +794,35 @@ endif () # Determine if a threading package is available on this system option (HDF5_ENABLE_THREADS "Enable thread support" ON) -if (HDF5_ENABLE_THREADS) - # When C11 threads are available, those are the top choice - CHECK_INCLUDE_FILE("threads.h" HAVE_THREADS_H) - if (HAVE_THREADS_H) - set (H5_HAVE_C11_THREADS 1) - else() - # Determine which threading package to use - set (THREADS_PREFER_PTHREAD_FLAG ON) - find_package (Threads) - - if (Threads_FOUND) - # When Win32 is available, we use those threads - if (WIN32) - set (H5_HAVE_WIN_THREADS 1) - else() - if (CMAKE_USE_PTHREADS_INIT) - set (H5_HAVE_PTHREAD_H 1) - else() - message (FATAL_ERROR " **** thread support requires C11 threads, Win32 threads or Pthreads **** ") - endif() - endif() - - set (CMAKE_REQUIRED_LIBRARIES ${CMAKE_THREAD_LIBS_INIT}) - else() - message (FATAL_ERROR " **** thread support requires C11 threads, Win32 threads or Pthreads **** ") - endif() - endif() - - # Threads are available +set (THREADS_PREFER_PTHREAD_FLAG ON) +find_package (Threads) +if (Threads_FOUND) set (H5_HAVE_THREADS 1) + set (CMAKE_REQUIRED_LIBRARIES ${CMAKE_THREAD_LIBS_INIT}) + + # Determine which threading package to use + # Comment out check for C11 threads for now, since it conflicts with the + # current --std=c99 compile flags at configuration time. When we switch to + # --std=c11, this can be uncommented. + #CHECK_INCLUDE_FILE("threads.h" HAVE_THREADS_H) + if (WIN32) + # When Win32 is available, we use those threads + set (H5_HAVE_WIN_THREADS 1) + elseif (HAVE_THREADS_H) + # When C11 threads are available, those are the top choice + set (H5_HAVE_C11_THREADS 1) + elseif (CMAKE_USE_PTHREADS_INIT) + set (H5_HAVE_PTHREAD_H 1) + else () + message (FATAL_ERROR " **** thread support requires C11 threads, Win32 threads or Pthreads **** ") + endif () # Check for compiler support for atomic variables CHECK_INCLUDE_FILE("stdatomic.h" HAVE_STDATOMIC_H) if (HAVE_STDATOMIC_H) set (H5_HAVE_STDATOMIC_H 1) endif() -endif() +endif () # Determine whether to build the HDF5 Subfiling VFD set (H5FD_SUBFILING_DIR ${HDF5_SRC_DIR}/H5FDsubfiling) diff --git a/configure.ac b/configure.ac index 82a3febf370..72bc8f91b76 100644 --- a/configure.ac +++ b/configure.ac @@ -2237,7 +2237,7 @@ if test "X$THREADS" = "Xyes"; then # Comment out check for C11 threads for now, since it conflicts with the # current --std=c99 compile flags at configuration time. When we switch to # --std=c11, this can be uncommented. - AC_CHECK_HEADERS([threads.h],[HAVE_THREADS_H="yes"],[HAVE_THREADS_H="no"]) + #AC_CHECK_HEADERS([threads.h],[HAVE_THREADS_H="yes"],[HAVE_THREADS_H="no"]) if test "x$HAVE_THREADS_H" = "xyes"; then # Default or no --> C11 threads if test "$withval" = "default" -o "$withval" = "no" ; then diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index eb50ba4f3e9..9afa502c990 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -647,6 +647,7 @@ set (H5TS_SOURCES ${HDF5_SRC_DIR}/H5TSbarrier.c ${HDF5_SRC_DIR}/H5TSc11.c ${HDF5_SRC_DIR}/H5TScond.c + ${HDF5_SRC_DIR}/H5TSdlftt_mutex.c ${HDF5_SRC_DIR}/H5TSint.c ${HDF5_SRC_DIR}/H5TSkey.c ${HDF5_SRC_DIR}/H5TSmutex.c @@ -1113,7 +1114,7 @@ if (BUILD_STATIC_LIBS) ) if (NOT WIN32) target_link_libraries (${HDF5_LIB_TARGET} - PRIVATE "$<$,$>:${CMAKE_THREAD_LIBS_INIT}>" + PRIVATE "$<$,$>:Threads::Threads>" ) endif () set_global_variable (HDF5_LIBRARIES_TO_EXPORT ${HDF5_LIB_TARGET}) @@ -1145,7 +1146,7 @@ if (BUILD_SHARED_LIBS) TARGET_C_PROPERTIES (${HDF5_LIBSH_TARGET} SHARED) target_link_libraries (${HDF5_LIBSH_TARGET} PRIVATE ${LINK_LIBS} ${LINK_COMP_LIBS} - PUBLIC "$<$:${LINK_PUB_LIBS}>" "$<$>:${CMAKE_DL_LIBS}>" "$<$:MPI::MPI_C>" "$<$,$>:${CMAKE_THREAD_LIBS_INIT}>" + PUBLIC "$<$:${LINK_PUB_LIBS}>" "$<$>:${CMAKE_DL_LIBS}>" "$<$:MPI::MPI_C>" "$<$,$>:Threads::Threads>" ) set_global_variable (HDF5_LIBRARIES_TO_EXPORT "${HDF5_LIBRARIES_TO_EXPORT};${HDF5_LIBSH_TARGET}") H5_SET_LIB_OPTIONS (${HDF5_LIBSH_TARGET} ${HDF5_LIB_NAME} SHARED "LIB")