Skip to content

Commit

Permalink
make wait_on_address configurable via cmake
Browse files Browse the repository at this point in the history
  • Loading branch information
SchrodingerZhu committed Nov 14, 2024
1 parent 8d4c1c3 commit 3e8f9e4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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")
Expand Down
11 changes: 6 additions & 5 deletions src/snmalloc/ds/combininglock.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ namespace snmalloc
class CombiningLockNode
{
template<typename Pal>
static constexpr bool has_wait_on_address =
pal_supports<PalFeatures::WaitOnAddress, Pal>;
static constexpr bool use_wait_on_address =
pal_supports<PalFeatures::WaitOnAddress, Pal> &&
SNMALLOC_USE_WAIT_ON_ADDRESS;

template<bool HasWaitOnAddress, typename Pal>
struct WaitWordTypeSelect;
Expand All @@ -60,7 +61,7 @@ namespace snmalloc
};

using WaitingWordType =
typename WaitWordTypeSelect<has_wait_on_address<DefaultPal>, DefaultPal>::
typename WaitWordTypeSelect<use_wait_on_address<DefaultPal>, DefaultPal>::
type;

template<typename F>
Expand Down Expand Up @@ -104,7 +105,7 @@ namespace snmalloc
template<typename Pal = DefaultPal>
static void wake(CombiningLockNode* node, LockStatus message)
{
if constexpr (!has_wait_on_address<Pal>)
if constexpr (!use_wait_on_address<Pal>)
{
node->set_status(message);
}
Expand All @@ -122,7 +123,7 @@ namespace snmalloc
template<typename Pal = DefaultPal>
void wait()
{
if constexpr (!has_wait_on_address<Pal>)
if constexpr (!use_wait_on_address<Pal>)
{
while (status.load(std::memory_order_acquire) == LockStatus::WAITING)
Aal::pause();
Expand Down

0 comments on commit 3e8f9e4

Please sign in to comment.