diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2021-03-09 10:10:25 +0300 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2021-03-09 10:00:41 +0100 |
commit | 5d658689dd2994fd1cb7c2fc722b86befd78dcba (patch) | |
tree | dbb6a66cda8eb77c9807b6bb9abe796d418aabcc /vcl/win | |
parent | d5eeca9bf3811b8c83d497dab5edb3ee2ba79a84 (diff) |
Simplify CWinClipboard mutexes
This replaces a home-grown ancestor class with use of cppu::BaseMutex,
and moves/renames mutexes to better reflect their use.
Change-Id: I6a9dd2e19ff7db524dc753d42e2027c4d5b2bb6a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/112188
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'vcl/win')
-rw-r--r-- | vcl/win/dtrans/WinClipboard.cxx | 37 | ||||
-rw-r--r-- | vcl/win/dtrans/WinClipboard.hxx | 19 |
2 files changed, 25 insertions, 31 deletions
diff --git a/vcl/win/dtrans/WinClipboard.cxx b/vcl/win/dtrans/WinClipboard.cxx index 407325b14280..23b20449e0c5 100644 --- a/vcl/win/dtrans/WinClipboard.cxx +++ b/vcl/win/dtrans/WinClipboard.cxx @@ -49,29 +49,34 @@ using namespace com::sun::star; -// definition of static members -CWinClipboard* CWinClipboard::s_pCWinClipbImpl = nullptr; -osl::Mutex CWinClipboard::s_aMutex; +namespace +{ +CWinClipboard* s_pCWinClipbImpl = nullptr; +osl::Mutex s_aClipboardSingletonMutex; +} /*XEventListener,*/ CWinClipboard::CWinClipboard(const uno::Reference<uno::XComponentContext>& rxContext, const OUString& aClipboardName) - : WeakComponentImplHelper<XSystemClipboard, XFlushableClipboard, XServiceInfo>( - m_aCbListenerMutex) + : WeakComponentImplHelper<XSystemClipboard, XFlushableClipboard, XServiceInfo>(m_aMutex) , m_xContext(rxContext) , m_itsName(aClipboardName) , m_pCurrentClipContent(nullptr) { // necessary to reassociate from // the static callback function - s_pCWinClipbImpl = this; + { + osl::MutexGuard aGuard(s_aClipboardSingletonMutex); + s_pCWinClipbImpl = this; + } + registerClipboardViewer(); } CWinClipboard::~CWinClipboard() { { - osl::MutexGuard aGuard(s_aMutex); + osl::MutexGuard aGuard(s_aClipboardSingletonMutex); s_pCWinClipbImpl = nullptr; } @@ -88,7 +93,7 @@ CWinClipboard::~CWinClipboard() uno::Reference<datatransfer::XTransferable> SAL_CALL CWinClipboard::getContents() { - osl::MutexGuard aGuard(m_aMutex); + osl::MutexGuard aGuard(m_aContentMutex); if (rBHelper.bDisposed) throw lang::DisposedException("object is already disposed", @@ -97,7 +102,7 @@ uno::Reference<datatransfer::XTransferable> SAL_CALL CWinClipboard::getContents( // use the shortcut or create a transferable from // system clipboard { - osl::MutexGuard aGuard2(m_ClipContentMutex); + osl::MutexGuard aGuard2(m_aContentCacheMutex); if (nullptr != m_pCurrentClipContent) return m_pCurrentClipContent->m_XTransferable; @@ -122,7 +127,7 @@ uno::Reference<datatransfer::XTransferable> SAL_CALL CWinClipboard::getContents( std::vector<sal_uInt32> aFormats(aUINTFormats.begin(), aUINTFormats.end()); rClipContent = new CDOTransferable(m_xContext, this, aFormats); - osl::MutexGuard aGuard2(m_ClipContentMutex); + osl::MutexGuard aGuard2(m_aContentCacheMutex); m_foreignContent = rClipContent; } } @@ -132,7 +137,7 @@ uno::Reference<datatransfer::XTransferable> SAL_CALL CWinClipboard::getContents( IDataObjectPtr CWinClipboard::getIDataObject() { - osl::MutexGuard aGuard(m_aMutex); + osl::MutexGuard aGuard(m_aContentMutex); if (rBHelper.bDisposed) throw lang::DisposedException("object is already disposed", @@ -156,7 +161,7 @@ void SAL_CALL CWinClipboard::setContents( const uno::Reference<datatransfer::XTransferable>& xTransferable, const uno::Reference<datatransfer::clipboard::XClipboardOwner>& xClipboardOwner) { - osl::MutexGuard aGuard(m_aMutex); + osl::MutexGuard aGuard(m_aContentMutex); if (rBHelper.bDisposed) throw lang::DisposedException("object is already disposed", @@ -167,7 +172,7 @@ void SAL_CALL CWinClipboard::setContents( if (xTransferable.is()) { { - osl::MutexGuard aGuard2(m_ClipContentMutex); + osl::MutexGuard aGuard2(m_aContentCacheMutex); m_foreignContent.clear(); @@ -195,7 +200,7 @@ OUString SAL_CALL CWinClipboard::getName() void SAL_CALL CWinClipboard::flushClipboard() { - osl::MutexGuard aGuard(m_aMutex); + osl::MutexGuard aGuard(m_aContentMutex); if (rBHelper.bDisposed) throw lang::DisposedException("object is already disposed", @@ -353,7 +358,7 @@ void CWinClipboard::onReleaseDataObject(CXNotifyingDataObject* theCaller) // if the current caller is the one we currently hold, then set it to NULL // because an external source must be the clipboardowner now - osl::MutexGuard aGuard(m_ClipContentMutex); + osl::MutexGuard aGuard(m_aContentCacheMutex); if (m_pCurrentClipContent == theCaller) m_pCurrentClipContent = nullptr; @@ -368,7 +373,7 @@ void CWinClipboard::unregisterClipboardViewer() { m_MtaOleClipboard.registerClip void WINAPI CWinClipboard::onClipboardContentChanged() { - osl::MutexGuard aGuard(s_aMutex); + osl::MutexGuard aGuard(s_aClipboardSingletonMutex); // reassociation to instance through static member if (nullptr != s_pCWinClipbImpl) diff --git a/vcl/win/dtrans/WinClipboard.hxx b/vcl/win/dtrans/WinClipboard.hxx index 8e64029b9ae3..ac86d0d547b4 100644 --- a/vcl/win/dtrans/WinClipboard.hxx +++ b/vcl/win/dtrans/WinClipboard.hxx @@ -21,6 +21,7 @@ #include <rtl/ustring.hxx> #include <sal/types.h> +#include <cppuhelper/basemutex.hxx> #include <cppuhelper/compbase.hxx> #include <com/sun/star/datatransfer/XTransferable.hpp> #include <com/sun/star/datatransfer/clipboard/XClipboardEx.hpp> @@ -46,18 +47,8 @@ // this will be assured by a OneInstanceFactory of the service and not // by this class! -// helper class, so that the mutex is constructed -// before the constructor of WeakComponentImplHelper -// will be called and initialized with this mutex -class CWinClipboardDummy -{ -protected: - osl::Mutex m_aMutex; - osl::Mutex m_aCbListenerMutex; -}; - class CWinClipboard final - : public CWinClipboardDummy, + : public cppu::BaseMutex, public cppu::WeakComponentImplHelper<css::datatransfer::clipboard::XSystemClipboard, css::datatransfer::clipboard::XFlushableClipboard, css::lang::XServiceInfo> @@ -69,10 +60,8 @@ class CWinClipboard final CMtaOleClipboard m_MtaOleClipboard; CXNotifyingDataObject* m_pCurrentClipContent; com::sun::star::uno::Reference<com::sun::star::datatransfer::XTransferable> m_foreignContent; - osl::Mutex m_ClipContentMutex; - - static osl::Mutex s_aMutex; - static CWinClipboard* s_pCWinClipbImpl; + osl::Mutex m_aContentMutex; + osl::Mutex m_aContentCacheMutex; void notifyAllClipboardListener(); void onReleaseDataObject(CXNotifyingDataObject* theCaller); |