[Libreoffice-commits] core.git: framework/source include/framework
Noel Grandin (via logerrit)
logerrit at kemper.freedesktop.org
Fri Jul 30 12:08:17 UTC 2021
framework/source/services/dispatchhelper.cxx | 28 ++++++++++++++++-----------
include/framework/dispatchhelper.hxx | 11 ++++------
2 files changed, 22 insertions(+), 17 deletions(-)
New commits:
commit 7b5922eb666e5f153060468b271d99510adb422e
Author: Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Fri Jul 30 10:10:55 2021 +0200
Commit: Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Fri Jul 30 14:07:43 2021 +0200
osl::Mutex->std::mutex in DispatchHelper
Change-Id: I6443f604f7f5cacc4b3d67bb6dab07706c82a9a7
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/119700
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
diff --git a/framework/source/services/dispatchhelper.cxx b/framework/source/services/dispatchhelper.cxx
index 380eab11ec67..cfa4a8a2bbe1 100644
--- a/framework/source/services/dispatchhelper.cxx
+++ b/framework/source/services/dispatchhelper.cxx
@@ -53,6 +53,7 @@ css::uno::Sequence<OUString> SAL_CALL DispatchHelper::getSupportedServiceNames()
*/
DispatchHelper::DispatchHelper(const css::uno::Reference<css::uno::XComponentContext>& xContext)
: m_xContext(xContext)
+ , m_aBlockFlag(false)
{
}
@@ -91,11 +92,12 @@ css::uno::Any SAL_CALL DispatchHelper::executeDispatch(
}
// parse given URL
+ css::uno::Reference<css::util::XURLTransformer> xParser;
/* SAFE { */
- osl::ClearableMutexGuard aReadLock(m_mutex);
- css::uno::Reference<css::util::XURLTransformer> xParser
- = css::util::URLTransformer::create(m_xContext);
- aReadLock.clear();
+ {
+ std::lock_guard aReadLock(m_mutex);
+ xParser = css::util::URLTransformer::create(m_xContext);
+ }
/* } SAFE */
css::util::URL aURL;
@@ -148,16 +150,18 @@ DispatchHelper::executeDispatch(const css::uno::Reference<css::frame::XDispatch>
css::uno::UNO_QUERY);
/* SAFE { */
{
- osl::MutexGuard aWriteLock(m_mutex);
+ std::lock_guard aWriteLock(m_mutex);
m_xBroadcaster = xNotifyDispatch;
- m_aBlock.reset();
+ m_aBlockFlag = false;
}
/* } SAFE */
// dispatch it and wait for a notification
// TODO/MBA: waiting in main thread?!
xNotifyDispatch->dispatchWithNotification(aURL, aArguments, xListener);
- m_aBlock.wait(); // wait for result
+
+ std::unique_lock aWriteLock(m_mutex);
+ m_aBlock.wait(aWriteLock, [this] { return m_aBlockFlag; }); // wait for result
}
else
{
@@ -180,9 +184,10 @@ DispatchHelper::executeDispatch(const css::uno::Reference<css::frame::XDispatch>
*/
void SAL_CALL DispatchHelper::dispatchFinished(const css::frame::DispatchResultEvent& aResult)
{
- osl::MutexGuard g(m_mutex);
+ std::lock_guard g(m_mutex);
m_aResult <<= aResult;
- m_aBlock.set();
+ m_aBlockFlag = true;
+ m_aBlock.notify_one();
m_xBroadcaster.clear();
}
@@ -193,9 +198,10 @@ void SAL_CALL DispatchHelper::dispatchFinished(const css::frame::DispatchResultE
*/
void SAL_CALL DispatchHelper::disposing(const css::lang::EventObject&)
{
- osl::MutexGuard g(m_mutex);
+ std::lock_guard g(m_mutex);
m_aResult.clear();
- m_aBlock.set();
+ m_aBlockFlag = true;
+ m_aBlock.notify_one();
m_xBroadcaster.clear();
}
}
diff --git a/include/framework/dispatchhelper.hxx b/include/framework/dispatchhelper.hxx
index f362f30ab633..ca7e2b2ccf12 100644
--- a/include/framework/dispatchhelper.hxx
+++ b/include/framework/dispatchhelper.hxx
@@ -28,7 +28,8 @@
#include <cppuhelper/implbase.hxx>
#include <framework/fwkdllapi.h>
-#include <osl/conditn.hxx>
+#include <condition_variable>
+#include <mutex>
namespace com::sun::star::lang
{
@@ -57,17 +58,15 @@ class UNLESS_MERGELIBS(FWK_DLLPUBLIC) DispatchHelper final
: public ::cppu::WeakImplHelper<css::lang::XServiceInfo, css::frame::XDispatchHelper,
css::frame::XDispatchResultListener>
{
- // member
-
-private:
- osl::Mutex m_mutex;
+ std::mutex m_mutex;
/** global uno service manager.
Can be used to create own needed services. */
css::uno::Reference<css::uno::XComponentContext> m_xContext;
/** used to wait for asynchronous listener callbacks. */
- ::osl::Condition m_aBlock;
+ std::condition_variable m_aBlock;
+ bool m_aBlockFlag;
css::uno::Any m_aResult;
More information about the Libreoffice-commits
mailing list