dtrans/source/win32/clipb/MtaOleClipb.cxx | 31 +++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-)
New commits: commit 4d833a75423b8aa2e938d0247f89661a4c8efcbf Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> Date: Tue Nov 15 15:36:20 2016 +0100 tdf#103852 avoid clipboard deadlock Change-Id: If0c5f01d0aefd2444781612d47d8145b4869f3a1 diff --git a/dtrans/source/win32/clipb/MtaOleClipb.cxx b/dtrans/source/win32/clipb/MtaOleClipb.cxx index 843a73d..c5b5718 100644 --- a/dtrans/source/win32/clipb/MtaOleClipb.cxx +++ b/dtrans/source/win32/clipb/MtaOleClipb.cxx @@ -200,15 +200,17 @@ class CAutoComInit public: CAutoComInit( ) { - /* - to be safe we call CoInitialize - although it is not necessary if - the calling thread was created - using osl_CreateThread because - this function calls CoInitialize - for every thread it creates + /* To be safe we call CoInitializeEx although it is not necessary if + the calling thread was created using osl_CreateThread because + this function calls CoInitializeEx for every thread it creates. + + We initialize with COINIT_APARTMENTTHREADED so Mulit-Threaded + Apartments(MTA) are used. See [1] for more details about STA and MTA + modes. + + [1] https://msdn.microsoft.com/en-us/library/ms809971.aspx */ - m_hResult = CoInitialize( NULL ); + m_hResult = CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED); if ( S_OK == m_hResult ) OSL_FAIL( \ @@ -220,15 +222,10 @@ public: ~CAutoComInit( ) { - /* - we only call CoUninitialize when - CoInitialize returned S_FALSE, what - means that com was already initialize - for that thread so we keep the balance - if CoInitialize returned S_OK what means - com was not yet initialized we better - let com initialized or we may run into - the realm of undefined behaviour + /* We only call CoUninitialize when CoInitialize returned S_FALSE, what + means that com was already initialize for that thread so we keep the balance + if CoInitialize returned S_OK what means com was not yet initialized we better + let com initialized or we may run into the realm of undefined behaviour */ if ( m_hResult == S_FALSE ) CoUninitialize( ); diff --git a/dtrans/source/win32/dtobj/XTDataObject.cxx b/dtrans/source/win32/dtobj/XTDataObject.cxx index 51108a1..ad1c9f0 100644 --- a/dtrans/source/win32/dtobj/XTDataObject.cxx +++ b/dtrans/source/win32/dtobj/XTDataObject.cxx @@ -25,8 +25,11 @@ #include "DTransHelper.hxx" #include "TxtCnvtHlp.hxx" #include <com/sun/star/datatransfer/clipboard/XClipboardEx.hpp> +#include "com/sun/star/awt/AsyncCallback.hpp" +#include "com/sun/star/awt/XCallback.hpp" #include "FmtFilter.hxx" #include <comphelper/processfactory.hxx> +#include <cppuhelper/implbase.hxx> #if defined _MSC_VER #pragma warning(push,1) @@ -52,6 +55,22 @@ using namespace com::sun::star::datatransfer::clipboard; using namespace com::sun::star::uno; using namespace com::sun::star::lang; + +class AsyncDereference : public cppu::WeakImplHelper<css::awt::XCallback> +{ + Reference<XTransferable> maTransferable; +public: + AsyncDereference(css::uno::Reference<css::datatransfer::XTransferable> const & rTransferable) + : maTransferable(rTransferable) + {} + + virtual void SAL_CALL notify(css::uno::Any const &) + throw (css::uno::RuntimeException, std::exception) override + { + maTransferable.set(nullptr); + } +}; + // a helper class that will be thrown by the function validateFormatEtc class CInvalidFormatEtcException @@ -67,12 +86,20 @@ CXTDataObject::CXTDataObject( const Reference< XComponentContext >& rxContext, const Reference< XTransferable >& aXTransferable ) : m_nRefCnt( 0 ) , m_XTransferable( aXTransferable ) + , m_XComponentContext( rxContext ) , m_bFormatEtcContainerInitialized( sal_False ) , m_DataFormatTranslator( rxContext ) , m_FormatRegistrar( rxContext, m_DataFormatTranslator ) { } +CXTDataObject::~CXTDataObject() +{ + css::awt::AsyncCallback::create(m_XComponentContext)->addCallback( + new AsyncDereference(m_XTransferable), + css::uno::Any()); +} + // IUnknown->QueryInterface STDMETHODIMP CXTDataObject::QueryInterface( REFIID iid, LPVOID* ppvObject ) diff --git a/dtrans/source/win32/dtobj/XTDataObject.hxx b/dtrans/source/win32/dtobj/XTDataObject.hxx index 3d8d71c..f9e98e8 100644 --- a/dtrans/source/win32/dtobj/XTDataObject.hxx +++ b/dtrans/source/win32/dtobj/XTDataObject.hxx @@ -64,7 +64,7 @@ class CXTDataObject : public IDataObject public: CXTDataObject( const css::uno::Reference< css::uno::XComponentContext >& rxContext, const css::uno::Reference< css::datatransfer::XTransferable >& aXTransferable ); - virtual ~CXTDataObject() {} + virtual ~CXTDataObject(); // ole interface implementation @@ -118,6 +118,7 @@ private: private: LONG m_nRefCnt; css::uno::Reference< css::datatransfer::XTransferable > m_XTransferable; + css::uno::Reference< css::uno::XComponentContext> m_XComponentContext; CFormatEtcContainer m_FormatEtcContainer; sal_Bool m_bFormatEtcContainerInitialized; CDataFormatTranslator m_DataFormatTranslator; diff --git a/toolkit/source/awt/asynccallback.cxx b/toolkit/source/awt/asynccallback.cxx index 2d30afe..9268cb5 100644 --- a/toolkit/source/awt/asynccallback.cxx +++ b/toolkit/source/awt/asynccallback.cxx @@ -88,8 +88,7 @@ void SAL_CALL AsyncCallback::addCallback(const css::uno::Reference< css::awt::XC { if ( Application::IsInMain() ) { - SolarMutexGuard aSolarGuard; - + // NOTE: We don't need SolarMutexGuard here as Application::PostUserEvent is thread-safe CallbackData* pCallbackData = new CallbackData( xCallback, aData ); Application::PostUserEvent( LINK( this, AsyncCallback, Notify_Impl ), pCallbackData ); } commit 11919ea148cee39af001acbe9e8e5987be6b58a8 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> Date: Tue Nov 22 21:42:48 2016 +0100 Revert "tdf#103852 avoid clipboard deadlock" This reverts commit fd42457d52b68c60f2cbbd518648044821bb13c9. diff --git a/dtrans/source/win32/dtobj/XTDataObject.cxx b/dtrans/source/win32/dtobj/XTDataObject.cxx index ad1c9f0..51108a1 100644 --- a/dtrans/source/win32/dtobj/XTDataObject.cxx +++ b/dtrans/source/win32/dtobj/XTDataObject.cxx @@ -25,11 +25,8 @@ #include "DTransHelper.hxx" #include "TxtCnvtHlp.hxx" #include <com/sun/star/datatransfer/clipboard/XClipboardEx.hpp> -#include "com/sun/star/awt/AsyncCallback.hpp" -#include "com/sun/star/awt/XCallback.hpp" #include "FmtFilter.hxx" #include <comphelper/processfactory.hxx> -#include <cppuhelper/implbase.hxx> #if defined _MSC_VER #pragma warning(push,1) @@ -55,22 +52,6 @@ using namespace com::sun::star::datatransfer::clipboard; using namespace com::sun::star::uno; using namespace com::sun::star::lang; - -class AsyncDereference : public cppu::WeakImplHelper<css::awt::XCallback> -{ - Reference<XTransferable> maTransferable; -public: - AsyncDereference(css::uno::Reference<css::datatransfer::XTransferable> const & rTransferable) - : maTransferable(rTransferable) - {} - - virtual void SAL_CALL notify(css::uno::Any const &) - throw (css::uno::RuntimeException, std::exception) override - { - maTransferable.set(nullptr); - } -}; - // a helper class that will be thrown by the function validateFormatEtc class CInvalidFormatEtcException @@ -86,20 +67,12 @@ CXTDataObject::CXTDataObject( const Reference< XComponentContext >& rxContext, const Reference< XTransferable >& aXTransferable ) : m_nRefCnt( 0 ) , m_XTransferable( aXTransferable ) - , m_XComponentContext( rxContext ) , m_bFormatEtcContainerInitialized( sal_False ) , m_DataFormatTranslator( rxContext ) , m_FormatRegistrar( rxContext, m_DataFormatTranslator ) { } -CXTDataObject::~CXTDataObject() -{ - css::awt::AsyncCallback::create(m_XComponentContext)->addCallback( - new AsyncDereference(m_XTransferable), - css::uno::Any()); -} - // IUnknown->QueryInterface STDMETHODIMP CXTDataObject::QueryInterface( REFIID iid, LPVOID* ppvObject ) diff --git a/dtrans/source/win32/dtobj/XTDataObject.hxx b/dtrans/source/win32/dtobj/XTDataObject.hxx index f9e98e8..3d8d71c 100644 --- a/dtrans/source/win32/dtobj/XTDataObject.hxx +++ b/dtrans/source/win32/dtobj/XTDataObject.hxx @@ -64,7 +64,7 @@ class CXTDataObject : public IDataObject public: CXTDataObject( const css::uno::Reference< css::uno::XComponentContext >& rxContext, const css::uno::Reference< css::datatransfer::XTransferable >& aXTransferable ); - virtual ~CXTDataObject(); + virtual ~CXTDataObject() {} // ole interface implementation @@ -118,7 +118,6 @@ private: private: LONG m_nRefCnt; css::uno::Reference< css::datatransfer::XTransferable > m_XTransferable; - css::uno::Reference< css::uno::XComponentContext> m_XComponentContext; CFormatEtcContainer m_FormatEtcContainer; sal_Bool m_bFormatEtcContainerInitialized; CDataFormatTranslator m_DataFormatTranslator; diff --git a/toolkit/source/awt/asynccallback.cxx b/toolkit/source/awt/asynccallback.cxx index 9268cb5..2d30afe 100644 --- a/toolkit/source/awt/asynccallback.cxx +++ b/toolkit/source/awt/asynccallback.cxx @@ -88,7 +88,8 @@ void SAL_CALL AsyncCallback::addCallback(const css::uno::Reference< css::awt::XC { if ( Application::IsInMain() ) { - // NOTE: We don't need SolarMutexGuard here as Application::PostUserEvent is thread-safe + SolarMutexGuard aSolarGuard; + CallbackData* pCallbackData = new CallbackData( xCallback, aData ); Application::PostUserEvent( LINK( this, AsyncCallback, Notify_Impl ), pCallbackData ); }
_______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits