[Libreoffice-commits] core.git: vcl/source
Stephan Bergmann (via logerrit)
logerrit at kemper.freedesktop.org
Mon Jun 28 18:21:40 UTC 2021
vcl/source/uitest/uno/uiobject_uno.cxx | 32 +++++++++++++++++++++++++-------
vcl/source/uitest/uno/uiobject_uno.hxx | 13 -------------
2 files changed, 25 insertions(+), 20 deletions(-)
New commits:
commit 4ad110677be8c9b89524a0cbe1690778b3db032e
Author: Stephan Bergmann <sbergman at redhat.com>
AuthorDate: Mon Jun 28 16:58:45 2021 +0200
Commit: Stephan Bergmann <sbergman at redhat.com>
CommitDate: Mon Jun 28 20:21:05 2021 +0200
UIObjectUnoObj::executeAction does not need mutable state in UIObjectUnoObj
...as none of the state (now stored in struct Notifier) needs to outlive the
invocation of executeAction. This change makes mReady monotonic, which makes it
easier to reason about (and allows to substantially shrink the range of the
mMutex lock in executeAction).
Change-Id: I0a4dd4a286773fd09c469cb7fd625c1444424e98
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/118031
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman at redhat.com>
diff --git a/vcl/source/uitest/uno/uiobject_uno.cxx b/vcl/source/uitest/uno/uiobject_uno.cxx
index fd75b892d0c4..9041dc7f14e0 100644
--- a/vcl/source/uitest/uno/uiobject_uno.cxx
+++ b/vcl/source/uitest/uno/uiobject_uno.cxx
@@ -10,20 +10,36 @@
#include <sal/config.h>
#include <atomic>
+#include <condition_variable>
#include <memory>
+#include <mutex>
#include "uiobject_uno.hxx"
#include <utility>
#include <cppuhelper/supportsservice.hxx>
+#include <tools/link.hxx>
#include <vcl/svapp.hxx>
#include <vcl/idle.hxx>
#include <vcl/window.hxx>
#include <set>
+class Timer;
+
+namespace {
+
+struct Notifier {
+ std::condition_variable cv;
+ std::mutex mMutex;
+ bool mReady = false;
+
+ DECL_LINK( NotifyHdl, Timer*, void );
+};
+
+}
+
UIObjectUnoObj::UIObjectUnoObj(std::unique_ptr<UIObject> pObj):
UIObjectBase(m_aMutex),
- mpObj(std::move(pObj)),
- mReady(true)
+ mpObj(std::move(pObj))
{
}
@@ -43,7 +59,7 @@ css::uno::Reference<css::ui::test::XUIObject> SAL_CALL UIObjectUnoObj::getChild(
return new UIObjectUnoObj(std::move(pObj));
}
-IMPL_LINK_NOARG(UIObjectUnoObj, NotifyHdl, Timer*, void)
+IMPL_LINK_NOARG(Notifier, NotifyHdl, Timer*, void)
{
std::scoped_lock<std::mutex> lk(mMutex);
mReady = true;
@@ -102,8 +118,6 @@ void SAL_CALL UIObjectUnoObj::executeAction(const OUString& rAction, const css::
if (!mpObj)
throw css::uno::RuntimeException();
- std::unique_lock<std::mutex> lk(mMutex);
- mReady = false;
auto aIdle = std::make_unique<Idle>();
aIdle->SetDebugName("UI Test Idle Handler");
aIdle->SetPriority(TaskPriority::HIGHEST);
@@ -123,14 +137,18 @@ void SAL_CALL UIObjectUnoObj::executeAction(const OUString& rAction, const css::
mpObj->execute(rAction, aMap);
};
- ExecuteWrapper* pWrapper = new ExecuteWrapper(func, LINK(this, UIObjectUnoObj, NotifyHdl));
+ Notifier notifier;
+ ExecuteWrapper* pWrapper = new ExecuteWrapper(func, LINK(¬ifier, Notifier, NotifyHdl));
aIdle->SetInvokeHandler(LINK(pWrapper, ExecuteWrapper, ExecuteActionHdl));
{
SolarMutexGuard aGuard;
aIdle->Start();
}
- cv.wait(lk, [this]{return mReady;});
+ {
+ std::unique_lock<std::mutex> lk(notifier.mMutex);
+ notifier.cv.wait(lk, [¬ifier]{return notifier.mReady;});
+ }
pWrapper->setSignal();
SolarMutexGuard aGuard;
diff --git a/vcl/source/uitest/uno/uiobject_uno.hxx b/vcl/source/uitest/uno/uiobject_uno.hxx
index a9f2a294d9e3..47fc54696832 100644
--- a/vcl/source/uitest/uno/uiobject_uno.hxx
+++ b/vcl/source/uitest/uno/uiobject_uno.hxx
@@ -15,14 +15,9 @@
#include <com/sun/star/ui/test/XUIObject.hpp>
#include <memory>
-#include <condition_variable>
-#include <mutex>
-#include <tools/link.hxx>
#include <vcl/uitest/uiobject.hxx>
-class Timer;
-
typedef ::cppu::WeakComponentImplHelper <
css::ui::test::XUIObject, css::lang::XServiceInfo
> UIObjectBase;
@@ -55,14 +50,6 @@ public:
css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override;
OUString SAL_CALL getHierarchy() override;
-
-private:
-
- DECL_LINK( NotifyHdl, Timer*, void );
-
- std::condition_variable cv;
- std::mutex mMutex;
- bool mReady;
};
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
More information about the Libreoffice-commits
mailing list