You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openoffice.apache.org by ji...@apache.org on 2020/12/01 22:00:45 UTC

[openoffice] branch AOO42X updated: Huge updates to macOS UNO bridges, based on FreeBSD and Linux.

This is an automated email from the ASF dual-hosted git repository.

jim pushed a commit to branch AOO42X
in repository https://gitbox.apache.org/repos/asf/openoffice.git


The following commit(s) were added to refs/heads/AOO42X by this push:
     new 37f4cb1  Huge updates to macOS UNO bridges, based on FreeBSD and Linux.
37f4cb1 is described below

commit 37f4cb171557a563bb797a6166dd60f907b367f2
Author: Jim Jagielski <ji...@gmail.com>
AuthorDate: Tue Dec 1 16:59:54 2020 -0500

    Huge updates to macOS UNO bridges, based on FreeBSD and Linux.
---
 .../inc/bridges/cpp_uno/shared/vtablefactory.hxx   |   2 +-
 .../source/cpp_uno/gcc3_freebsd_x86-64/except.cxx  |   2 +-
 .../source/cpp_uno/s5abi_macosx_x86-64/call.s      | 120 +++++++++++++++++++++
 .../source/cpp_uno/s5abi_macosx_x86-64/cpp2uno.cxx |  68 ++----------
 .../source/cpp_uno/s5abi_macosx_x86-64/except.cxx  |   9 +-
 .../source/cpp_uno/s5abi_macosx_x86-64/makefile.mk |   6 +-
 .../source/cpp_uno/s5abi_macosx_x86-64/share.hxx   |   8 +-
 .../source/cpp_uno/s5abi_macosx_x86-64/uno2cpp.cxx |   5 +-
 main/bridges/source/cpp_uno/shared/component.cxx   |  44 +++-----
 .../source/cpp_uno/shared/vtablefactory.cxx        |   8 +-
 main/vcl/aqua/source/app/salinst.cxx               |  10 +-
 11 files changed, 169 insertions(+), 113 deletions(-)

diff --git a/main/bridges/inc/bridges/cpp_uno/shared/vtablefactory.hxx b/main/bridges/inc/bridges/cpp_uno/shared/vtablefactory.hxx
index 3fe88e5..dc15fb5 100644
--- a/main/bridges/inc/bridges/cpp_uno/shared/vtablefactory.hxx
+++ b/main/bridges/inc/bridges/cpp_uno/shared/vtablefactory.hxx
@@ -33,7 +33,7 @@
 #include <hash_map>
 
 /*See: http://people.redhat.com/drepper/selinux-mem.html*/
-#if defined (LINUX) || defined (FREEBSD)
+#if defined (LINUX) || defined (FREEBSD) || defined(MACOSX)
 #define USE_DOUBLE_MMAP
 #endif
 
diff --git a/main/bridges/source/cpp_uno/gcc3_freebsd_x86-64/except.cxx b/main/bridges/source/cpp_uno/gcc3_freebsd_x86-64/except.cxx
index 7902bd9..bfe18db 100644
--- a/main/bridges/source/cpp_uno/gcc3_freebsd_x86-64/except.cxx
+++ b/main/bridges/source/cpp_uno/gcc3_freebsd_x86-64/except.cxx
@@ -187,7 +187,7 @@ type_info * RTTI::getRTTI( typelib_CompoundTypeDescription *pTypeDescr ) SAL_THR
                     type_info * base_rtti = getRTTI(
                         (typelib_CompoundTypeDescription *)pTypeDescr->pBaseTypeDescription );
                     rtti = new __si_class_type_info(
-                        strdup( rttiName ), static_cast<__class_type_info *>(base_rtti) );
+                        strdup( rttiName ), (__class_type_info *)base_rtti );
                 }
                 else
                 {
diff --git a/main/bridges/source/cpp_uno/s5abi_macosx_x86-64/call.s b/main/bridges/source/cpp_uno/s5abi_macosx_x86-64/call.s
new file mode 100644
index 0000000..4801a94
--- /dev/null
+++ b/main/bridges/source/cpp_uno/s5abi_macosx_x86-64/call.s
@@ -0,0 +1,120 @@
+/**************************************************************
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ *************************************************************/
+
+	.text
+	.align 2
+.globl privateSnippetExecutor
+	.type	privateSnippetExecutor, @function
+privateSnippetExecutor:
+.LFB3:
+	pushq	%rbp
+.LCFI0:
+	movq	%rsp, %rbp
+.LCFI1:
+	subq	$160, %rsp
+.LCFI2:
+	movq	%r10, -152(%rbp)		# Save (nVtableOffset << 32) + nFunctionIndex
+
+	movq	%rdi, -112(%rbp)		# Save GP registers
+	movq	%rsi, -104(%rbp)
+	movq	%rdx, -96(%rbp)
+	movq	%rcx, -88(%rbp)
+	movq	%r8 , -80(%rbp)
+	movq	%r9 , -72(%rbp)
+	
+	movsd	%xmm0, -64(%rbp)		# Save FP registers
+	movsd	%xmm1, -56(%rbp)
+	movsd	%xmm2, -48(%rbp)
+	movsd	%xmm3, -40(%rbp)
+	movsd	%xmm4, -32(%rbp)
+	movsd	%xmm5, -24(%rbp)
+	movsd	%xmm6, -16(%rbp)
+	movsd	%xmm7, -8(%rbp)
+
+	leaq	-144(%rbp), %r9			# 6th param: sal_uInt64 * pRegisterReturn
+	leaq	16(%rbp), %r8			# 5rd param: void ** ovrflw
+	leaq	-64(%rbp), %rcx			# 4th param: void ** fpreg
+	leaq	-112(%rbp), %rdx		# 3rd param: void ** gpreg
+	movl	-148(%rbp), %esi		# 2nd param: sal_int32 nVtableOffset
+	movl	-152(%rbp), %edi		# 1st param: sal_int32 nFunctionIndex
+	
+	call	cpp_vtable_call
+
+	cmp	$10, %rax					# typelib_TypeClass_FLOAT
+	je	.Lfloat
+	cmp	$11, %rax					# typelib_TypeClass_DOUBLE
+	je	.Lfloat
+
+	movq	-144(%rbp), %rax		# Return value (int case)
+	movq	-136(%rbp), %rdx		# Return value (int case)
+	movq	-144(%rbp), %xmm0		# Return value (int case)
+	movq	-136(%rbp), %xmm1		# Return value (int case)
+	jmp	.Lfinish
+.Lfloat:
+	movlpd	-144(%rbp), %xmm0		# Return value (float/double case)
+
+.Lfinish:
+	leave
+	ret
+.LFE3:
+	.size	privateSnippetExecutor, .-privateSnippetExecutor
+	# see http://refspecs.linuxfoundation.org/LSB_3.0.0/LSB-Core-generic/LSB-Core-generic/ehframechpt.html
+	# for details of the .eh_frame, the "Common Information Entry" and "Frame Description Entry" formats
+	# and http://mentorembedded.github.io/cxx-abi/exceptions.pdf for more info
+	.section	.eh_frame,"a",@progbits
+.Lframe1:
+	.long	.LECIE1-.LSCIE1
+.LSCIE1:
+	.long	0x0
+	.byte	0x1
+	.string	"zR"
+	.uleb128 0x1
+	.sleb128 -8
+	.byte	0x10
+	.uleb128 0x1
+	.byte	0x1b
+	.byte	0xc
+	.uleb128 0x7
+	.uleb128 0x8
+	.byte	0x90
+	.uleb128 0x1
+	.align 8
+.LECIE1:
+.LSFDE1:
+	.long	.LEFDE1-.LASFDE1
+.LASFDE1:
+	.long	.LASFDE1-.Lframe1
+	.long	.LFB3-.
+	.long	.LFE3-.LFB3
+	.uleb128 0x0
+	.byte	0x4
+	.long	.LCFI0-.LFB3
+	.byte	0xe
+	.uleb128 0x10
+	.byte	0x86
+	.uleb128 0x2
+	.byte	0x4
+	.long	.LCFI1-.LCFI0
+	.byte	0xd
+	.uleb128 0x6
+	.align 8
+.LEFDE1:
+	.section	.note.GNU-stack,"",@progbits
diff --git a/main/bridges/source/cpp_uno/s5abi_macosx_x86-64/cpp2uno.cxx b/main/bridges/source/cpp_uno/s5abi_macosx_x86-64/cpp2uno.cxx
index 18d81dc..9c20b7a 100644
--- a/main/bridges/source/cpp_uno/s5abi_macosx_x86-64/cpp2uno.cxx
+++ b/main/bridges/source/cpp_uno/s5abi_macosx_x86-64/cpp2uno.cxx
@@ -395,70 +395,17 @@ extern "C" typelib_TypeClass cpp_vtable_call(
 }
 
 //==================================================================================================
+extern "C" void privateSnippetExecutor( ... );
 
-// privateSnippetExecutor() is only called by the trampolines created by codeSnippet()
-//
-// it saves all the registers used for parameter passing in the x86_64 ABI.
-// Then it uses them to provide the parameters to its cpp_vtable_call() and
-// to handle the return value.
-//
-// This method makes assumptions about the stack layout of the stack frame above!
-
-extern "C" void privateSnippetExecutor( void )
-{
-    asm volatile (
-	"subq	$160, %%rsp\n\t"
-	"movq	%%r10, -152(%%rbp)\n\t"		// Save (nVtableOffset << 32) + nFunctionIndex
-
-	"movq	%%rdi, -112(%%rbp)\n\t"		// Save GP registers
-	"movq	%%rsi, -104(%%rbp)\n\t"
-	"movq	%%rdx, -96(%%rbp)\n\t"
-	"movq	%%rcx, -88(%%rbp)\n\t"
-	"movq	%%r8 , -80(%%rbp)\n\t"
-	"movq	%%r9 , -72(%%rbp)\n\t"
-	
-	"movsd	%%xmm0, -64(%%rbp)\n\t"		// Save FP registers
-	"movsd	%%xmm1, -56(%%rbp)\n\t"
-	"movsd	%%xmm2, -48(%%rbp)\n\t"
-	"movsd	%%xmm3, -40(%%rbp)\n\t"
-	"movsd	%%xmm4, -32(%%rbp)\n\t"
-	"movsd	%%xmm5, -24(%%rbp)\n\t"
-	"movsd	%%xmm6, -16(%%rbp)\n\t"
-	"movsd	%%xmm7, -8(%%rbp)\n\t"
-
-	"leaq	-144(%%rbp), %%r9\n\t"		// 6th param: sal_uInt64* pRegisterReturn
-	"leaq	16(%%rbp), %%r8\n\t"		// 5rd param: void** ovrflw
-	"leaq	-64(%%rbp), %%rcx\n\t"		// 4th param: void** fpreg
-	"leaq	-112(%%rbp), %%rdx\n\t"		// 3rd param: void** gpreg
-	"movl	-148(%%rbp), %%esi\n\t"		// 2nd param: sal_int32 nVtableOffset
-	"movl	-152(%%rbp), %%edi\n\t"		// 1st param: sal_int32 nFunctionIndex
-	
-	"call	_cpp_vtable_call\n\t"
-
-	"cmp	$10, %%rax\n\t"				// typelib_TypeClass_FLOAT
-	"je	.Lfloat\n\t"
-	"cmp	$11, %%rax\n\t"				// typelib_TypeClass_DOUBLE
-	"je	.Lfloat\n\t"
-
-	"movq	-144(%%rbp), %%rax\n\t"		// Return value (int case)
-	"movq	-136(%%rbp), %%rdx\n\t"		// Return value (int case)
-	"movq	-144(%%rbp), %%xmm0\n\t"	// Return value (int case)
-	"movq	-136(%%rbp), %%xmm1\n\t"	// Return value (int case)
-	"jmp	.Lfinish\n"
-".Lfloat:\n\t"
-	"movlpd	-144(%%rbp), %%xmm0\n"		// Return value (float/double case)
-".Lfinish:\n\t"
-	"addq	$160, %%rsp\n"
-	:
-	: 
-	: "rax", "r10", "xmm0" );
-}
-
-static const int codeSnippetSize = 24;
+const int codeSnippetSize = 24;
 
 // Generate a trampoline that redirects method calls to
 // privateSnippetExecutor().
 //
+// privateSnippetExecutor() saves all the registers that are used for
+// parameter passing on x86_64, and calls the cpp_vtable_call().
+// When it returns, privateSnippetExecutor() sets the return value.
+//
 // Note: The code snippet we build here must not create a stack frame,
 // otherwise the UNO exceptions stop working thanks to non-existing
 // unwinding info.
@@ -515,11 +462,10 @@ bridges::cpp_uno::shared::VtableFactory::initializeBlock(
 //==================================================================================================
 
 unsigned char * bridges::cpp_uno::shared::VtableFactory::addLocalFunctions(
-	Slot ** slots, unsigned char * code, /*sal_PtrDiff writetoexecdiff,*/
+	Slot ** slots, unsigned char * code, sal_PtrDiff writetoexecdiff,
 	typelib_InterfaceTypeDescription const * type, sal_Int32 nFunctionOffset,
 	sal_Int32 functionCount, sal_Int32 nVtableOffset )
 {
-	static const sal_PtrDiff writetoexecdiff = 0;
 	(*slots) -= functionCount;
 	Slot * s = *slots;
 	for ( sal_Int32 nPos = 0; nPos < type->nMembers; ++nPos )
diff --git a/main/bridges/source/cpp_uno/s5abi_macosx_x86-64/except.cxx b/main/bridges/source/cpp_uno/s5abi_macosx_x86-64/except.cxx
index f9a11ef..0d64e70 100644
--- a/main/bridges/source/cpp_uno/s5abi_macosx_x86-64/except.cxx
+++ b/main/bridges/source/cpp_uno/s5abi_macosx_x86-64/except.cxx
@@ -141,7 +141,7 @@ type_info * RTTI::getRTTI( typelib_CompoundTypeDescription *pTypeDescr ) SAL_THR
     t_rtti_map::const_iterator iFind( m_rttis.find( unoName ) );
     if (iFind == m_rttis.end())
     {
-        // build the mangled name for unoName's RTTI typeinfo symbol
+        // RTTI symbol
         OStringBuffer buf( 64 );
         buf.append( RTL_CONSTASCII_STRINGPARAM("_ZTIN") );
         sal_Int32 index = 0;
@@ -174,7 +174,7 @@ type_info * RTTI::getRTTI( typelib_CompoundTypeDescription *pTypeDescr ) SAL_THR
                 // symbol and rtti-name is nearly identical,
                 // the symbol is prefixed with _ZTI
                 char const * rttiName = symName.getStr() +4;
-#if OSL_DEBUG_LEVEL >= 1
+#if OSL_DEBUG_LEVEL > 1
                 fprintf( stderr,"generated rtti for %s\n", rttiName );
                 const OString aCUnoName = OUStringToOString( unoName, RTL_TEXTENCODING_UTF8);
                 OSL_TRACE( "TypeInfo for \"%s\" not found and cannot be generated.\n", aCUnoName.getStr());
@@ -200,8 +200,9 @@ type_info * RTTI::getRTTI( typelib_CompoundTypeDescription *pTypeDescr ) SAL_THR
                 rtti = NULL;
 #endif
 
-                bool bOK = m_generatedRttis.insert( t_rtti_map::value_type( unoName, rtti )).second;
-                OSL_ENSURE( bOK, "### inserting new generated rtti failed?!" );
+                pair< t_rtti_map::iterator, bool > insertion(
+                    m_generatedRttis.insert( t_rtti_map::value_type( unoName, rtti ) ) );
+                OSL_ENSURE( insertion.second, "### inserting new generated rtti failed?!" );
             }
             else // taking already generated rtti
             {
diff --git a/main/bridges/source/cpp_uno/s5abi_macosx_x86-64/makefile.mk b/main/bridges/source/cpp_uno/s5abi_macosx_x86-64/makefile.mk
index 7f92ad1..7f64991 100644
--- a/main/bridges/source/cpp_uno/s5abi_macosx_x86-64/makefile.mk
+++ b/main/bridges/source/cpp_uno/s5abi_macosx_x86-64/makefile.mk
@@ -48,7 +48,8 @@ SLOFILES= \
 	$(SLO)$/abi.obj			\
 	$(SLO)$/except.obj		\
 	$(SLO)$/cpp2uno.obj		\
-	$(SLO)$/uno2cpp.obj
+	$(SLO)$/uno2cpp.obj		\
+	$(SLO)$/call.obj
 
 SHL1TARGET= $(TARGET)
 
@@ -70,3 +71,6 @@ SHL1STDLIBS= \
 
 .INCLUDE :  target.mk
 
+$(SLO)$/%.obj: %.s
+    $(CC) -c -o $(SLO)$/$(@:b).o $<
+    touch $@
diff --git a/main/bridges/source/cpp_uno/s5abi_macosx_x86-64/share.hxx b/main/bridges/source/cpp_uno/s5abi_macosx_x86-64/share.hxx
index b64609d..c3c84d6 100644
--- a/main/bridges/source/cpp_uno/s5abi_macosx_x86-64/share.hxx
+++ b/main/bridges/source/cpp_uno/s5abi_macosx_x86-64/share.hxx
@@ -36,11 +36,11 @@ void dummy_can_throw_anything( char const * );
 
 struct _Unwind_Exception
 {
-    unsigned long exception_class;
+    unsigned exception_class __attribute__((__mode__(__DI__)));
     void * exception_cleanup;
-    uintptr_t private_1;
-    uintptr_t private_2;
-};
+    unsigned private_1 __attribute__((__mode__(__word__)));
+    unsigned private_2 __attribute__((__mode__(__word__)));
+} __attribute__((__aligned__));
 
 struct __cxa_exception
 { 
diff --git a/main/bridges/source/cpp_uno/s5abi_macosx_x86-64/uno2cpp.cxx b/main/bridges/source/cpp_uno/s5abi_macosx_x86-64/uno2cpp.cxx
index 6d7d581..a58791c 100644
--- a/main/bridges/source/cpp_uno/s5abi_macosx_x86-64/uno2cpp.cxx
+++ b/main/bridges/source/cpp_uno/s5abi_macosx_x86-64/uno2cpp.cxx
@@ -149,9 +149,8 @@ static void callVirtualMethod(void * pThis, sal_uInt32 nVtableIndex,
         :
         : "m" ( pMethod ), "m" ( pGPR ), "m" ( pFPR ), "m" ( nFPR ),
           "m" ( rax ), "m" ( rdx ), "m" ( xmm0 ), "m" ( xmm1 ),
-          "m" (pCallStack) // dummy input to prevent the compiler from optimizing it out
-        : "rax", "rbx", "rcx", "rdx", "rdi", "rsi", "r8", "r9",
-          "r10", "r11", "r10", "r12", "r13", "r14", "r15", "rbx",
+          "m" (pCallStack) // dummy input to prevent the compiler from optimizing the alloca out
+        : "rax", "rdi", "rsi", "rdx", "rcx", "r8", "r9", "r11",
           "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7"
     );
 
diff --git a/main/bridges/source/cpp_uno/shared/component.cxx b/main/bridges/source/cpp_uno/shared/component.cxx
index dfa5a8d..da729d4 100644
--- a/main/bridges/source/cpp_uno/shared/component.cxx
+++ b/main/bridges/source/cpp_uno/shared/component.cxx
@@ -53,42 +53,22 @@ rtl_StandardModuleCount g_moduleCount = MODULE_COUNT_INIT;
 
 namespace {
 
-#if (defined(__SUNPRO_CC) && (__SUNPRO_CC == 0x500)) \
-    || (defined(__GNUC__) && defined(__APPLE__))
-static ::rtl::OUString * s_pStaticOidPart = 0;
-#endif
-
 const ::rtl::OUString & SAL_CALL cppu_cppenv_getStaticOIdPart() SAL_THROW( () )
 {
-#if ! ((defined(__SUNPRO_CC) && (__SUNPRO_CC == 0x500)) \
-    || (defined(__GNUC__) && defined(__APPLE__)))
-    static ::rtl::OUString * s_pStaticOidPart = 0;
-#endif
-    if (! s_pStaticOidPart)
-    {
-        ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
-        if (! s_pStaticOidPart)
+    static ::rtl::OUString s_aStaticOidPart = []() {
+        ::rtl::OUStringBuffer aRet( 64 );
+        aRet.appendAscii( RTL_CONSTASCII_STRINGPARAM("];") );
+        // good guid
+        sal_uInt8 ar[16];
+        ::rtl_getGlobalProcessId(ar);
+        for ( sal_Int32 i = 0; i < 16; ++i )
         {
-            ::rtl::OUStringBuffer aRet( 64 );
-            aRet.appendAscii( RTL_CONSTASCII_STRINGPARAM("];") );
-            // good guid
-            sal_uInt8 ar[16];
-            ::rtl_getGlobalProcessId( ar );
-            for ( sal_Int32 i = 0; i < 16; ++i )
-            {
-                aRet.append( (sal_Int32)ar[i], 16 );
-            }
-#if (defined(__SUNPRO_CC) && (__SUNPRO_CC == 0x500)) \
-    || (defined(__GNUC__) && defined(__APPLE__))
-            s_pStaticOidPart = new ::rtl::OUString( aRet.makeStringAndClear() );
-#else
-            static ::rtl::OUString s_aStaticOidPart(
-                aRet.makeStringAndClear() );
-            s_pStaticOidPart = &s_aStaticOidPart;
-#endif
+            aRet.append( (sal_Int32)ar[i], 16 );
         }
-    }
-    return *s_pStaticOidPart;
+        return aRet.makeStringAndClear();
+    }();
+    return s_aStaticOidPart;
+
 }
 
 }
diff --git a/main/bridges/source/cpp_uno/shared/vtablefactory.cxx b/main/bridges/source/cpp_uno/shared/vtablefactory.cxx
index f4d6c56..35bad98 100644
--- a/main/bridges/source/cpp_uno/shared/vtablefactory.cxx
+++ b/main/bridges/source/cpp_uno/shared/vtablefactory.cxx
@@ -96,6 +96,11 @@ extern "C" void * SAL_CALL allocExec(rtl_arena_type *, sal_Size * size) {
     sal_Size n = (*size + (pagesize - 1)) & ~(pagesize - 1);
     void * p;
 #if defined SAL_UNX
+#if defined MACOSX
+    p = mmap(
+        0, n, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANON | MAP_JIT, -1,
+        0);
+#else
     p = mmap(
         0, n, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1,
         0);
@@ -107,6 +112,7 @@ extern "C" void * SAL_CALL allocExec(rtl_arena_type *, sal_Size * size) {
 		munmap (static_cast<char*>(p), n);
 		p = 0;
 	}
+#endif
 #elif defined SAL_W32
     p = VirtualAlloc(0, n, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
 #elif defined(SAL_OS2)
@@ -195,7 +201,7 @@ VtableFactory::VtableFactory(): m_arena(
     rtl_arena_create(
         "bridges::cpp_uno::shared::VtableFactory",
         sizeof (void *), // to satisfy alignment requirements
-        0, reinterpret_cast< rtl_arena_type * >(-1), allocExec, freeExec, 0))
+        0, reinterpret_cast< rtl_arena_type * >( 0 ), allocExec, freeExec, 0))
 {
     if (m_arena == 0) {
         throw std::bad_alloc();
diff --git a/main/vcl/aqua/source/app/salinst.cxx b/main/vcl/aqua/source/app/salinst.cxx
index 66ff6af..8ba2d56 100644
--- a/main/vcl/aqua/source/app/salinst.cxx
+++ b/main/vcl/aqua/source/app/salinst.cxx
@@ -781,18 +781,18 @@ void AquaSalInstance::Yield( bool bWait, bool bHandleAllCurrentEvents )
         }
         osl_setCondition( maWaitingYieldCond );
     }
-    else if( bWait )
+    else if( bWait && maWaitingYieldCond )
     {
         // #i103162#
         // wait until any thread (most likely the main thread)
-        // has dispatched an event, cop out at 200 ms
+        // has dispatched an event, cop out at 500 ms
+        sal_uLong nCount;
+        TimeValue aVal = { 0, 500000000 };
         osl_resetCondition( maWaitingYieldCond );
-        TimeValue aVal = { 0, 200000000 };
-        sal_uLong nCount = ReleaseYieldMutex();
+        nCount = ReleaseYieldMutex();
         osl_waitCondition( maWaitingYieldCond, &aVal );
         AcquireYieldMutex( nCount );
     }
-    
 	// we get some apple events way too early
 	// before the application is ready to handle them,
 	// so their corresponding application events need to be delayed