Adapt comphelper::ThreadPool to Emscripten's threading needs

...by keeping the worker threads around by default instead of joining and later
re-spawning them; see 5b1df7709d "Document the
Emscripten threads issue".  But lets be cautious and change the bJoin default
only for Emscripten.

Also, cap the thread pool size to MAX_CONCURRENCY=4 and increase to
-sPTHREAD_POOL_SIZE=6.  In an experimental setup where the Emscripten build
starts up with the start center rather than a Writer document, that is just
enough to cover the thread-spawning needs when executing the start center
window's paint task:  Four threads for the comphelper::ThreadPool (used from
within drawinglayer::convertToBitmapEx -> ... ->
BitmapBasicMorphologyFilter::filter), and one each for
configmgr::Components::WriteThread (see e8358d0a0f
"Keep around a single configmgr::Components::WriteThread instance") and
salhelper::TimerManager.

Change-Id: I5b1d0e9dc09f05fb3b679c8dc1c38ee45c61c0f8
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/171004
Reviewed-by: Stephan Bergmann <stephan.bergmann@allotropia.de>
Tested-by: Jenkins
This commit is contained in:
Stephan Bergmann
2024-07-25 10:51:16 +02:00
parent 4b6390290f
commit b84ef4d67e
3 changed files with 9 additions and 2 deletions

View File

@@ -67,7 +67,13 @@ public:
/** Wait until all queued tasks associated with the tag are completed
@param bJoin - if set call joinThreadsIfIdle() at the end
*/
void waitUntilDone(const std::shared_ptr<ThreadTaskTag>&, bool bJoin = true);
void waitUntilDone(const std::shared_ptr<ThreadTaskTag>&, bool bJoin =
#if defined EMSCRIPTEN
false
#else
true
#endif
);
/// join all threads if there are no tasks presently.
void joinThreadsIfIdle();

View File

@@ -15,7 +15,7 @@ gb_EMSCRIPTEN_CPPFLAGS := -pthread -s USE_PTHREADS=1 -D_LARGEFILE64_SOURCE -D_LA
gb_EMSCRIPTEN_LDFLAGS := $(gb_EMSCRIPTEN_CPPFLAGS)
# Initial memory size and worker thread pool
gb_EMSCRIPTEN_LDFLAGS += -s TOTAL_MEMORY=1GB -s PTHREAD_POOL_SIZE=4
gb_EMSCRIPTEN_LDFLAGS += -s TOTAL_MEMORY=1GB -s PTHREAD_POOL_SIZE=6
# To keep the link time (and memory) down, prevent all rewriting options from wasm-emscripten-finalize
# See emscripten.py, finalize_wasm, modify_wasm = True

View File

@@ -2,5 +2,6 @@
if (!('preRun' in Module)) Module['preRun'] = [];
Module.preRun.push(function() {
ENV.MAX_CONCURRENCY = '4';
ENV.SAL_LOG = "+WARN"
});