Skip to content

Commit

Permalink
feature switch for thread local variables and multi-threading
Browse files Browse the repository at this point in the history
thread local variables will trigger a memory allocation on a bare metal system.
use a macro to define the variable as thread local. Bare metal by definition has no
threads and so needs no qualifier.
  • Loading branch information
CrustyAuklet committed Apr 24, 2024
1 parent 2f62308 commit af299a1
Show file tree
Hide file tree
Showing 4 changed files with 12 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 "Multi-threading support and thread local variables -- disable if 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 defined(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: 'Multi-threading support and thread local variables -- disable if 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
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 af299a1

Please sign in to comment.