42 #include "qplatformdefs.h" 45 #include "private/qeventdispatcher_unix_p.h" 49 #include <QWindowSystemInterface> 50 #include <QtCore/QElapsedTimer> 51 #include <QtCore/QAtomicInt> 52 #include <QtCore/QSemaphore> 54 #include <QtCore/QDebug> 86 m_edPrivate(eventDispatcherPrivate),
91 void setSelectValues(
int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds)
95 m_writefds = writefds;
96 m_exceptfds = exceptfds;
121 : eventLoopIntegration(0),
122 barrierBeforeBlocking(0),
123 barrierReturnValue(0),
124 selectReturnMutex(0),
125 selectWorkerNeedsSync(true),
126 selectWorkerHasResult(false),
128 m_integrationInitialised(false),
129 m_hasIntegration(false),
130 m_isEventLoopIntegrationRunning(false)
138 delete eventLoopIntegration;
139 delete barrierBeforeBlocking;
140 delete barrierReturnValue;
141 delete selectReturnMutex;
146 if (!m_integrationInitialised) {
149 if (QApplicationPrivate::platformIntegration()) {
150 that->
eventLoopIntegration = QApplicationPrivate::platformIntegration()->createEventLoopIntegration();
159 qWarning(
"Having eventloop integration without monotonic timers can lead to undefined behaviour");
165 return m_hasIntegration;
170 return m_isEventLoopIntegrationRunning;
176 m_isEventLoopIntegrationRunning =
true;
177 eventLoopIntegration->startEventLoop();
207 if (
d->hasIntegration()) {
208 if (!
d->isEventLoopIntegrationRunning()) {
209 d->runEventLoopIntegration();
211 if (
d->threadData->quitNow) {
212 d->eventLoopIntegration->quitEventLoop();
220 d->interrupt =
false;
223 while (!
d->interrupt) {
241 QApplicationPrivate::processWindowSystemEvent(event);
250 return (nevents > 0);
263 if (
d->hasIntegration())
272 if (
d->hasIntegration())
279 qApp->sendPostedEvents();
287 if (
d->hasIntegration()) {
288 qint64 timeoutmsec = LONG_MAX;
290 timeoutmsec = timeout->tv_sec * 1000 + (timeout->tv_usec/1000);
291 d->selectReturnMutex->lock();
292 if (
d->selectWorkerNeedsSync) {
293 if (
d->selectWorkerHasResult) {
294 retVal =
d->selectWorker->retVal();
295 d->selectWorkerHasResult =
false;
297 d->selectReturnMutex->unlock();
298 d->barrierReturnValue->checkpoint();
299 d->eventLoopIntegration->setNextTimerEvent(0);
302 d->selectWorkerNeedsSync =
false;
303 d->selectWorker->setSelectValues(nfds,readfds, writefds, exceptfds);
304 d->barrierBeforeBlocking->checkpoint();
307 d->selectReturnMutex->unlock();
308 d->eventLoopIntegration->setNextTimerEvent(timeoutmsec);
322 m_edPrivate->barrierBeforeBlocking->checkpoint();
323 int tmpRet =
qt_safe_select(m_nfds,m_readfds,m_writefds,m_exceptfds,0);
324 m_edPrivate->selectReturnMutex->lock();
325 m_edPrivate->eventLoopIntegration->qtNeedsToProcessEvents();
327 m_edPrivate->selectWorkerNeedsSync =
true;
328 m_edPrivate->selectWorkerHasResult =
true;
331 m_edPrivate->selectReturnMutex->unlock();
332 m_edPrivate->barrierReturnValue->checkpoint();
int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, timeval *timeout)
bool hasIntegration() const
QEventDispatcherQPA(QObject *parent=0)
bool filterEvent(void *message)
Sends message through the event filter that was set by setEventFilter().
#define QT_END_NAMESPACE
This macro expands to.
The QSemaphore class provides a general counting semaphore.
The QMutex class provides access serialization between threads.
The QAtomicInt class provides platform-independent atomic operations on integers. ...
~QEventDispatcherQPAPrivate()
bool testAndSetAcquire(int expectedValue, int newValue)
Atomic test-and-set.
bool isEventLoopIntegrationRunning() const
QMutex * selectReturnMutex
QEventDispatcherQPAPrivate * m_edPrivate
void unregisterSocketNotifier(QSocketNotifier *notifier)
Unregisters notifier from the event dispatcher.
void release(int n=1)
Releases n resources guarded by the semaphore.
Rendezvous * barrierBeforeBlocking
void registerSocketNotifier(QSocketNotifier *notifier)
Registers notifier with the event loop.
The QObject class is the base class of all Qt objects.
virtual bool event(QEvent *)
This virtual function receives events to an object and should return true if the event e was recogniz...
static bool isMonotonic()
Returns true if this is a monotonic clock, false otherwise.
The QSocketNotifier class provides support for monitoring activity on a file descriptor.
void registerSocketNotifier(QSocketNotifier *notifier)
Registers notifier with the event loop.
static int windowSystemEventsQueued()
static QThread * currentThread()
Returns a pointer to a QThread which manages the currently executing thread.
#define QT_BEGIN_NAMESPACE
This macro expands to.
bool selectWorkerHasResult
bool m_isEventLoopIntegrationRunning
bool m_integrationInitialised
Q_CORE_EXPORT void qWarning(const char *,...)
bool processEvents(QEventLoop::ProcessEventsFlags flags)
Processes pending events that match flags until there are no more events to process.
bool hasPendingEvents()
Returns true if there is an event waiting; otherwise returns false.
static void sendPostedEvents()
QEventDispatcherQPAPrivate()
Q_CORE_EXPORT uint qGlobalPostedEventsCount()
void wakeUp()
Wakes up the event loop.
void acquire(int n=1)
Tries to acquire n resources guarded by the semaphore.
void flush()
Flushes the event queue.
#define Q_DECLARE_PUBLIC(Class)
static WindowSystemEvent * getWindowSystemEvent()
int qt_safe_select(int nfds, fd_set *fdread, fd_set *fdwrite, fd_set *fdexcept, const struct timeval *orig_timeout)
void start(Priority=InheritPriority)
Begins execution of the thread by calling run().
void run()
The starting point for the thread.
bool processEvents(QEventLoop::ProcessEventsFlags flags)
Processes pending events that match flags until there are no more events to process.
void runEventLoopIntegration()
virtual int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, timeval *timeout)
#define QT_USE_NAMESPACE
This macro expands to using QT_NAMESPACE if QT_NAMESPACE is defined and nothing otherwise.
QFuture< T > run(Function function,...)
void setSelectValues(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds)
QPlatformEventLoopIntegration * eventLoopIntegration
bool selectWorkerNeedsSync
The QThread class provides a platform-independent way to manage threads.
Rendezvous * barrierReturnValue
void unregisterSocketNotifier(QSocketNotifier *notifier)
Unregisters notifier from the event dispatcher.
SelectWorker * selectWorker
bool testAndSetOrdered(int expectedValue, int newValue)
Atomic test-and-set.
SelectWorker(QEventDispatcherQPAPrivate *eventDispatcherPrivate)