[Libreoffice-commits] core.git: 2 commits - sal/osl vcl/README vcl/win winaccessibility/README winaccessibility/source

Michael Stahl mstahl at redhat.com
Thu Jan 9 04:48:08 PST 2014


 sal/osl/w32/file_error.c                 |   21 ---------------------
 sal/osl/w32/file_error.h                 |    8 --------
 sal/osl/w32/file_url.cxx                 |   26 ++++++++++++--------------
 sal/osl/w32/thread.c                     |    5 ++---
 vcl/README                               |    7 +++++++
 vcl/win/source/app/salinst.cxx           |    2 +-
 winaccessibility/README                  |   16 ++++++++++++++++
 winaccessibility/source/UAccCOM/stdafx.h |    4 +++-
 8 files changed, 41 insertions(+), 48 deletions(-)

New commits:
commit bcfd016c88f2da271fc77da608b42d2f5bd83448
Author: Michael Stahl <mstahl at redhat.com>
Date:   Tue Nov 26 12:58:31 2013 +0100

    some notes about COM threading in LO generally and winaccessibility
    
    - document general COM threading architecture in vcl README
    - document winaccessiblitiy locking in README
    - define _ATL_APARTMENT_THREADED for UAccCOM
    
    Change-Id: I7c3fd952f2cdee7d245a818bf33c477e7ea20fc2

diff --git a/sal/osl/w32/thread.c b/sal/osl/w32/thread.c
index 0bb7172..a5cf715 100644
--- a/sal/osl/w32/thread.c
+++ b/sal/osl/w32/thread.c
@@ -49,9 +49,8 @@ static unsigned __stdcall oslWorkerWrapperFunction(void* pData)
 {
     osl_TThreadImpl* pThreadImpl= (osl_TThreadImpl*)pData;
 
-    /* Initialize COM */
-
-    CoInitializeEx(NULL, COINIT_MULTITHREADED);
+    /* Initialize COM - Multi Threaded Apartment (MTA) for all threads */
+    CoInitializeEx(0, COINIT_MULTITHREADED); /* spawned by oslCreateThread */
 
     /* call worker-function with data */
 
diff --git a/vcl/README b/vcl/README
index bebb9e1..e4cc922 100644
--- a/vcl/README
+++ b/vcl/README
@@ -64,6 +64,13 @@ portable C++ class library for GUIs, with very old roots, that was
 developed by StarDivision. Nowadays it is not used by anything except
 LibreOffice (and OpenOffice).
 
+== COM threading ==
+
+The way COM is used in LO generally:
+- vcl InitSalData() puts main thread into Single-threaded Apartment (STA)
+- oslWorkerWrapperFunction() puts every thread spawned via oslCreateThread()
+  into MTA (free-threaded)
+
 == EMF+ ==
 
 emf+ is vector file format used by MSO and is successor of wmf and
diff --git a/vcl/win/source/app/salinst.cxx b/vcl/win/source/app/salinst.cxx
index 1c5e7e7..316c544 100644
--- a/vcl/win/source/app/salinst.cxx
+++ b/vcl/win/source/app/salinst.cxx
@@ -446,7 +446,7 @@ SalData::~SalData()
 void InitSalData()
 {
     SalData* pSalData = new SalData;
-    CoInitialize(0);
+    CoInitialize(0); // put main thread in Single Threaded Apartment (STA)
 
     // init GDIPlus
     static Gdiplus::GdiplusStartupInput gdiplusStartupInput;
diff --git a/winaccessibility/README b/winaccessibility/README
index eb425e4..bac3681 100644
--- a/winaccessibility/README
+++ b/winaccessibility/README
@@ -26,6 +26,22 @@ Here is one way of visualising the code / control flow
 VCL <-> UNO toolkit <-> UNO a11y <-> win a11y <-> COM / IAccessible2
 vcl/ <-> toolkit/ <-> accessibility/ <-> winaccessibility/ <-> UAccCom/
 
+Threading
+
+It's possible that the UNO components are called from threads other
+than the main thread, so they have to be synchronized. It would be nice
+to put the component into an UNO apartment (and the COM components into STA)
+but UNO would spawn a new thread for it so it's not possible.
+The COM components also call into the same global AccObjectWinManager
+as the UNO components do so both have to be synchronized in the same way.
+So we use the SolarMutex for all synchronization since anything else
+would be rather difficult to make work.  Unfortunately there is a
+pre-exising problem in vcl with Win32 Window creation and destruction
+on non-main threads where a synchronous SendMessage is used while
+the SolarMutex is locked that can cause deadlocks if the main thread is
+waiting on the SolarMutex itself at that time and thus not handing the
+Win32 message; this is easy to trigger with JunitTests but hopefully
+not by actual end users.
 
 Debugging / playing with winaccessibility
 
diff --git a/winaccessibility/source/UAccCOM/stdafx.h b/winaccessibility/source/UAccCOM/stdafx.h
index 66019e2..e71ac0b 100644
--- a/winaccessibility/source/UAccCOM/stdafx.h
+++ b/winaccessibility/source/UAccCOM/stdafx.h
@@ -28,7 +28,9 @@
 #pragma once
 #endif // _MSC_VER > 1000
 
-//#define _ATL_APARTMENT_THREADED
+// this turns off ATL's locking in the COM component implementations
+// (we don't need it since we use SolarMutex instead)
+#define _ATL_APARTMENT_THREADED
 
 #include <prewin.h>
 #include <windows.h>
commit 4eae9d19cce5356d536ae509861a5c95f65aea4a
Author: Michael Stahl <mstahl at redhat.com>
Date:   Thu Jan 9 13:15:32 2014 +0100

    sal: remove OSL_ENSURE_FILE, better use SAL_LOG/SAL_INFO
    
    Change-Id: I43d77cbf572acc4c27785990e28b43b35d71c96d

diff --git a/sal/osl/w32/file_error.c b/sal/osl/w32/file_error.c
index 3bb2e49..3697c9d 100644
--- a/sal/osl/w32/file_error.c
+++ b/sal/osl/w32/file_error.c
@@ -122,25 +122,4 @@ oslFileError oslTranslateFileError (/*DWORD*/ unsigned long dwError)
         return osl_File_E_INVAL;
 }
 
-//#####################################################
-#if OSL_DEBUG_LEVEL > 0
-void _osl_warnFile( const char *message, rtl_uString *ustrFile )
-{
-    char szBuffer[2048];
-
-    if (ustrFile)
-    {
-        rtl_String  *strFile = NULL;
-
-        rtl_uString2String( &strFile, rtl_uString_getStr( ustrFile ), rtl_uString_getLength( ustrFile ),
-                            osl_getThreadTextEncoding(), OUSTRING_TO_OSTRING_CVTFLAGS );
-        snprintf( szBuffer, sizeof(szBuffer), message, strFile->buffer );
-        rtl_string_release( strFile );
-
-        message = szBuffer;
-    }
-    OSL_FAIL( message );
-}
-#endif /* OSL_DEBUG_LEVEL */
-
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sal/osl/w32/file_error.h b/sal/osl/w32/file_error.h
index d134e67..d31f1f8 100644
--- a/sal/osl/w32/file_error.h
+++ b/sal/osl/w32/file_error.h
@@ -21,7 +21,6 @@
 #define INCLUDED_OSL_FILE_ERROR_H
 
 #include "osl/file.h"
-#include "rtl/ustring.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -29,13 +28,6 @@ extern "C" {
 
 oslFileError oslTranslateFileError (/*DWORD*/ unsigned long dwError);
 
-#if OSL_DEBUG_LEVEL > 0
-void _osl_warnFile (const char * message, rtl_uString * ustrFile);
-#define OSL_ENSURE_FILE( cond, msg, file ) ( (cond) ?  (void)0 : _osl_warnFile( msg, file ) )
-#else
-#define OSL_ENSURE_FILE( cond, msg, file ) ((void)0)
-#endif
-
 #ifdef __cplusplus
 }
 #endif
diff --git a/sal/osl/w32/file_url.cxx b/sal/osl/w32/file_url.cxx
index 51f1328..233b56e 100644
--- a/sal/osl/w32/file_url.cxx
+++ b/sal/osl/w32/file_url.cxx
@@ -711,10 +711,11 @@ oslFileError _osl_getSystemPathFromFileURL( rtl_uString *strURL, rtl_uString **p
 
     /* If the length of strUTF8 and strURL differs it indicates that the URL was not correct encoded */
 
-    OSL_ENSURE_FILE(
-        strUTF8->length == strURL->length ||
-        0 != rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength( strURL->buffer, strURL->length, "file:\\\\", 7 )
-        ,"osl_getSystemPathFromFileURL: \"%s\" is not encoded !!!", strURL );
+    SAL_WARN_IF(
+        strUTF8->length != strURL->length &&
+        0 == rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength( strURL->buffer, strURL->length, "file:\\\\", 7 )
+        , "sal.osl"
+        ,"osl_getSystemPathFromFileURL: \"" << strURL << "\" is not encoded !!!");
 
     bValidEncoded = _osl_decodeURL( strUTF8, &strDecodedURL );
 
@@ -809,10 +810,9 @@ oslFileError _osl_getSystemPathFromFileURL( rtl_uString *strURL, rtl_uString **p
             if ( IsValidFilePath( strTempPath, NULL, VALIDATEPATH_ALLOW_RELATIVE | VALIDATEPATH_ALLOW_ELLIPSE, &strTempPath ) )
                 nError = osl_File_E_None;
         }
-        /*
-          else
-          OSL_ENSURE_FILE( !nError, "osl_getSystemPathFromFileURL: \"%s\" is not an absolute FileURL !!!", strURL );
-        */
+        else
+          SAL_INFO_IF(nError, "sal.osl",
+              "osl_getSystemPathFromFileURL: \"" << strURL << "\" is not an absolute FileURL");
 
     }
 
@@ -825,9 +825,8 @@ oslFileError _osl_getSystemPathFromFileURL( rtl_uString *strURL, rtl_uString **p
     if ( strTempPath )
         rtl_uString_release( strTempPath );
 
-    /*
-      OSL_ENSURE_FILE( !nError, "osl_getSystemPathFromFileURL: \"%s\" is not a FileURL !!!", strURL );
-    */
+    SAL_INFO_IF(nError, "sal.osl",
+        "osl_getSystemPathFromFileURL: \"" << strURL << "\" is not a FileURL");
 
     return nError;
 }
@@ -933,9 +932,8 @@ oslFileError _osl_getFileURLFromSystemPath( rtl_uString* strPath, rtl_uString**
     if ( strTempURL )
         rtl_uString_release( strTempURL );
 
-    /*
-      OSL_ENSURE_FILE( !nError, "osl_getFileURLFromSystemPath: \"%s\" is not a systemPath !!!", strPath );
-    */
+    SAL_INFO_IF(nError, "sal.osl",
+        "osl_getFileURLFromSystemPath: \"" << strPath << "\" is not a systemPath");
     return nError;
 }
 


More information about the Libreoffice-commits mailing list