Skip to content

Commit

Permalink
move USING_MLOCK to cmakelists with USE_MIMALLOC to control mimalolc …
Browse files Browse the repository at this point in the history
…linking
  • Loading branch information
Cathrach committed Sep 29, 2022
1 parent 626bcdb commit 72a940d
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
1 change: 1 addition & 0 deletions .github/workflows/protocol-check-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ jobs:
-D CMAKE_BUILD_TYPE=Debug \
-D CHECK_CI=TRUE \
-D SANITIZE=address+undefined \
-D USE_MIMALLOC=OFF \
-D MACOS_TARGET_ARCHITECTURE=${{ matrix.config.arch }}
cd build
Expand Down
6 changes: 5 additions & 1 deletion protocol/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ endif()
option(SANITIZE "Enable sanitizer during build (address, thread, undefined)." OFF)
option(CLIENT_SHARED_LIB "Build the client as a shared library" OFF)
option(USE_CCACHE "Use ccache to speed up builds" OFF)
option(USE_MIMALLOC "Link the client to mimalloc" ON)

# Add our compiler flags
include(cmake/compiler-options.cmake)
Expand Down Expand Up @@ -272,7 +273,7 @@ else()
find_package(OpenSSL REQUIRED)
endif()

if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin" AND USE_MIMALLOC)
# We manually compile a malloc hook so we can mlock all memory allocations in the protocol, improving latency when memory pressure is high
# see github.com/whisthq/mimalloc
message(STATUS "Looking for mimalloc lib: libmimalloc.a")
Expand Down Expand Up @@ -302,6 +303,9 @@ message(STATUS "Looking for mimalloc lib: libmimalloc.a")
message(FATAL_ERROR "Library Sentry was not found! ${SENTRY_DIR_PATH}")
endif()
list(APPEND SHARED_LIBS_PATHS ${SENTRY_DIR_PATH})
add_compile_definitions(USING_MLOCK=true)
else()
add_compile_definitions(USING_MLOCK=false)
endif()

set(SDL2_DIR_PATH "${CMAKE_BINARY_DIR}/lib/${arch}/SDL2/${CMAKE_SYSTEM_NAME}")
Expand Down
6 changes: 3 additions & 3 deletions protocol/whist/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ add_library(whistCore STATIC
error_codes.c
whist_string.c
)
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")

if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin" AND USE_MIMALLOC)
target_sources(whistCore PRIVATE
mimalloc_hook.cpp
)
target_link_libraries(whistCore ${LIB_MIMALLOC})
endif()

# Ensure that whist.v is updated prior to compiling whistCore
add_dependencies(whistCore git_revision)

set_property(TARGET whistCore PROPERTY
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")

target_link_libraries(whistCore ${LIB_MIMALLOC})
6 changes: 0 additions & 6 deletions protocol/whist/core/whist.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@ Includes

#include "platform.h"

#if OS_IS(OS_MACOS)
#define USING_MLOCK true
#else
#define USING_MLOCK false
#endif

#ifdef __cplusplus

// whist.h supports direct cpp inclusion, with internal extern "C"
Expand Down

0 comments on commit 72a940d

Please sign in to comment.