summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrzej Hunt <andrzej.hunt@collabora.com>2014-07-18 10:02:48 +0200
committerAndrzej Hunt <andrzej@ahunt.org>2014-08-19 14:04:58 +0200
commit00c402ad68e4ec51027481bf32ed2f777a15383e (patch)
tree77080055216228e7e15aaa17b3b9dfbf0d3fe9fc
parent2478f38a79abf6942d0909c9eb1f5424915e03dd (diff)
Use OfficeIPCThread::WaitForReady rather than sleeping.
This way we actually continue when we're ready to, rather than dumbly hoping we wait for long enough. This isn't entirely unproblematic though -- if we have no config pre-prepared (i.e. first-run), then we just end up hanging on this since soffice_main exits without doing anything to the OfficeIPCThread. (Which is especially problematic for unit tests which specifically run on an empty config.) Change-Id: I064fb500a224cfe37a0d3ba24b6154ffd72a71a3
-rw-r--r--desktop/source/lib/init.cxx33
1 files changed, 20 insertions, 13 deletions
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index e2f3704e3f9f..05b23809d199 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -60,9 +60,11 @@
// We also need to hackily be able to start the main libreoffice thread
#include "../app/sofficemain.h"
+#include "../app/officeipcthread.hxx"
using namespace css;
using namespace vcl;
+using namespace desktop;
using namespace utl;
using namespace boost;
@@ -693,22 +695,27 @@ static int lo_initialize(LibreOfficeKit* pThis, const char* pAppPath)
// Force headless -- this is only for bitmap rendering.
rtl::Bootstrap::set("SAL_USE_VCLPLUGIN", "svp");
-// InitVCL();
- // InitVCL() happens in soffice_main for us -- and we can't call InitVCL twice
- // unfortunately -- which is annoying since (see below)
+ // We could use InitVCL() here -- and used to before using soffice_main,
+ // however that now deals with the initialisation for us (and it's not
+ // possible to try to set up VCL twice.
+
+ // Instead VCL init is done for us by soffice_main in a separate thread,
+ // however we specifically can't proceed until this setup is complete
+ // (or you get segfaults trying to use VCL and/or deadlocks due to other
+ // setup within soffice_main). Specifically the various Application::
+ // functions depend on VCL being ready -- the deadlocks would happen
+ // if you try to use loadDocument too early.
+
+ // The OfficeIPCThread is specifically set to be read when all the other
+ // init in Desktop::Main (run from soffice_main) is done. We can "enable"
+ // the Thread from wherever (it's done again in Desktop::Main), and can
+ // then use it to wait until we're definitely ready to continue.
+
+ OfficeIPCThread::EnableOfficeIPCThread();
pthread_t thread;
pthread_create(&thread, 0, lo_startmain, NULL);
- sleep(10);
- // We'll segfault trying to access Application if we're too fast...
- // Specifically pImplSVData doesn't exist until InitVCL has been called,
- // and that won't be immediate, but we can't call InitVCL ourselves
- // as soffice_main already does so, but InitVCL would then fail
- // within soffice_main if we have already called it earlier.
- //
- // And there's also a chance of deadlock if we try to open documents
- // too early -- when running in a debugger we therefore need quite
- // a large delay here (for now).
+ OfficeIPCThread::WaitForReady();
Application::EnableHeadlessMode(true);