From f8dc519a043962c2f5b97d2353867866e54a95f9 Mon Sep 17 00:00:00 2001 From: Kirill Pinegin Date: Thu, 14 Nov 2019 15:33:40 +0300 Subject: [PATCH] add flags, add function declaration --- CMakeLists.txt | 6 ++++++ include/mimalloc-types.h | 4 ++++ include/mimalloc.h | 5 +++++ 3 files changed, 15 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 443476f0..203da67b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,6 +12,7 @@ option(MI_USE_CXX "Use the C++ compiler to compile the library" OFF) option(MI_SECURE "Use security mitigations (like guard pages and randomization)" OFF) option(MI_LOCAL_DYNAMIC_TLS "Use slightly slower, dlopen-compatible TLS mechanism (Unix)" OFF) option(MI_BUILD_TESTS "Build test executables" ON) +option(MI_USER_CLEANUP "Enable mi_register_user_cleanup functionality" OFF) set(mi_install_dir "lib/mimalloc-${mi_version}") @@ -71,6 +72,11 @@ if(MI_SECURE MATCHES "ON") list(APPEND mi_defines MI_SECURE=2) endif() +if(MI_USER_CLEANUP MATCHES "ON") + message(STATUS "Enable mi_register_user_cleanup functionality (MI_USER_CLEANUP=ON)") + list(APPEND mi_defines MI_USER_CLEANUP=1) +endif() + if(MI_SEE_ASM MATCHES "ON") message(STATUS "Generate assembly listings (MI_SEE_ASM=ON)") list(APPEND mi_cflags -save-temps) diff --git a/include/mimalloc-types.h b/include/mimalloc-types.h index 72fb7e7e..5fbb9ea5 100644 --- a/include/mimalloc-types.h +++ b/include/mimalloc-types.h @@ -29,6 +29,10 @@ terms of the MIT license. A copy of the license can be found in the file #define MI_SECURE 0 #endif +#if !defined(MI_USER_CLEANUP) +#define MI_USER_CLEANUP 0 +#endif + // Define MI_DEBUG as 1 for basic assert checks and statistics // set it to 2 to do internal asserts, // and to 3 to do extensive invariant checking. diff --git a/include/mimalloc.h b/include/mimalloc.h index b63ed79d..f63038e5 100644 --- a/include/mimalloc.h +++ b/include/mimalloc.h @@ -114,6 +114,11 @@ mi_decl_export void mi_register_deferred_free(mi_deferred_free_fun* deferred_fre typedef void (mi_output_fun)(const char* msg); mi_decl_export void mi_register_output(mi_output_fun* out) mi_attr_noexcept; +#if MI_USER_CLEANUP +typedef void (mi_cleanup_fun)(void* user_data, void* p, size_t size); +mi_decl_export void mi_register_user_cleanup(mi_cleanup_fun* out, void* user_data) mi_attr_noexcept; +#endif + mi_decl_export void mi_collect(bool force) mi_attr_noexcept; mi_decl_export int mi_version(void) mi_attr_noexcept; mi_decl_export void mi_stats_reset(void) mi_attr_noexcept;