diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2021-06-28 16:58:45 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2021-06-28 20:21:05 +0200 |
commit | 4ad110677be8c9b89524a0cbe1690778b3db032e (patch) | |
tree | e72d00c20910853a39e813dc696f8a3cfd6507e3 /vcl/source/uitest/uno | |
parent | 1b052ff4ac5f5d29b69a91d4f14742e555f2a03b (diff) |
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@redhat.com>
Diffstat (limited to 'vcl/source/uitest/uno')
-rw-r--r-- | vcl/source/uitest/uno/uiobject_uno.cxx | 32 | ||||
-rw-r--r-- | vcl/source/uitest/uno/uiobject_uno.hxx | 13 |
2 files changed, 25 insertions, 20 deletions
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: */ |