Skip to content

Commit

Permalink
Merge pull request #159 from CrustyAuklet/build-option-threading
Browse files Browse the repository at this point in the history
feature switch for thread_local variables and multi-threading
  • Loading branch information
cschreib authored Apr 28, 2024
2 parents fb1f8dd + 73f4935 commit ccd3afa
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ set(SNITCH_MAX_PATH_LENGTH 1024 CACHE STRING "Maximum length of a file
# Feature toggles.
set(SNITCH_DEFINE_MAIN ON CACHE BOOL "Define main() in snitch -- disable to provide your own main() function.")
set(SNITCH_WITH_EXCEPTIONS ON CACHE BOOL "Use exceptions in snitch implementation -- will be forced OFF if exceptions are not available.")
set(SNITCH_WITH_MULTITHREADING ON CACHE BOOL "Make the testing framework thread-safe -- disable if multithreading is not needed.")
set(SNITCH_WITH_TIMINGS ON CACHE BOOL "Measure the time taken by each test case -- disable to speed up tests.")
set(SNITCH_WITH_SHORTHAND_MACROS ON CACHE BOOL "Use short names for test macros -- disable if this causes conflicts.")
set(SNITCH_CONSTEXPR_FLOAT_USE_BITCAST ON CACHE BOOL "Use std::bit_cast if available to implement exact constexpr float-to-string conversion.")
Expand Down
9 changes: 9 additions & 0 deletions include/snitch/snitch_config.hpp.config
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@
#if !defined(SNITCH_WITH_CATCH2_REPORTER)
#cmakedefine01 SNITCH_WITH_CATCH2_REPORTER
#endif
#if !defined(SNITCH_WITH_MULTITHREADING)
#cmakedefine01 SNITCH_WITH_MULTITHREADING
#endif
#if !defined(SNITCH_SHARED_LIBRARY)
#cmakedefine01 SNITCH_SHARED_LIBRARY
#endif
Expand All @@ -97,6 +100,12 @@
# define SNITCH_WITH_EXCEPTIONS 0
#endif

#if SNITCH_WITH_MULTITHREADING
# define SNITCH_THREAD_LOCAL thread_local
#else
# define SNITCH_THREAD_LOCAL
#endif

#if !defined(__cpp_lib_bit_cast)
# undef SNITCH_CONSTEXPR_FLOAT_USE_BITCAST
# define SNITCH_CONSTEXPR_FLOAT_USE_BITCAST 0
Expand Down
1 change: 1 addition & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ option('max_path_length' ,type: 'integer' ,value: 1024, description: 'M
# Feature toggles.
option('define_main' ,type: 'boolean' ,value: true, description: 'Define main() in snitch -- disable to provide your own main() function.')
option('with_exceptions' ,type: 'boolean' ,value: true, description: 'Use exceptions in snitch implementation -- will be forced OFF if exceptions are not available.')
option('with_multithreading' ,type: 'boolean', value: true, description: 'Make the testing framework thread-safe -- disable if multithreading is not needed.')
option('with_timings' ,type: 'boolean' ,value: true, description: 'Measure the time taken by each test case -- disable to speed up tests.')
option('with_shorthand_macros' ,type: 'boolean' ,value: true, description: 'Use short names for test macros -- disable if this causes conflicts.')
option('constexpr_float_use_bitcast' ,type: 'boolean' ,value: true, description: 'Use std::bit_cast if available to implement exact constexpr float-to-string conversion.')
Expand Down
1 change: 1 addition & 0 deletions snitch/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ conf_data = configuration_data({

'SNITCH_DEFINE_MAIN' : get_option('define_main').to_int(),
'SNITCH_WITH_EXCEPTIONS' : get_option('with_exceptions').to_int(),
'SNITCH_WITH_MULTITHREADING' : get_option('with_multithreading').to_int(),
'SNITCH_WITH_TIMINGS' : get_option('with_timings').to_int(),
'SNITCH_WITH_SHORTHAND_MACROS' : get_option('with_shorthand_macros').to_int(),
'SNITCH_CONSTEXPR_FLOAT_USE_BITCAST' : get_option('constexpr_float_use_bitcast').to_int(),
Expand Down
2 changes: 1 addition & 1 deletion src/snitch_test_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace snitch::impl {
namespace {
thread_local test_state* thread_current_test = nullptr;
SNITCH_THREAD_LOCAL test_state* thread_current_test = nullptr;
}

test_state& get_current_test() noexcept {
Expand Down

0 comments on commit ccd3afa

Please sign in to comment.