File tree 3 files changed +21
-3
lines changed
3 files changed +21
-3
lines changed Original file line number Diff line number Diff line change @@ -105,15 +105,21 @@ if(NOT SIMDJSON_EXCEPTIONS)
105
105
target_compile_definitions (simdjson-internal -flags INTERFACE SIMDJSON_EXCEPTIONS=0)
106
106
endif ()
107
107
108
- option (SIMDJSON_ENABLE_THREADS "Enable threaded operation " ON )
108
+ option (SIMDJSON_ENABLE_THREADS "Link with thread support " ON )
109
109
if (SIMDJSON_ENABLE_THREADS)
110
110
set (CMAKE_THREAD_PREFER_PTHREAD TRUE )
111
111
set (THREADS_PREFER_PTHREAD_FLAG TRUE )
112
112
find_package (Threads REQUIRED)
113
113
target_link_libraries (simdjson-flags INTERFACE Threads::Threads)
114
114
target_link_libraries (simdjson-flags INTERFACE ${CMAKE_THREAD_LIBS_INIT} )
115
115
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
+ 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." OFF )
121
+ if (SIMDJSON_DO_NOT_USE_THREADS_NO_MATTER_WHAT)
122
+ target_compile_definitions (simdjson-flags INTERFACE SIMDJSON_DO_NOT_USE_THREADS_NO_MATTER_WHAT=1)
117
123
endif ()
118
124
119
125
if (SIMDJSON_USE_LIBCPP)
Original file line number Diff line number Diff line change @@ -101,6 +101,12 @@ A `document_stream` instance uses at most two threads: there is a main thread an
101
101
You should expect the main thread to be fully occupied while the worker thread is partially busy
102
102
(e.g., 80% of the time).
103
103
104
+ If you compile simdjson with thread support and you still do not want simdjson to use threads,
105
+ you can forcefully disable them by setting the SIMDJSON_DO_NOT_USE_THREADS_NO_MATTER_WHAT macro
106
+ to 1 in C++, or by passing SIMDJSON_DO_NOT_USE_THREADS_NO_MATTER_WHAT=ON to cmake. It is a
107
+ compile-time decision: if you disable the threads with SIMDJSON_DO_NOT_USE_THREADS_NO_MATTER_WHAT,
108
+ you will not be able to use threads in simdjson unless you recompile.
109
+
104
110
Support
105
111
-------
106
112
Original file line number Diff line number Diff line change @@ -122,7 +122,6 @@ compiling for a known 64-bit platform."
122
122
#endif
123
123
#endif
124
124
125
-
126
125
// workaround for large stack sizes under -O0.
127
126
// https://github.com/simdjson/simdjson/issues/691
128
127
#ifdef __APPLE__
@@ -136,6 +135,13 @@ compiling for a known 64-bit platform."
136
135
#endif
137
136
#endif
138
137
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
+
139
145
#if defined(__clang__)
140
146
#define NO_SANITIZE_UNDEFINED __attribute__((no_sanitize(" undefined" )))
141
147
#elif defined(__GNUC__)
You can’t perform that action at this time.
0 commit comments