From a7a6cd043749947773cbf3e85ed66ffd6273f659 Mon Sep 17 00:00:00 2001 From: Richard Gobeille Date: Mon, 20 Dec 2021 02:58:04 -0800 Subject: [PATCH] tools: fix compilation of Build utilities --- GNUmakefile | 2 +- source/build/include/baselayer.h | 3 +-- source/build/include/compat.h | 13 +++++++++++++ source/build/include/sjson.h | 2 -- source/build/src/baselayer.cpp | 12 ++---------- source/build/src/sdlayer.cpp | 2 +- source/build/src/winlayer.cpp | 2 +- source/tools/src/generateicon.cpp | 1 + 8 files changed, 20 insertions(+), 17 deletions(-) diff --git a/GNUmakefile b/GNUmakefile index 7ebbd71a8..c8c174fb3 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -437,7 +437,7 @@ tools_obj := $(obj)/$(tools) tools_cflags := $(engine_cflags) -tools_deps := engine_tools +tools_deps := engine_tools mimalloc tools_targets := \ arttool \ diff --git a/source/build/include/baselayer.h b/source/build/include/baselayer.h index 008318003..b6d61135c 100644 --- a/source/build/include/baselayer.h +++ b/source/build/include/baselayer.h @@ -19,8 +19,7 @@ extern int app_main(int argc, char const * const * argv); extern const char* AppProperName; extern const char* AppTechnicalName; -void engineCreateAllocator(void); -void engineDestroyAllocator(void); +void engineSetupAllocator(void); #ifdef DEBUGGINGAIDS # define DEBUG_MASK_DRAWING diff --git a/source/build/include/compat.h b/source/build/include/compat.h index 5dd6d0b1d..fd536253a 100644 --- a/source/build/include/compat.h +++ b/source/build/include/compat.h @@ -1297,6 +1297,19 @@ void *handle_memerr(void); extern sm_allocator g_sm_heap; +static FORCE_INLINE void engineCreateAllocator(void) +{ + // 8 buckets of 2MB each--we don't really need to burn a lot of memory here for this thing to do its job + g_sm_heap = _sm_allocator_create(SMM_MAX_BUCKET_COUNT, 2097152); + _sm_allocator_thread_cache_create(g_sm_heap, sm::CACHE_HOT, { 20480, 32768, 32768, 1536, 4096, 8192, 128, 4096 }); +} + +static FORCE_INLINE void engineDestroyAllocator(void) +{ + _sm_allocator_thread_cache_destroy(g_sm_heap); + _sm_allocator_destroy(g_sm_heap); +} + #ifdef BITNESS64 # define ALLOC_ALIGNMENT 16 #else diff --git a/source/build/include/sjson.h b/source/build/include/sjson.h index b691bca2a..74a98ea05 100644 --- a/source/build/include/sjson.h +++ b/source/build/include/sjson.h @@ -144,8 +144,6 @@ #ifndef SJSON_H_ #define SJSON_H_ -extern "C" void engineDestroyAllocator(void); - #ifdef _MSC_VER # ifndef __cplusplus diff --git a/source/build/src/baselayer.cpp b/source/build/src/baselayer.cpp index c1fe589ee..bc81e0616 100644 --- a/source/build/src/baselayer.cpp +++ b/source/build/src/baselayer.cpp @@ -139,17 +139,9 @@ static int osdfunc_heapinfo(osdcmdptr_t UNUSED(parm)) return OSDCMD_OK; } -void engineDestroyAllocator(void) +void engineSetupAllocator(void) { - _sm_allocator_thread_cache_destroy(g_sm_heap); - _sm_allocator_destroy(g_sm_heap); -} - -void engineCreateAllocator(void) -{ - // 8 buckets of 2MB each--we don't really need to burn a lot of memory here for this thing to do its job - g_sm_heap = _sm_allocator_create(SMM_MAX_BUCKET_COUNT, 2097152); - _sm_allocator_thread_cache_create(g_sm_heap, sm::CACHE_HOT, { 20480, 32768, 32768, 1536, 4096, 8192, 128, 4096 }); + engineCreateAllocator(); #ifdef SMMALLOC_STATS_SUPPORT OSD_RegisterFunction("bucketlist", "bucketlist: list bucket statistics", osdfunc_bucketlist); diff --git a/source/build/src/sdlayer.cpp b/source/build/src/sdlayer.cpp index 27ab392ea..fa76bebf8 100644 --- a/source/build/src/sdlayer.cpp +++ b/source/build/src/sdlayer.cpp @@ -452,7 +452,7 @@ int SDL_main(int argc, char *argv[]) int main(int argc, char *argv[]) #endif { - engineCreateAllocator(); + engineSetupAllocator(); #if SDL_MAJOR_VERSION >= 2 && (SDL_MINOR_VERSION > 0 || SDL_PATCHLEVEL >= 8) if (EDUKE32_SDL_LINKED_PREREQ(linked, 2, 0, 8)) diff --git a/source/build/src/winlayer.cpp b/source/build/src/winlayer.cpp index 367c0ec03..ccf9fa25f 100644 --- a/source/build/src/winlayer.cpp +++ b/source/build/src/winlayer.cpp @@ -281,7 +281,7 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nC _CrtSetDbgFlag(_CRTDBG_CHECK_ALWAYS_DF); #endif - engineCreateAllocator(); + engineSetupAllocator(); mutex_init(&m_initprintf); diff --git a/source/tools/src/generateicon.cpp b/source/tools/src/generateicon.cpp index 16f7096e3..81f46b28b 100644 --- a/source/tools/src/generateicon.cpp +++ b/source/tools/src/generateicon.cpp @@ -61,6 +61,7 @@ int main(int argc, char **argv) memset(&icon, 0, sizeof(icon)); + engineCreateAllocator(); kpzload(argv[1], (intptr_t*)&icon.pixels, &icon.width, &icon.height); if (!icon.pixels) { Bfprintf(stderr, "Failure loading %s\n", argv[1]); -- GitLab