summaryrefslogtreecommitdiff
path: root/sal
diff options
context:
space:
mode:
authorAshod Nakashian <ashod.nakashian@collabora.co.uk>2017-12-25 15:02:41 -0500
committerAndras Timar <andras.timar@collabora.com>2018-03-20 12:26:28 +0100
commite97590d3abd430d353cc692124bc41d0111e6cd4 (patch)
treebf86008bea23966759d1a25eb18c52b0dd227351 /sal
parent6fb9ccd212130c890f93e27cf3a3b0743b42f45d (diff)
rtl: support start/stop threads around pre-init
This is necessary to avoid having extra threads while forking. After forking, the second stage of pre-init is started and so we start the stopped rtl threads. The comment for rtl_alloc_preInit_phase_t has more details. Reviewed-on: https://gerrit.libreoffice.org/47060 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Ashod Nakashian <ashnakash@gmail.com> (cherry picked from commit 271a663d2f098f3f665cab6da2e13b265a7eab93) Change-Id: I1a3f7be74d4b04d0b2fc4a72b02124c2faa3c047
Diffstat (limited to 'sal')
-rw-r--r--sal/inc/rtllifecycle.h4
-rw-r--r--sal/qa/rtl/alloc/rtl_alloc.cxx4
-rw-r--r--sal/rtl/alloc_cache.cxx10
-rw-r--r--sal/rtl/strimp.cxx53
4 files changed, 53 insertions, 18 deletions
diff --git a/sal/inc/rtllifecycle.h b/sal/inc/rtllifecycle.h
index 82e38dee6372..528f4cc48a2f 100644
--- a/sal/inc/rtllifecycle.h
+++ b/sal/inc/rtllifecycle.h
@@ -26,6 +26,10 @@ void rtl_cache_fini(void);
void ensureCacheSingleton(void);
+void rtl_cache_stop_threads(void);
+
+void rtl_cache_start_threads(void);
+
void rtl_memory_init(void);
void rtl_memory_fini(void);
diff --git a/sal/qa/rtl/alloc/rtl_alloc.cxx b/sal/qa/rtl/alloc/rtl_alloc.cxx
index 0e9b7c0f47a8..37c7b41eb338 100644
--- a/sal/qa/rtl/alloc/rtl_alloc.cxx
+++ b/sal/qa/rtl/alloc/rtl_alloc.cxx
@@ -158,7 +158,7 @@ public:
const char *sample = "Hello World";
std::vector<OUString> aStrings;
- rtl_alloc_preInit(true);
+ rtl_alloc_preInit(rtlAllocPreInitStart);
OUString aFoo("foo");
@@ -183,7 +183,7 @@ public:
}
// should static-ize all the strings.
- rtl_alloc_preInit(false);
+ rtl_alloc_preInit(rtlAllocPreInitEnd);
for (size_t i = 0; i < aStrings.size(); ++i)
CPPUNIT_ASSERT_MESSAGE( "static after.", (aStrings[i].pData->refCount & SAL_STRING_STATIC_FLAG) );
diff --git a/sal/rtl/alloc_cache.cxx b/sal/rtl/alloc_cache.cxx
index 468bbdcdbf04..5ad8690e3152 100644
--- a/sal/rtl/alloc_cache.cxx
+++ b/sal/rtl/alloc_cache.cxx
@@ -1353,6 +1353,16 @@ rtl_cache_wsupdate_all(void * arg)
#endif
}
+void rtl_cache_stop_threads(void)
+{
+ rtl_cache_wsupdate_fini();
+}
+
+void rtl_cache_start_threads(void)
+{
+ rtl_cache_wsupdate_init();
+}
+
void rtl_cache_init()
{
{
diff --git a/sal/rtl/strimp.cxx b/sal/rtl/strimp.cxx
index a739bda8f155..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-intialize 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: */