diff --git a/config_host.mk.in b/config_host.mk.in index 15b82b07ffb2..d759bc2d9ce5 100644 --- a/config_host.mk.in +++ b/config_host.mk.in @@ -176,6 +176,7 @@ ENABLE_DOTNET=@ENABLE_DOTNET@ SYSTEM_DRAGONBOX=@SYSTEM_DRAGONBOX@ SYSTEM_FROZEN=@SYSTEM_FROZEN@ export ENABLE_EMSCRIPTEN_PROXY_POSIX_SOCKETS=@ENABLE_EMSCRIPTEN_PROXY_POSIX_SOCKETS@ +export ENABLE_EMSCRIPTEN_PROXY_TO_PTHREAD=@ENABLE_EMSCRIPTEN_PROXY_TO_PTHREAD@ export ENABLE_EPOXY=@ENABLE_EPOXY@ export ENABLE_EOT=@ENABLE_EOT@ export ENABLE_EVOAB2=@ENABLE_EVOAB2@ diff --git a/config_host/config_emscripten.h.in b/config_host/config_emscripten.h.in index 24d1a9ca5dd8..d8121613a934 100644 --- a/config_host/config_emscripten.h.in +++ b/config_host/config_emscripten.h.in @@ -11,4 +11,6 @@ #define HAVE_EMSCRIPTEN_PROXY_POSIX_SOCKETS 0 +#define HAVE_EMSCRIPTEN_PROXY_TO_PTHREAD 0 + /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/configure.ac b/configure.ac index 026e81caeb85..dd2954a283b8 100644 --- a/configure.ac +++ b/configure.ac @@ -2167,6 +2167,15 @@ AC_ARG_WITH(main-module, Default value is 'writer'.]), ,) +if test "$_os" = Emscripten; then + AC_ARG_ENABLE(emscripten-proxy-to-pthread, + AS_HELP_STRING([--disable-emscripten-proxy-to-pthread], + [Experimentally disable use of the Emscripten -sPROXY_TO_PTHREAD feature.]),, + enable_emscripten_proxy_to_pthread=yes) +else + enable_emscripten_proxy_to_pthread= +fi + if test "$_os" = Emscripten; then AC_ARG_ENABLE(emscripten-proxy-posix-sockets, AS_HELP_STRING([--enable-emscripten-proxy-posix-sockets], @@ -4177,6 +4186,14 @@ AC_SUBST(ENABLE_WASM_STRIP) AC_SUBST(ENABLE_WASM_STRIP_WRITER) AC_SUBST(ENABLE_WASM_STRIP_CALC) +if test "$enable_emscripten_proxy_to_pthread" = yes; then + ENABLE_EMSCRIPTEN_PROXY_TO_PTHREAD=TRUE + AC_DEFINE(HAVE_EMSCRIPTEN_PROXY_TO_PTHREAD) +else + ENABLE_EMSCRIPTEN_PROXY_TO_PTHREAD= +fi +AC_SUBST(ENABLE_EMSCRIPTEN_PROXY_TO_PTHREAD) + if test "$enable_emscripten_proxy_posix_sockets" = yes; then ENABLE_EMSCRIPTEN_PROXY_POSIX_SOCKETS=TRUE AC_DEFINE(HAVE_EMSCRIPTEN_PROXY_POSIX_SOCKETS) diff --git a/desktop/Executable_soffice_bin.mk b/desktop/Executable_soffice_bin.mk index fcf16e041fb9..a791e8f362e4 100644 --- a/desktop/Executable_soffice_bin.mk +++ b/desktop/Executable_soffice_bin.mk @@ -63,8 +63,10 @@ $(call gb_Executable_get_linktarget_target,soffice_bin): \ $(eval $(call gb_Executable_add_ldflags,soffice_bin,\ -s EXPORTED_FUNCTIONS=@$(gb_CustomTarget_workdir)/desktop/soffice_bin-emscripten-exports/exports -Wl$(COMMA)--whole-archive $(call gb_StaticLibrary_get_target,unoembind) -Wl$(COMMA)--no-whole-archive \ - -sPROXY_TO_PTHREAD=1 \ - $(if $(DISABLE_GUI),,-sOFFSCREENCANVAS_SUPPORT=1 -sOFFSCREENCANVASES_TO_PTHREAD=\#qtcanvas) \ + $(if $(ENABLE_EMSCRIPTEN_PROXY_TO_PTHREAD), \ + -sPROXY_TO_PTHREAD=1 \ + $(if $(DISABLE_GUI),, \ + -sOFFSCREENCANVAS_SUPPORT=1 -sOFFSCREENCANVASES_TO_PTHREAD=\#qtcanvas)) \ )) ifeq ($(ENABLE_QT6),TRUE) $(eval $(call gb_Executable_add_ldflags,soffice_bin, \ diff --git a/desktop/source/app/appinit.cxx b/desktop/source/app/appinit.cxx index 16f023b0a414..6c7637f32f9e 100644 --- a/desktop/source/app/appinit.cxx +++ b/desktop/source/app/appinit.cxx @@ -54,6 +54,7 @@ #include #include #include +#include #endif using namespace ::com::sun::star::uno; @@ -94,12 +95,20 @@ EM_JS(void, setupMainChannel, (), { }); extern "C" void resolveUnoMain(pthread_t id) { +#if HAVE_EMSCRIPTEN_PROXY_TO_PTHREAD EM_ASM({ const sofficeMain = PThread.pthreads[$0]; const channel = new MessageChannel(); sofficeMain.postMessage({cmd:"LOWA-channel"}, [channel.port2]); Module.uno_main$resolve(channel.port1); }, id); +#else + EM_ASM({ + const channel = new MessageChannel(); + postMessage({cmd:"LOWA-channel"}, [channel.port2]); + Module.uno_main$resolve(channel.port1); + }, id); +#endif } void initUno() { diff --git a/solenv/gbuild/platform/EMSCRIPTEN_INTEL_GCC.mk b/solenv/gbuild/platform/EMSCRIPTEN_INTEL_GCC.mk index 2b55b4ba1218..4951bb1cae03 100644 --- a/solenv/gbuild/platform/EMSCRIPTEN_INTEL_GCC.mk +++ b/solenv/gbuild/platform/EMSCRIPTEN_INTEL_GCC.mk @@ -17,6 +17,10 @@ gb_EMSCRIPTEN_LDFLAGS := $(gb_EMSCRIPTEN_CPPFLAGS) # Initial memory size gb_EMSCRIPTEN_LDFLAGS += -s TOTAL_MEMORY=1GB +ifeq ($(ENABLE_EMSCRIPTEN_PROXY_TO_PTHREAD),) +gb_EMSCRIPTEN_LDFLAGS += -sPTHREAD_POOL_SIZE=6 +endif + # Double the main thread stack size, but keep the default value for other threads: gb_EMSCRIPTEN_LDFLAGS += -sSTACK_SIZE=131072 -sDEFAULT_PTHREAD_STACK_SIZE=65536