diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-09-08 09:44:33 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-09-11 19:07:58 +0200 |
commit | 2601708e3c00092693af6dd04561125cafb21d8e (patch) | |
tree | d1bd3c64060f71a91c7d90fc3b3d03bf1936aae7 /vcl/source/uitest | |
parent | 40069adbc225a6dd5d3431a7cd9f17986f6385de (diff) |
cleanup mutex and signalling in ExecuteWrapper
found this while examining issues reported by clang-tidy.
Judging from the code, the original intention was to somehow lock access
to the mbSignal field in ExecuteWrapper, but since we were not locking
when writing to that field, and that field was not volatile, it
surprises me that this worked very well at all.
We can accomplish the same end more reliably by just marking the field
as volatile and not doing any locking at all.
Change-Id: I388c7082a809b6aca5a3c8981625f55cfef3cfcd
Reviewed-on: https://gerrit.libreoffice.org/60184
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'vcl/source/uitest')
-rw-r--r-- | vcl/source/uitest/uno/uiobject_uno.cxx | 23 |
1 files changed, 2 insertions, 21 deletions
diff --git a/vcl/source/uitest/uno/uiobject_uno.cxx b/vcl/source/uitest/uno/uiobject_uno.cxx index a121889e67c9..f95a67747e25 100644 --- a/vcl/source/uitest/uno/uiobject_uno.cxx +++ b/vcl/source/uitest/uno/uiobject_uno.cxx @@ -58,8 +58,7 @@ class ExecuteWrapper { std::function<void()> mFunc; Link<Timer*, void> mHandler; - bool mbSignal; - std::mutex mMutex; + volatile bool mbSignal; public: @@ -75,11 +74,6 @@ public: mbSignal = true; } - std::mutex& getMutex() - { - return mMutex; - } - DECL_LINK( ExecuteActionHdl, Timer*, void ); }; @@ -96,21 +90,9 @@ IMPL_LINK_NOARG(ExecuteWrapper, ExecuteActionHdl, Timer*, void) aIdle.Start(); } - for (;;) { - { - std::unique_lock<std::mutex> lock(mMutex); - if (mbSignal) { - break; - } - } + while (!mbSignal) { Application::Reschedule(); } - std::unique_lock<std::mutex> lock(mMutex); - while (!mbSignal) - { - // coverity[sleep] - intentional sleep while mutex held - std::this_thread::sleep_for(std::chrono::milliseconds(5)); - } } delete this; } @@ -146,7 +128,6 @@ void SAL_CALL UIObjectUnoObj::executeAction(const OUString& rAction, const css:: }; ExecuteWrapper* pWrapper = new ExecuteWrapper(func, LINK(this, UIObjectUnoObj, NotifyHdl)); - std::unique_lock<std::mutex>(pWrapper->getMutex()); aIdle->SetInvokeHandler(LINK(pWrapper, ExecuteWrapper, ExecuteActionHdl)); { SolarMutexGuard aGuard; |