diff --git a/CMakeLists.txt b/CMakeLists.txt index 3941c06af..019feaa48 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,6 +27,7 @@ option(SNMALLOC_LINK_ICF "Link with Identical Code Folding" ON) option(SNMALLOC_IPO "Link with IPO/LTO support" OFF) option(SNMALLOC_BENCHMARK_INDIVIDUAL_MITIGATIONS "Build tests and ld_preload for individual mitigations" OFF) option(SNMALLOC_ENABLE_DYNAMIC_LOADING "Build such that snmalloc can be dynamically loaded. This is not required for LD_PRELOAD, and will harm performance if enabled." OFF) +option(SNMALLOC_ENABLE_WAIT_ON_ADDRESS "Use wait on address backoff strategy if it is available" ON) # Options that apply only if we're not building the header-only library cmake_dependent_option(SNMALLOC_RUST_SUPPORT "Build static library for rust" OFF "NOT SNMALLOC_HEADER_ONLY_LIBRARY" OFF) cmake_dependent_option(SNMALLOC_STATIC_LIBRARY "Build static libraries" ON "NOT SNMALLOC_HEADER_ONLY_LIBRARY" OFF) @@ -196,6 +197,13 @@ if(SNMALLOC_USE_CXX17) else() target_compile_features(snmalloc INTERFACE cxx_std_20) endif() + +if(SNMALLOC_ENABLE_WAIT_ON_ADDRESS) + target_compile_definitions(snmalloc INTERFACE SNMALLOC_USE_WAIT_ON_ADDRESS=1) +else() + target_compile_definitions(snmalloc INTERFACE SNMALLOC_USE_WAIT_ON_ADDRESS=0) +endif() + # https://learn.microsoft.com/en-us/cpp/build/reference/zc-cplusplus if(MSVC) target_compile_options(snmalloc INTERFACE "/Zc:__cplusplus") diff --git a/src/snmalloc/ds/combininglock.h b/src/snmalloc/ds/combininglock.h index d6eaea289..e632c0ced 100644 --- a/src/snmalloc/ds/combininglock.h +++ b/src/snmalloc/ds/combininglock.h @@ -41,8 +41,9 @@ namespace snmalloc class CombiningLockNode { template - static constexpr bool has_wait_on_address = - pal_supports; + static constexpr bool use_wait_on_address = + pal_supports && + SNMALLOC_USE_WAIT_ON_ADDRESS; template struct WaitWordTypeSelect; @@ -60,7 +61,7 @@ namespace snmalloc }; using WaitingWordType = - typename WaitWordTypeSelect, DefaultPal>:: + typename WaitWordTypeSelect, DefaultPal>:: type; template @@ -104,7 +105,7 @@ namespace snmalloc template static void wake(CombiningLockNode* node, LockStatus message) { - if constexpr (!has_wait_on_address) + if constexpr (!use_wait_on_address) { node->set_status(message); } @@ -122,7 +123,7 @@ namespace snmalloc template void wait() { - if constexpr (!has_wait_on_address) + if constexpr (!use_wait_on_address) { while (status.load(std::memory_order_acquire) == LockStatus::WAITING) Aal::pause();