tdf#119856 vcl: Qt5/KDE5 RunInMainThread
commit265caa4381c048c346c907b017561ab0fe0367ff
authorMichael Stahl <Michael.Stahl@cib.de>
Fri, 22 Feb 2019 18:19:27 +0000 (22 19:19 +0100)
committerKatarina Behrens <Katarina.Behrens@cib.de>
Tue, 5 Mar 2019 11:47:57 +0000 (5 12:47 +0100)
tree826ea80cad1783f2cf1f4af1c2fb4af15efe237b
parentc3751ed3c98e8ed40100a8073b97c83d9ded0803
tdf#119856 vcl: Qt5/KDE5 RunInMainThread

The problem with the current approach of transferring calls to the main
thread with Q_EMIT signals is that if the code that should run in the
main thread needs SolarMutex, then the non-main-thread must use
SolarMutexReleaser - but then the main thread will run not only the call
that is needed right now, but will potentially process all pending
events, and the other thread hasn't prepared for that.

We need the inter-thread feature of Qt::BlockingQueuedConnection and the
non-queued feature of Qt::DirectConnection, but this combination doesn't
appear to exist.

So the SolarMutexReleaser needs to go - but then the main thread does
need SolarMutex for some things, and hence we need to trick it into
believing it has SolarMutex with the m_bNoYieldLock hack.

Then it becomes apparent that the main thread may be blocked on either
Qt events, which is fine, or on the SalYieldMutex's m_aMutex, which will
never be released now.

So the main thread must never block on m_aMutex; the alternative is to
use the same approach as the osx code (and, in a somewhat different
form, the svp code), and add some condition variables on which the main
thread can block if it fails to acquire the m_aMutex immediately.

It's even possible to do this in a somewhat generic way with lambdas.

This does appear to work, but it makes the Q_EMIT approach entirely
untenable, because now the main thread will be blocked on the condition
variable and the non-main-thread will be blocked until the Qt event is
processed.

Change-Id: I6480a6b909d5ec8814b2ff10dbefb0f3686a83c7
Reviewed-on: https://gerrit.libreoffice.org/68232
Tested-by: Jenkins
Reviewed-by: Katarina Behrens <Katarina.Behrens@cib.de>
vcl/inc/qt5/Qt5Instance.hxx
vcl/qt5/Qt5Instance.cxx
vcl/unx/kde5/KDE5SalInstance.cxx
vcl/unx/kde5/KDE5SalInstance.hxx