Merge pull request #995 from simdjson/dlemire/issue988

This introduces a new option to forcefully disable threads for people who also want them enabled
This commit is contained in:
Daniel Lemire 2020-06-26 18:37:18 -04:00 committed by GitHub
commit 13e1794e91
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 3 deletions

View File

@ -105,7 +105,7 @@ if(NOT SIMDJSON_EXCEPTIONS)
target_compile_definitions(simdjson-internal-flags INTERFACE SIMDJSON_EXCEPTIONS=0)
endif()
option(SIMDJSON_ENABLE_THREADS "Enable threaded operation" ON)
option(SIMDJSON_ENABLE_THREADS "Link with thread support" ON)
if(SIMDJSON_ENABLE_THREADS)
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
@ -113,7 +113,18 @@ if(SIMDJSON_ENABLE_THREADS)
target_link_libraries(simdjson-flags INTERFACE Threads::Threads)
target_link_libraries(simdjson-flags INTERFACE ${CMAKE_THREAD_LIBS_INIT})
target_compile_options(simdjson-flags INTERFACE ${CMAKE_THREAD_LIBS_INIT})
target_compile_definitions(simdjson-flags INTERFACE SIMDJSON_THREADS_ENABLED=1)
target_compile_definitions(simdjson-flags INTERFACE SIMDJSON_THREADS_ENABLED=1) # This will be set in the code automatically.
endif()
# Some users compile simdjson with thread support but still do not want simdjson to use threads.
#
# Important : Expect this option to disappear in the future.
#
option(SIMDJSON_DO_NOT_USE_THREADS_NO_MATTER_WHAT "Whether we enabled thread support or not (SIMDJSON_ENABLE_THREADS), do not use threads.\
This option does nothing when thread support is not enabled. We reserve the right to remove this option in a future release in\
favor of a runtime approach." OFF)
if(SIMDJSON_DO_NOT_USE_THREADS_NO_MATTER_WHAT)
target_compile_definitions(simdjson-flags INTERFACE SIMDJSON_DO_NOT_USE_THREADS_NO_MATTER_WHAT=1)
endif()
if(SIMDJSON_USE_LIBCPP)

View File

@ -122,7 +122,6 @@ compiling for a known 64-bit platform."
#endif
#endif
// workaround for large stack sizes under -O0.
// https://github.com/simdjson/simdjson/issues/691
#ifdef __APPLE__
@ -136,6 +135,13 @@ compiling for a known 64-bit platform."
#endif
#endif
#if SIMDJSON_DO_NOT_USE_THREADS_NO_MATTER_WHAT
// No matter what happened, we undefine SIMDJSON_THREADS_ENABLED and so disable threads.
#undef SIMDJSON_THREADS_ENABLED
#endif
#if defined(__clang__)
#define NO_SANITIZE_UNDEFINED __attribute__((no_sanitize("undefined")))
#elif defined(__GNUC__)