Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qandroideventdispatcher.cpp
Go to the documentation of this file.
1// Copyright (C) 2014 BogDan Vatra <bogdan@kde.org>
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
5#include "androidjnimain.h"
7
14
20
21enum States {Running = 0, StopRequest = 1, Stopping = 2};
22
24{
25 int prevState = m_stopRequest.fetchAndStoreAcquire(Running);
26 if (prevState == Stopping) {
27 m_semaphore.release();
28 wakeUp();
29 } else if (prevState == Running) {
30 qWarning("Error: start without corresponding stop");
31 }
32 //else if prevState == StopRequest, no action needed
33}
34
36{
37 if (m_stopRequest.testAndSetAcquire(Running, StopRequest))
38 wakeUp();
39 else
40 qWarning("Error: start/stop out of sync");
41}
42
44{
45 m_goingToStop.storeRelaxed(stop ? 1 : 0);
46 if (!stop)
47 wakeUp();
48}
49
50bool QAndroidEventDispatcher::processEvents(QEventLoop::ProcessEventsFlags flags)
51{
52 if (m_goingToStop.loadRelaxed())
54
55 {
57 if (protector.acquire() && m_stopRequest.testAndSetAcquire(StopRequest, Stopping)) {
58 m_semaphore.acquire();
59 wakeUp();
60 }
61 }
62
64}
65
67{
68 Q_CONSTINIT static QAndroidEventDispatcherStopper androidEventDispatcherStopper;
69 return &androidEventDispatcherStopper;
70}
71
73{
74 QMutexLocker lock(&m_mutex);
75 if (!m_started.testAndSetOrdered(0, 1))
76 return;
77
78 for (QAndroidEventDispatcher *d : std::as_const(m_dispatchers))
79 d->start();
80}
81
83{
84 QMutexLocker lock(&m_mutex);
85 if (!m_started.testAndSetOrdered(1, 0))
86 return;
87
88 for (QAndroidEventDispatcher *d : std::as_const(m_dispatchers))
89 d->stop();
90}
91
93{
94 QMutexLocker lock(&m_mutex);
95 m_dispatchers.push_back(dispatcher);
96}
97
99{
100 QMutexLocker lock(&m_mutex);
101 m_dispatchers.erase(std::find(m_dispatchers.begin(), m_dispatchers.end(), dispatcher));
102}
103
105{
106 QMutexLocker lock(&m_mutex);
107 for (QAndroidEventDispatcher *d : std::as_const(m_dispatchers))
108 d->goingToStop(stop);
109}
static QAndroidEventDispatcherStopper * instance()
void removeEventDispatcher(QAndroidEventDispatcher *dispatcher)
void addEventDispatcher(QAndroidEventDispatcher *dispatcher)
QAndroidEventDispatcher(QObject *parent=nullptr)
bool processEvents(QEventLoop::ProcessEventsFlags flags) override
Processes pending events that match flags until there are no more events to process.
bool testAndSetOrdered(T expectedValue, T newValue) noexcept
void storeRelaxed(T newValue) noexcept
T fetchAndStoreAcquire(T newValue) noexcept
bool testAndSetAcquire(T expectedValue, T newValue) noexcept
T loadRelaxed() const noexcept
void wakeUp() override
\threadsafe
@ ExcludeSocketNotifiers
Definition qeventloop.h:28
@ X11ExcludeTimers
Definition qeventloop.h:30
iterator erase(const_iterator begin, const_iterator end)
Definition qlist.h:889
void push_back(parameter_type t)
Definition qlist.h:675
iterator end()
Definition qlist.h:626
iterator begin()
Definition qlist.h:625
\inmodule QtCore
Definition qmutex.h:313
\inmodule QtCore
Definition qobject.h:103
void acquire(int n=1)
Tries to acquire n resources guarded by the semaphore.
void release(int n=1)
Releases n resources guarded by the semaphore.
bool processEvents(QEventLoop::ProcessEventsFlags flags) override
Processes pending events that match flags until there are no more events to process.
bool blockEventLoopsWhenSuspended()
#define qWarning
Definition qlogging.h:166
GLbitfield flags
QReadWriteLock lock
[0]