summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrzej Hunt <andrzej.hunt@collabora.com>2014-07-18 10:02:48 +0200
committerAndrzej Hunt <andrzej.hunt@collabora.com>2014-07-18 10:02:48 +0200
commit6942d9b6ae3c3a8802fadf16feacd5984f55b273 (patch)
tree5bab1556ee7d15dda1879698ebb9fb588d730975
parent13c5fb87f76655e7aa05040a4c737843561d1f44 (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 0be5f8dd6cef..76d05f36f880 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -60,8 +60,10 @@
// 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 desktop;
using namespace utl;
using namespace boost;
@@ -637,22 +639,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);