Kaydet (Commit) 123c7b80 authored tarafından Tor Lillqvist's avatar Tor Lillqvist

tdf#125397: Fixes for threads and SolarMutex on iOS

We need to call SfxApplication::GetOrCreate() in lo_initialize() now.
Otherwise we will crash in sfx2. No idea why it worked earlier.

I think we want to avoid the "VCLXToolkit VCL main thread" ever
running in the iOS app. I don't think we had it running earlier, but
now for some reason it got started when creating a document from a
template, and that seemed to cause a hang.

Also, when creating a document from a template, lo_initialize() is
called from the app's real main thread (the one that the process
starts in). In that case we do want to release the SolarMutex after
InitVCL() if this was the first time we called InitVCL(). Awful crack.

Not really sure I fully understand all that is going on, but this
change does seem to fix recent problems... All this thread and
SolarMutex stuff is so incredibly fragile.

Change-Id: Ib04498ad199b64f27701f89d2df7003bca316406
üst b26b6cab
......@@ -96,6 +96,7 @@
#include <editeng/fontitem.hxx>
#include <editeng/flstitem.hxx>
#include <sfx2/app.hxx>
#include <sfx2/objsh.hxx>
#include <sfx2/viewsh.hxx>
#include <sfx2/viewfrm.hxx>
......@@ -4598,7 +4599,6 @@ static void lo_runLoop(LibreOfficeKit* /*pThis*/,
void* pData)
{
#ifdef IOS // Maybe ANDROID, too?
InitVCL();
Application::GetSolarMutex().acquire();
#endif
......@@ -4922,6 +4922,19 @@ static int lo_initialize(LibreOfficeKit* pThis, const char* pAppPath, const char
// CommandLineArgs):
desktop::Desktop::GetCommandLineArgs().setHeadless();
#ifdef IOS
if (InitVCL() && [NSThread isMainThread])
{
static bool bFirstTime = true;
if (bFirstTime)
{
Application::GetSolarMutex().release();
bFirstTime = false;
}
}
SfxApplication::GetOrCreate();
#endif
if (eStage == PRE_INIT)
{
{
......
......@@ -835,6 +835,8 @@ bool lcl_convertMessageBoxType(
return ( eVal != css::awt::MessageBoxType::MessageBoxType_MAKE_FIXED_SIZE );
}
#ifndef IOS
static sal_Int32 nVCLToolkitInstanceCount = 0;
static bool bInitedByVCLToolkit = false;
......@@ -905,6 +907,8 @@ static void ToolkitWorkerFunction( void* pArgs )
}
}
#endif
// constructor, which might initialize VCL
VCLXToolkit::VCLXToolkit():
cppu::WeakComponentImplHelper<
......@@ -922,6 +926,7 @@ VCLXToolkit::VCLXToolkit():
hSvToolsLib = nullptr;
fnSvtCreateWindow = nullptr;
#ifndef IOS
osl::Guard< osl::Mutex > aGuard( getInitMutex() );
nVCLToolkitInstanceCount++;
if( ( nVCLToolkitInstanceCount == 1 ) && ( !Application::IsInMain() ) )
......@@ -930,6 +935,7 @@ VCLXToolkit::VCLXToolkit():
CreateMainLoopThread( ToolkitWorkerFunction, this );
getInitCondition().wait();
}
#endif
}
void SAL_CALL VCLXToolkit::disposing()
......@@ -943,6 +949,7 @@ void SAL_CALL VCLXToolkit::disposing()
}
#endif
#ifndef IOS
{
osl::Guard< osl::Mutex > aGuard( getInitMutex() );
if( --nVCLToolkitInstanceCount == 0 )
......@@ -955,7 +962,7 @@ void SAL_CALL VCLXToolkit::disposing()
}
}
}
#endif
if (m_bEventListener)
{
::Application::RemoveEventListener(m_aEventListenerLink);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment