From 15231113cb5816fa755304665a48b7aa0390eaac Mon Sep 17 00:00:00 2001 From: Allen Byrne Date: Wed, 20 Apr 2011 12:32:12 -0500 Subject: [svn-r20568] Bug #5929: On windows check for existence of InitOnceExecuteOnce for use by threads. Tested: Windows Xp and 7 --- CMakeLists.txt | 6 ++- config/cmake/ConfigureChecks.cmake | 75 +++++++++++++++++++++++++++++++++++++- config/cmake/HDF5Tests.c | 42 ++++++++++----------- 3 files changed, 98 insertions(+), 25 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a9bce2c..8d1e026 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -610,8 +610,10 @@ IF (WIN32 AND NOT CYGWIN) MESSAGE (FATAL " **** Parallel and Threadsafe options are mutually exclusive **** ") ENDIF (HDF5_ENABLE_PARALLEL) SET (H5_HAVE_THREADSAFE 1) - SET (H5_HAVE_WIN_THREADS 1) - MESSAGE (STATUS " **** Windows Threads only available in WINVER>=0x600 (Vista or Windows 7)**** ") + IF (H5_HAVE_IOEO) + MESSAGE (STATUS " **** Windows Threads only available in WINVER>=0x600 (Vista or Windows 7)**** ") + SET (H5_HAVE_WIN_THREADS 1) + ENDIF (H5_HAVE_IOEO) ENDIF (HDF5_ENABLE_THREADSAFE) ENDIF (WIN32 AND NOT CYGWIN) diff --git a/config/cmake/ConfigureChecks.cmake b/config/cmake/ConfigureChecks.cmake index 20e320f..ec16ce6 100644 --- a/config/cmake/ConfigureChecks.cmake +++ b/config/cmake/ConfigureChecks.cmake @@ -155,6 +155,7 @@ IF (WINDOWS) SET (H5_HAVE_WINDOW_PATH 1) SET (WINDOWS_MAX_BUF (1024 * 1024 * 1024)) SET (H5_DEFAULT_VFD H5FD_WINDOWS) + SET (LINK_LIBS ${LINK_LIBS} "kernel32") ELSE (WINDOWS) SET (H5_DEFAULT_VFD H5FD_SEC2) ENDIF (WINDOWS) @@ -208,7 +209,6 @@ ENDIF (NOT WINDOWS) CHECK_LIBRARY_EXISTS_CONCAT ("ws2_32" WSAStartup H5_HAVE_LIBWS2_32) CHECK_LIBRARY_EXISTS_CONCAT ("wsock32" gethostbyname H5_HAVE_LIBWSOCK32) -#CHECK_LIBRARY_EXISTS_CONCAT ("dl" dlopen H5_HAVE_LIBDL) CHECK_LIBRARY_EXISTS_CONCAT ("ucb" gethostname H5_HAVE_LIBUCB) CHECK_LIBRARY_EXISTS_CONCAT ("socket" connect H5_HAVE_LIBSOCKET) CHECK_LIBRARY_EXISTS ("c" gethostbyname "" NOT_NEED_LIBNSL) @@ -219,6 +219,9 @@ ENDIF (NOT NOT_NEED_LIBNSL) SET (USE_INCLUDES "") +IF (WINDOWS) + SET (USE_INCLUDES ${USE_INCLUDES} "windows.h") +ENDIF (WINDOWS) #----------------------------------------------------------------------------- # Check IF header file exists and add it to the list. #----------------------------------------------------------------------------- @@ -276,6 +279,7 @@ IF (H5_HAVE_STDINT_H AND CMAKE_CXX_COMPILER_LOADED) CHECK_INCLUDE_FILE_CXX ("stdint.h" H5_HAVE_STDINT_H_CXX) IF (NOT H5_HAVE_STDINT_H_CXX) SET (H5_HAVE_STDINT_H "" CACHE INTERNAL "Have includes HAVE_STDINT_H") + SET (USE_INCLUDES ${USE_INCLUDES} "stdint.h") ENDIF (NOT H5_HAVE_STDINT_H_CXX) ENDIF (H5_HAVE_STDINT_H AND CMAKE_CXX_COMPILER_LOADED) @@ -370,7 +374,10 @@ ENDIF (NOT H5_SIZEOF_OFF64_T) # For other tests to use the same libraries -SET (CMAKE_REQUIRED_LIBRARIES ${LINK_LIBS}) +SET (CMAKE_REQUIRED_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} "-DWIN32 -D_WINDOWS") +# SET (CMAKE_REQUIRED_LIBRARIES ${LINK_LIBS}) +# SET (CMAKE_REQUIRED_INCLUDES ${USE_INCLUDES}) +# CHECK_FUNCTION_EXISTS (initonceexecuteonce H5_HAVE_IOEO) #----------------------------------------------------------------------------- # Check for some functions that are used @@ -580,6 +587,70 @@ IF (NOT WINDOWS) ENDIF (NOT WINDOWS) #----------------------------------------------------------------------------- +# Check if InitOnceExecuteOnce is available +#----------------------------------------------------------------------------- +IF (WINDOWS) + MESSAGE (STATUS "Checking for InitOnceExecuteOnce:") + IF("${H5_HAVE_IOEO}" MATCHES "^${H5_HAVE_IOEO}$") + IF (LARGEFILE) + SET (CMAKE_REQUIRED_DEFINITIONS + "${CURRENT_TEST_DEFINITIONS} -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE" + ) + ENDIF (LARGEFILE) + SET(MACRO_CHECK_FUNCTION_DEFINITIONS + "-DHAVE_IOEO ${CMAKE_REQUIRED_FLAGS}") + IF(CMAKE_REQUIRED_LIBRARIES) + SET(CHECK_C_SOURCE_COMPILES_ADD_LIBRARIES + "-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES}") + ELSE(CMAKE_REQUIRED_LIBRARIES) + SET(CHECK_C_SOURCE_COMPILES_ADD_LIBRARIES) + ENDIF(CMAKE_REQUIRED_LIBRARIES) + IF(CMAKE_REQUIRED_INCLUDES) + SET(CHECK_C_SOURCE_COMPILES_ADD_INCLUDES + "-DINCLUDE_DIRECTORIES:STRING=${CMAKE_REQUIRED_INCLUDES}") + ELSE(CMAKE_REQUIRED_INCLUDES) + SET(CHECK_C_SOURCE_COMPILES_ADD_INCLUDES) + ENDIF(CMAKE_REQUIRED_INCLUDES) + + TRY_RUN(HAVE_IOEO_EXITCODE HAVE_IOEO_COMPILED + ${CMAKE_BINARY_DIR} + ${HDF5_RESOURCES_DIR}/HDF5Tests.c + COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} + CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_FUNCTION_DEFINITIONS} + -DCMAKE_SKIP_RPATH:BOOL=${CMAKE_SKIP_RPATH} + "${CHECK_C_SOURCE_COMPILES_ADD_LIBRARIES}" + "${CHECK_C_SOURCE_COMPILES_ADD_INCLUDES}" + COMPILE_OUTPUT_VARIABLE OUTPUT) + # if it did not compile make the return value fail code of 1 + IF(NOT HAVE_IOEO_COMPILED) + SET(HAVE_IOEO_EXITCODE 1) + ENDIF(NOT HAVE_IOEO_COMPILED) + # if the return value was 0 then it worked + IF("${HAVE_IOEO_EXITCODE}" EQUAL 0) + SET(H5_HAVE_IOEO 1 CACHE INTERNAL "Test InitOnceExecuteOnce") + MESSAGE(STATUS "Performing Test InitOnceExecuteOnce - Success") + FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log + "Performing C SOURCE FILE Test InitOnceExecuteOnce succeded with the following output:\n" + "${OUTPUT}\n" + "Return value: ${HAVE_IOEO}\n") + ELSE("${HAVE_IOEO_EXITCODE}" EQUAL 0) + IF(CMAKE_CROSSCOMPILING AND "${HAVE_IOEO_EXITCODE}" MATCHES "FAILED_TO_RUN") + SET(H5_HAVE_IOEO "${HAVE_IOEO_EXITCODE}") + ELSE(CMAKE_CROSSCOMPILING AND "${HAVE_IOEO_EXITCODE}" MATCHES "FAILED_TO_RUN") + SET(H5_HAVE_IOEO "" CACHE INTERNAL "Test InitOnceExecuteOnce") + ENDIF(CMAKE_CROSSCOMPILING AND "${HAVE_IOEO_EXITCODE}" MATCHES "FAILED_TO_RUN") + + MESSAGE(STATUS "Performing Test InitOnceExecuteOnce - Failed") + FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log + "Performing InitOnceExecuteOnce Test failed with the following output:\n" + "${OUTPUT}\n" + "Return value: ${HAVE_IOEO_EXITCODE}\n") + ENDIF("${HAVE_IOEO_EXITCODE}" EQUAL 0) + ENDIF("${H5_HAVE_IOEO}" MATCHES "^${H5_HAVE_IOEO}$") +ENDIF (WINDOWS) + + +#----------------------------------------------------------------------------- # Option to see if GPFS is available on this filesystem --enable-gpfs #----------------------------------------------------------------------------- OPTION (HDF5_ENABLE_GPFS "Enable GPFS hints for the MPI/POSIX file driver" OFF) diff --git a/config/cmake/HDF5Tests.c b/config/cmake/HDF5Tests.c index 55e91a4..f580bbc 100644 --- a/config/cmake/HDF5Tests.c +++ b/config/cmake/HDF5Tests.c @@ -327,16 +327,6 @@ int main () #endif /* DEV_T_IS_SCALAR */ -#if defined( INLINE_TEST_inline ) || defined( INLINE_TEST___inline__ ) || defined( INLINE_TEST___inline ) -#ifndef __cplusplus -typedef int foo_t; -static INLINE_TEST_INLINE foo_t static_foo () { return 0; } -INLINE_TEST_INLINE foo_t foo () {return 0; } -int main() { return 0; } -#endif - -#endif /* INLINE_TEST */ - #ifdef HAVE_OFF64_T #include int main() @@ -384,21 +374,31 @@ int main () #endif /* HAVE_GPFS */ -#ifdef HAVE_WIN_THREADS +#ifdef HAVE_IOEO #include +typedef void (WINAPI *PGNSI)(LPSYSTEM_INFO); int main () { - BOOL first_init_g=INIT_ONCE_STATIC_INIT; - BOOL CALLBACK win32_first_thread_init(PINIT_ONCE InitOnce, PVOID Parameter, PVOID *lpContext); - BOOL ret=FALSE; - - ret=InitOnceExecuteOnce(&first_init_g, win32_first_thread_init, NULL, NULL); - exit(ret ? 0 : 1); + PGNSI pGNSI; + pGNSI = (PGNSI) GetProcAddress( + GetModuleHandle(TEXT("kernel32.dll")), + "InitOnceExecuteOnce"); + if(NULL == pGNSI) + return 1; + else + return 0; } -BOOL CALLBACK -win32_first_thread_init(PINIT_ONCE InitOnce, PVOID Parameter, PVOID *lpContext) -{return TRUE;} -#endif /* HAVE_WIN_THREADS */ +#endif /* HAVE_IOEO */ + +#if defined( INLINE_TEST_inline ) || defined( INLINE_TEST___inline__ ) || defined( INLINE_TEST___inline ) +#ifndef __cplusplus +typedef int foo_t; +static INLINE_TEST_INLINE foo_t static_foo () { return 0; } +INLINE_TEST_INLINE foo_t foo () {return 0; } +int main() { return 0; } +#endif + +#endif /* INLINE_TEST */ -- cgit v0.12