1
0
Fork 0

Add jemalloc initialization helper

This commit is contained in:
Ilya Fedin 2022-01-29 02:26:13 +04:00 committed by John Preston
parent 0fb6ba2c87
commit 167a914da5
5 changed files with 51 additions and 3 deletions

View file

@ -5,6 +5,9 @@
# https://github.com/desktop-app/legal/blob/master/LEGAL
add_subdirectory(external)
if (LINUX)
add_subdirectory(linux_jemalloc_helper)
endif()
if (LINUX AND NOT DESKTOP_APP_USE_PACKAGED)
add_subdirectory(linux_xcb_helper)
endif()

View file

@ -21,7 +21,7 @@ if (DESKTOP_APP_USE_PACKAGED)
${JEMALLOC_INCLUDE_DIRS}
)
target_link_options(external_jemalloc
target_link_libraries(external_jemalloc
INTERFACE
-Wl,--push-state,--no-as-needed,${JEMALLOC_LINK_LIBRARIES},--pop-state
)
@ -48,7 +48,7 @@ INTERFACE
${SOURCE_DIR}/include
)
target_link_options(external_jemalloc
target_link_libraries(external_jemalloc
INTERFACE
-Wl,--push-state,--whole-archive,${SOURCE_DIR}/lib/libjemalloc.a,--pop-state
)

View file

@ -0,0 +1,19 @@
# This file is part of Desktop App Toolkit,
# a set of libraries for developing nice desktop applications.
#
# For license and copyright information please follow this link:
# https://github.com/desktop-app/legal/blob/master/LEGAL
add_library(linux_jemalloc_helper OBJECT)
init_target(linux_jemalloc_helper "(external)")
add_library(desktop-app::linux_jemalloc_helper ALIAS linux_jemalloc_helper)
nice_target_sources(linux_jemalloc_helper ${CMAKE_CURRENT_SOURCE_DIR}
PRIVATE
linux_jemalloc_helper.cpp
)
target_link_libraries(linux_jemalloc_helper
PRIVATE
desktop-app::external_jemalloc
)

View file

@ -0,0 +1,25 @@
// This file is part of Desktop App Toolkit,
// a set of libraries for developing nice desktop applications.
//
// For license and copyright information please follow this link:
// https://github.com/desktop-app/legal/blob/master/LEGAL
//
#ifdef __FREEBSD__
#include <malloc_np.h>
#else // __FREEBSD__
#include <jemalloc/jemalloc.h>
#endif // !__FREEBSD__
namespace {
class JemallocInitializer {
public:
JemallocInitializer() {
auto backgroundThread = true;
mallctl("background_thread", nullptr, nullptr, &backgroundThread, sizeof(bool));
}
};
static const JemallocInitializer initializer;
} // namespace

View file

@ -64,7 +64,8 @@ endif()
target_link_libraries(common_options
INTERFACE
desktop-app::external_jemalloc
desktop-app::linux_jemalloc_helper
$<TARGET_OBJECTS:desktop-app::linux_jemalloc_helper>
${CMAKE_DL_LIBS}
)