Avoid deadlock on suspend/resume

On some devices, there is a possibility of getting a state change
while we are locking the event loop for suspend. This is
probably related to change 8c0ef140b3, but we should in
any case use the existing deadlock protection mutex mechanism,
just to make sure that there are not other cases which could
trigger the same deadlock.

Task-number: QTBUG-44339
Change-Id: I3e0b5fa2ddf4ef86e6b29cb1d67c4cccedd8242e
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@theqtcompany.com>
This commit is contained in:
Paul Olav Tvete 2015-03-13 11:41:49 +01:00
parent f901b75926
commit 5d34bf9033

View File

@ -33,6 +33,7 @@
#include "qandroideventdispatcher.h"
#include "androidjnimain.h"
#include "androiddeadlockprotector.h"
QAndroidEventDispatcher::QAndroidEventDispatcher(QObject *parent) :
QUnixEventDispatcherQPA(parent)
@ -78,11 +79,13 @@ void QAndroidEventDispatcher::goingToStop(bool stop)
int QAndroidEventDispatcher::select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, timespec *timeout)
{
if (m_stopRequest.testAndSetAcquire(StopRequest, Stopping)) {
{
AndroidDeadlockProtector protector;
if (protector.acquire() && m_stopRequest.testAndSetAcquire(StopRequest, Stopping)) {
m_semaphore.acquire();
wakeUp();
}
}
return QUnixEventDispatcherQPA::select(nfds, readfds, writefds, exceptfds, timeout);
}