Add jemalloc initialization helper
This commit is contained in:
parent
0fb6ba2c87
commit
167a914da5
5 changed files with 51 additions and 3 deletions
|
|
@ -5,6 +5,9 @@
|
||||||
# https://github.com/desktop-app/legal/blob/master/LEGAL
|
# https://github.com/desktop-app/legal/blob/master/LEGAL
|
||||||
|
|
||||||
add_subdirectory(external)
|
add_subdirectory(external)
|
||||||
|
if (LINUX)
|
||||||
|
add_subdirectory(linux_jemalloc_helper)
|
||||||
|
endif()
|
||||||
if (LINUX AND NOT DESKTOP_APP_USE_PACKAGED)
|
if (LINUX AND NOT DESKTOP_APP_USE_PACKAGED)
|
||||||
add_subdirectory(linux_xcb_helper)
|
add_subdirectory(linux_xcb_helper)
|
||||||
endif()
|
endif()
|
||||||
|
|
|
||||||
4
external/jemalloc/CMakeLists.txt
vendored
4
external/jemalloc/CMakeLists.txt
vendored
|
|
@ -21,7 +21,7 @@ if (DESKTOP_APP_USE_PACKAGED)
|
||||||
${JEMALLOC_INCLUDE_DIRS}
|
${JEMALLOC_INCLUDE_DIRS}
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_options(external_jemalloc
|
target_link_libraries(external_jemalloc
|
||||||
INTERFACE
|
INTERFACE
|
||||||
-Wl,--push-state,--no-as-needed,${JEMALLOC_LINK_LIBRARIES},--pop-state
|
-Wl,--push-state,--no-as-needed,${JEMALLOC_LINK_LIBRARIES},--pop-state
|
||||||
)
|
)
|
||||||
|
|
@ -48,7 +48,7 @@ INTERFACE
|
||||||
${SOURCE_DIR}/include
|
${SOURCE_DIR}/include
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_options(external_jemalloc
|
target_link_libraries(external_jemalloc
|
||||||
INTERFACE
|
INTERFACE
|
||||||
-Wl,--push-state,--whole-archive,${SOURCE_DIR}/lib/libjemalloc.a,--pop-state
|
-Wl,--push-state,--whole-archive,${SOURCE_DIR}/lib/libjemalloc.a,--pop-state
|
||||||
)
|
)
|
||||||
|
|
|
||||||
19
linux_jemalloc_helper/CMakeLists.txt
Normal file
19
linux_jemalloc_helper/CMakeLists.txt
Normal 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
|
||||||
|
)
|
||||||
25
linux_jemalloc_helper/linux_jemalloc_helper.cpp
Normal file
25
linux_jemalloc_helper/linux_jemalloc_helper.cpp
Normal 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
|
||||||
|
|
@ -64,7 +64,8 @@ endif()
|
||||||
|
|
||||||
target_link_libraries(common_options
|
target_link_libraries(common_options
|
||||||
INTERFACE
|
INTERFACE
|
||||||
desktop-app::external_jemalloc
|
desktop-app::linux_jemalloc_helper
|
||||||
|
$<TARGET_OBJECTS:desktop-app::linux_jemalloc_helper>
|
||||||
${CMAKE_DL_LIBS}
|
${CMAKE_DL_LIBS}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue