89 : m_fd(wl_display_get_fd(wl))
92 , m_wlevqueue(ev_queue)
97 setObjectName(QStringLiteral(
"WaylandEventThread"));
103
104
105
106
107
108
109
110
111 if (m_quitting.loadRelaxed())
115 if (dispatchQueuePending() < 0) {
116 Q_EMIT waylandError();
117 m_quitting.storeRelaxed(
true);
121 wl_display_flush(m_wldisplay);
125 if (m_reading.loadAcquire())
128 if (prepareReadQueue() == 0) {
129 QMutexLocker l(&m_mutex);
130 m_reading.storeRelease(
true);
141 if (m_pipefd[1] != -1 && write(m_pipefd[1],
"\0", 1) == -1)
142 qWarning(
"Failed to write to the pipe: %s.", strerror(errno));
144 m_quitting.storeRelaxed(
true);
164 if (qt_safe_pipe(fds) != 0)
165 qWarning(
"Pipe creation failed. Quitting may hang.");
180 while (waitForReading()) {
181 if (!m_reading.loadRelaxed())
184 pollfd fds[2] = { { m_fd, POLLIN, 0 }, { m_pipefd[0], POLLIN, 0 } };
187 if (fds[1].revents & POLLIN) {
189 wl_display_cancel_read(m_wldisplay);
193 if (fds[0].revents & POLLIN)
194 wl_display_read_events(m_wldisplay);
199 wl_display_cancel_read(m_wldisplay);
204 bool waitForReading()
206 Q_ASSERT(QThread::currentThread() ==
this);
208 m_reading.storeRelease(
false);
210 if (m_mode == SelfDispatch) {
213 Q_EMIT needReadAndDispatch();
215 QMutexLocker lock(&m_mutex);
218 while (!m_reading.loadRelaxed() && !m_quitting.loadRelaxed())
219 m_cond.wait(&m_mutex);
222 return !m_quitting.loadRelaxed();
225 int dispatchQueuePending()
228 return wl_display_dispatch_queue_pending(m_wldisplay, m_wlevqueue);
230 return wl_display_dispatch_pending(m_wldisplay);
233 int prepareReadQueue()
236 return wl_display_prepare_read_queue(m_wldisplay, m_wlevqueue);
238 return wl_display_prepare_read(m_wldisplay);
243 wl_display *m_wldisplay;
244 wl_event_queue *m_wlevqueue;
245 OperatingMode m_mode;
248
249
250
251
252
253
254
256 QAtomicInteger<
bool> m_reading;
257 QAtomicInteger<
bool> m_quitting;
259 QWaitCondition m_cond;