Android: Fix data race in QAndroidEventDispatcherStopper
Change-Id: If5f8406d7af2d91e267a0ba380e73287feabac9f Reviewed-by: BogDan Vatra <bogdan@kdab.com>bb10
parent
2294d1fb1a
commit
d0b8356e7e
|
|
@ -108,10 +108,9 @@ QAndroidEventDispatcherStopper *QAndroidEventDispatcherStopper::instance()
|
|||
void QAndroidEventDispatcherStopper::startAll()
|
||||
{
|
||||
QMutexLocker lock(&m_mutex);
|
||||
if (started)
|
||||
if (!m_started.testAndSetOrdered(0, 1))
|
||||
return;
|
||||
|
||||
started = true;
|
||||
for (QAndroidEventDispatcher *d : qAsConst(m_dispatchers))
|
||||
d->start();
|
||||
}
|
||||
|
|
@ -119,10 +118,9 @@ void QAndroidEventDispatcherStopper::startAll()
|
|||
void QAndroidEventDispatcherStopper::stopAll()
|
||||
{
|
||||
QMutexLocker lock(&m_mutex);
|
||||
if (!started)
|
||||
if (!m_started.testAndSetOrdered(1, 0))
|
||||
return;
|
||||
|
||||
started = false;
|
||||
for (QAndroidEventDispatcher *d : qAsConst(m_dispatchers))
|
||||
d->stop();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ class QAndroidEventDispatcherStopper
|
|||
{
|
||||
public:
|
||||
static QAndroidEventDispatcherStopper *instance();
|
||||
static bool stopped() {return !instance()->started; }
|
||||
static bool stopped() {return !instance()->m_started.load(); }
|
||||
void startAll();
|
||||
void stopAll();
|
||||
void addEventDispatcher(QAndroidEventDispatcher *dispatcher);
|
||||
|
|
@ -77,7 +77,7 @@ public:
|
|||
|
||||
private:
|
||||
QMutex m_mutex;
|
||||
bool started = true;
|
||||
QAtomicInt m_started = 1;
|
||||
QVector<QAndroidEventDispatcher *> m_dispatchers;
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue