diff options
Diffstat (limited to 'sal/rtl/strimp.cxx')
-rw-r--r-- | sal/rtl/strimp.cxx | 53 |
1 files changed, 37 insertions, 16 deletions
diff --git a/sal/rtl/strimp.cxx b/sal/rtl/strimp.cxx index ed0d333639d2..d520d2412b6e 100644 --- a/sal/rtl/strimp.cxx +++ b/sal/rtl/strimp.cxx @@ -21,6 +21,7 @@ #include <assert.h> #include <rtl/alloc.h> #include <rtl/ustring.h> +#include <rtllifecycle.h> #include "strimp.hxx" #include "alloc_impl.hxx" @@ -93,25 +94,45 @@ static void mark_static(void *addr, sal_Size /* size */, void *) str->refCount |= SAL_STRING_STATIC_FLAG; } -void SAL_CALL rtl_alloc_preInit (sal_Bool start) SAL_THROW_EXTERN_C() +void SAL_CALL rtl_alloc_preInit (rtl_alloc_preInit_phase_t phase) SAL_THROW_EXTERN_C() { - if (start) + switch (phase) { - rtl_allocateString = pre_allocateStringFn; - rtl_freeString = pre_freeStringFn; - pre_arena = rtl_arena_create("pre-init strings", 4, 0, - nullptr, rtl_arena_alloc, - rtl_arena_free, 0); - } - else // back to normal - { - rtl_arena_foreach(pre_arena, mark_static, nullptr); - rtl_allocateString = rtl_allocateMemory; - rtl_freeString = rtl_freeMemory; - - // TODO: also re-initialize main allocator as well. + case rtlAllocPreInitStart: + { + rtl_allocateString = pre_allocateStringFn; + rtl_freeString = pre_freeStringFn; + pre_arena = rtl_arena_create("pre-init strings", 4, 0, + nullptr, rtl_arena_alloc, + rtl_arena_free, 0); + + // To be consistent (and to ensure the rtl_cache threads are started). + ensureCacheSingleton(); + } + break; + + case rtlAllocPreInitEnd: + // back to normal + { + rtl_arena_foreach(pre_arena, mark_static, nullptr); + rtl_allocateString = rtl_allocateMemory; + rtl_freeString = rtl_freeMemory; + + // Stop the rtl cache thread to have no extra threads while forking. + rtl_cache_stop_threads(); + + // TODO: also re-initialize main allocator as well. + } + break; + + case rtlAllocPostInit: + { + // We have forked and need to restart threads and anything + // that must start after forking. + rtl_cache_start_threads(); + } + break; } } - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |