diff options
author | Paul Olav Tvete <paul.tvete@digia.com> | 2014-10-03 14:24:40 +0200 |
---|---|---|
committer | Paul Olav Tvete <paul.tvete@digia.com> | 2014-10-20 10:23:47 +0200 |
commit | 1fe8a708cbdb957be55b6162c5379102a46b3ed8 (patch) | |
tree | d16d33e17c7f1e4269c10a35ed438ce0df7900c5 /src/plugins/platforms/android/qandroidinputcontext.cpp | |
parent | 1faba97683ec42155acd7ed51d14f65bb240bc75 (diff) |
Android: deadlock avoidance
This change adds deadlock protection to all places where we lock
one thread while waiting for the other to do something. If we
detect that the other thread is going to block, we abort the
operation. This could cause unexpected problems, such as painting
errors, text input errors, or even crashes, but the alternative is
a guaranteed deadlock.
Task-number: QTBUG-41369
Change-Id: I2627a955cfafc4bce54eb9d0d38e19b768b06956
Reviewed-by: Christian Stromme <christian.stromme@digia.com>
Diffstat (limited to 'src/plugins/platforms/android/qandroidinputcontext.cpp')
-rw-r--r-- | src/plugins/platforms/android/qandroidinputcontext.cpp | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/plugins/platforms/android/qandroidinputcontext.cpp b/src/plugins/platforms/android/qandroidinputcontext.cpp index e3d488b958..a3848c9c2b 100644 --- a/src/plugins/platforms/android/qandroidinputcontext.cpp +++ b/src/plugins/platforms/android/qandroidinputcontext.cpp @@ -38,6 +38,7 @@ #include "androidjnimain.h" #include "androidjniinput.h" #include "qandroideventdispatcher.h" +#include "androiddeadlockprotector.h" #include <QDebug> #include <qevent.h> #include <qguiapplication.h> @@ -998,6 +999,9 @@ QVariant QAndroidInputContext::queryFocusObjectThreadSafe(Qt::InputMethodQuery q const bool inMainThread = qGuiApp->thread() == QThread::currentThread(); if (QAndroidEventDispatcherStopper::stopped() && !inMainThread) return retval; + AndroidDeadlockProtector protector; + if (!inMainThread && !protector.acquire()) + return retval; QMetaObject::invokeMethod(this, "queryFocusObjectUnsafe", inMainThread ? Qt::DirectConnection : Qt::BlockingQueuedConnection, @@ -1015,6 +1019,9 @@ QSharedPointer<QInputMethodQueryEvent> QAndroidInputContext::focusObjectInputMet const bool inMainThread = qGuiApp->thread() == QThread::currentThread(); if (QAndroidEventDispatcherStopper::stopped() && !inMainThread) return QSharedPointer<QInputMethodQueryEvent>(); + AndroidDeadlockProtector protector; + if (!inMainThread && !protector.acquire()) + return QSharedPointer<QInputMethodQueryEvent>(); QInputMethodQueryEvent *queryEvent = 0; QMetaObject::invokeMethod(this, "focusObjectInputMethodQueryUnsafe", @@ -1052,7 +1059,9 @@ void QAndroidInputContext::sendInputMethodEventThreadSafe(QInputMethodEvent *eve const bool inMainThread = qGuiApp->thread() == QThread::currentThread(); if (QAndroidEventDispatcherStopper::stopped() && !inMainThread) return; - + AndroidDeadlockProtector protector; + if (!inMainThread && !protector.acquire()) + return; QMetaObject::invokeMethod(this, "sendInputMethodEventUnsafe", inMainThread ? Qt::DirectConnection : Qt::BlockingQueuedConnection, Q_ARG(QInputMethodEvent*, event)); |