90 : m_fd(wl_display_get_fd(wl))
93 , m_wlevqueue(ev_queue)
98 setObjectName(QStringLiteral(
"WaylandEventThread"));
104
105
106
107
108
109
110
111
112 if (m_quitting.loadRelaxed())
116 if (dispatchQueuePending() < 0) {
117 Q_EMIT waylandError();
118 m_quitting.storeRelaxed(
true);
122 wl_display_flush(m_wldisplay);
126 if (m_reading.loadAcquire())
129 if (prepareReadQueue() == 0) {
130 QMutexLocker l(&m_mutex);
131 m_reading.storeRelease(
true);
142 if (m_pipefd[1] != -1 && write(m_pipefd[1],
"\0", 1) == -1)
143 qWarning(
"Failed to write to the pipe: %s.", strerror(errno));
145 m_quitting.storeRelaxed(
true);
165 if (qt_safe_pipe(fds) != 0)
166 qWarning(
"Pipe creation failed. Quitting may hang.");
181 while (waitForReading()) {
182 if (!m_reading.loadRelaxed())
185 pollfd fds[2] = { { m_fd, POLLIN, 0 }, { m_pipefd[0], POLLIN, 0 } };
188 if (fds[1].revents & POLLIN) {
190 wl_display_cancel_read(m_wldisplay);
194 if (fds[0].revents & POLLIN)
195 wl_display_read_events(m_wldisplay);
200 wl_display_cancel_read(m_wldisplay);
205 bool waitForReading()
207 Q_ASSERT(QThread::currentThread() ==
this);
209 m_reading.storeRelease(
false);
211 if (m_mode == SelfDispatch) {
214 Q_EMIT needReadAndDispatch();
216 QMutexLocker lock(&m_mutex);
219 while (!m_reading.loadRelaxed() && !m_quitting.loadRelaxed())
220 m_cond.wait(&m_mutex);
223 return !m_quitting.loadRelaxed();
226 int dispatchQueuePending()
229 return wl_display_dispatch_queue_pending(m_wldisplay, m_wlevqueue);
231 return wl_display_dispatch_pending(m_wldisplay);
234 int prepareReadQueue()
237 return wl_display_prepare_read_queue(m_wldisplay, m_wlevqueue);
239 return wl_display_prepare_read(m_wldisplay);
244 wl_display *m_wldisplay;
245 wl_event_queue *m_wlevqueue;
246 OperatingMode m_mode;
249
250
251
252
253
254
255
257 QAtomicInteger<
bool> m_reading;
258 QAtomicInteger<
bool> m_quitting;
260 QWaitCondition m_cond;