summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/android/androiddeadlockprotector.h
diff options
context:
space:
mode:
authorPaul Olav Tvete <paul.tvete@digia.com>2014-10-03 14:24:40 +0200
committerPaul Olav Tvete <paul.tvete@digia.com>2014-10-20 10:23:47 +0200
commit1fe8a708cbdb957be55b6162c5379102a46b3ed8 (patch)
treed16d33e17c7f1e4269c10a35ed438ce0df7900c5 /src/plugins/platforms/android/androiddeadlockprotector.h
parent1faba97683ec42155acd7ed51d14f65bb240bc75 (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/androiddeadlockprotector.h')
-rw-r--r--src/plugins/platforms/android/androiddeadlockprotector.h67
1 files changed, 67 insertions, 0 deletions
diff --git a/src/plugins/platforms/android/androiddeadlockprotector.h b/src/plugins/platforms/android/androiddeadlockprotector.h
new file mode 100644
index 0000000000..a0a82aa9d1
--- /dev/null
+++ b/src/plugins/platforms/android/androiddeadlockprotector.h
@@ -0,0 +1,67 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the plugins of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL21$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 or version 3 as published by the Free
+** Software Foundation and appearing in the file LICENSE.LGPLv21 and
+** LICENSE.LGPLv3 included in the packaging of this file. Please review the
+** following information to ensure the GNU Lesser General Public License
+** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef ANDROID_DEADLOCKPROTECTOR_H
+#define ANDROID_DEADLOCKPROTECTOR_H
+
+#include <QAtomicInt>
+
+QT_BEGIN_NAMESPACE
+
+class AndroidDeadlockProtector
+{
+public:
+ AndroidDeadlockProtector()
+ : m_acquired(0)
+ {
+ }
+
+ ~AndroidDeadlockProtector() {
+ if (m_acquired)
+ s_blocked.storeRelease(0);
+ }
+
+ bool acquire() {
+ m_acquired = s_blocked.testAndSetAcquire(0, 1);
+ return m_acquired;
+ }
+
+private:
+ static QAtomicInt s_blocked;
+ int m_acquired;
+};
+
+QT_END_NAMESPACE
+
+#endif // ANDROID_DEADLOCKPROTECTOR_H
+