Skip to content

Commit 13e1794

Browse files
authored
Merge pull request simdjson#995 from simdjson/dlemire/issue988
This introduces a new option to forcefully disable threads for people who also want them enabled
2 parents 86241e2 + 67b3595 commit 13e1794

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

cmake/simdjson-flags.cmake

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,26 @@ if(NOT SIMDJSON_EXCEPTIONS)
105105
target_compile_definitions(simdjson-internal-flags INTERFACE SIMDJSON_EXCEPTIONS=0)
106106
endif()
107107

108-
option(SIMDJSON_ENABLE_THREADS "Enable threaded operation" ON)
108+
option(SIMDJSON_ENABLE_THREADS "Link with thread support" ON)
109109
if(SIMDJSON_ENABLE_THREADS)
110110
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
111111
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
112112
find_package(Threads REQUIRED)
113113
target_link_libraries(simdjson-flags INTERFACE Threads::Threads)
114114
target_link_libraries(simdjson-flags INTERFACE ${CMAKE_THREAD_LIBS_INIT})
115115
target_compile_options(simdjson-flags INTERFACE ${CMAKE_THREAD_LIBS_INIT})
116-
target_compile_definitions(simdjson-flags INTERFACE SIMDJSON_THREADS_ENABLED=1)
116+
target_compile_definitions(simdjson-flags INTERFACE SIMDJSON_THREADS_ENABLED=1) # This will be set in the code automatically.
117+
endif()
118+
119+
# Some users compile simdjson with thread support but still do not want simdjson to use threads.
120+
#
121+
# Important : Expect this option to disappear in the future.
122+
#
123+
option(SIMDJSON_DO_NOT_USE_THREADS_NO_MATTER_WHAT "Whether we enabled thread support or not (SIMDJSON_ENABLE_THREADS), do not use threads.\
124+
This option does nothing when thread support is not enabled. We reserve the right to remove this option in a future release in\
125+
favor of a runtime approach." OFF)
126+
if(SIMDJSON_DO_NOT_USE_THREADS_NO_MATTER_WHAT)
127+
target_compile_definitions(simdjson-flags INTERFACE SIMDJSON_DO_NOT_USE_THREADS_NO_MATTER_WHAT=1)
117128
endif()
118129

119130
if(SIMDJSON_USE_LIBCPP)

include/simdjson/portability.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ compiling for a known 64-bit platform."
122122
#endif
123123
#endif
124124
125-
126125
// workaround for large stack sizes under -O0.
127126
// https://github.com/simdjson/simdjson/issues/691
128127
#ifdef __APPLE__
@@ -136,6 +135,13 @@ compiling for a known 64-bit platform."
136135
#endif
137136
#endif
138137
138+
139+
#if SIMDJSON_DO_NOT_USE_THREADS_NO_MATTER_WHAT
140+
// No matter what happened, we undefine SIMDJSON_THREADS_ENABLED and so disable threads.
141+
#undef SIMDJSON_THREADS_ENABLED
142+
#endif
143+
144+
139145
#if defined(__clang__)
140146
#define NO_SANITIZE_UNDEFINED __attribute__((no_sanitize("undefined")))
141147
#elif defined(__GNUC__)

0 commit comments

Comments
 (0)