7#include <private/qnumeric_p.h>
8#include <private/qthread_p.h>
13#include <QtCore/qlist.h>
17using namespace std::chrono;
18using namespace std::chrono_literals;
31 QList<GPollFDWithQSocketNotifier *>
pollfds;
50 if (
p->pollfd.revents & G_IO_NVAL) {
52 const char *
const t[] = {
"Read",
"Write",
"Exception" };
53 qWarning(
"QSocketNotifier: Invalid socket %d and type '%s', disabling...",
54 p->pollfd.fd,
t[
int(
p->socketNotifier->type())]);
56 p->socketNotifier->setEnabled(
false);
71 for (
src->activeNotifierPos = 0;
src->activeNotifierPos <
src->pollfds.size();
72 ++
src->activeNotifierPos) {
75 if ((
p->pollfd.revents &
p->pollfd.events) != 0)
106 auto remaining =
src->timerList.timerWait().value_or(-1ms);
107 *
timeout = qt_saturate<gint>(ceil<milliseconds>(remaining).
count());
114 if (
src->timerList.isEmpty()
118 return !
src->timerList.hasPendingTimers();
128 if (
src->runWithIdlePriority) {
140 if (
src->runWithIdlePriority)
228 const bool canWait =
data->canWaitLocked();
233 return !canWait ||
source->d->wakeUpCalled;
246 source->d->runTimersOnceWithNormalPriority();
263#if GLIB_MAJOR_VERSION == 2 && GLIB_MINOR_VERSION < 32
267 if (!g_thread_supported())
284#if GLIB_CHECK_VERSION (2, 22, 0)
290 g_source_set_name(
source,
"[Qt] GPostEventSource");
300 g_source_set_name(
source,
"[Qt] GSocketNotifierSource");
308 g_source_set_name(
source,
"[Qt] GTimerSource");
317 g_source_set_name(
source,
"[Qt] GIdleTimerSource");
343 d->timerSource->timerList.clearTimers();
344 d->timerSource->timerList.~QTimerInfoList();
345 g_source_destroy(&
d->timerSource->source);
346 g_source_unref(&
d->timerSource->source);
347 d->timerSource =
nullptr;
348 g_source_destroy(&
d->idleTimerSource->source);
349 g_source_unref(&
d->idleTimerSource->source);
350 d->idleTimerSource =
nullptr;
353 for (
int i = 0;
i <
d->socketNotifierSource->pollfds.size(); ++
i) {
355 g_source_remove_poll(&
d->socketNotifierSource->source, &
p->pollfd);
359 g_source_destroy(&
d->socketNotifierSource->source);
360 g_source_unref(&
d->socketNotifierSource->source);
361 d->socketNotifierSource =
nullptr;
364 g_source_destroy(&
d->postEventSource->source);
365 g_source_unref(&
d->postEventSource->source);
366 d->postEventSource =
nullptr;
369#if GLIB_CHECK_VERSION (2, 22, 0)
370 g_main_context_pop_thread_default (
d->mainContext);
372 g_main_context_unref(
d->mainContext);
373 d->mainContext =
nullptr;
387 QEventLoop::ProcessEventsFlags savedFlags =
d->timerSource->processEventsFlags;
388 d->timerSource->processEventsFlags =
flags;
392 d->timerSource->runWithIdlePriority =
false;
395 bool result = g_main_context_iteration(
d->mainContext, canWait);
396 while (!
result && canWait)
397 result = g_main_context_iteration(
d->mainContext, canWait);
399 d->timerSource->processEventsFlags = savedFlags;
410 int sockfd = int(
notifier->socket());
414 qWarning(
"QSocketNotifier: Internal error");
418 qWarning(
"QSocketNotifier: socket notifiers cannot be enabled from another thread");
430 p->pollfd.events = G_IO_IN | G_IO_HUP | G_IO_ERR;
433 p->pollfd.events = G_IO_OUT | G_IO_ERR;
436 p->pollfd.events = G_IO_PRI | G_IO_ERR;
441 d->socketNotifierSource->pollfds.append(
p);
443 g_source_add_poll(&
d->socketNotifierSource->source, &
p->pollfd);
451 qWarning(
"QSocketNotifier: Internal error");
455 qWarning(
"QSocketNotifier: socket notifiers cannot be disabled from another thread");
462 for (
int i = 0;
i <
d->socketNotifierSource->pollfds.size(); ++
i) {
466 g_source_remove_poll(&
d->socketNotifierSource->source, &
p->pollfd);
468 d->socketNotifierSource->pollfds.removeAt(
i);
472 if (i <= d->socketNotifierSource->activeNotifierPos)
473 --
d->socketNotifierSource->activeNotifierPos;
485 qWarning(
"QEventDispatcherGlib::registerTimer: invalid arguments");
488 qWarning(
"QEventDispatcherGlib::registerTimer: timers cannot be started from another thread");
494 d->timerSource->timerList.registerTimer(timerId, interval, timerType,
object);
501 qWarning(
"QEventDispatcherGlib::unregisterTimer: invalid argument");
504 qWarning(
"QEventDispatcherGlib::unregisterTimer: timers cannot be stopped from another thread");
510 return d->timerSource->timerList.unregisterTimer(timerId);
517 qWarning(
"QEventDispatcherGlib::unregisterTimers: invalid argument");
520 qWarning(
"QEventDispatcherGlib::unregisterTimers: timers cannot be stopped from another thread");
526 return d->timerSource->timerList.unregisterTimers(
object);
533 qWarning(
"QEventDispatcherGlib:timersForObject: invalid argument");
539 return d->timerSource->timerList.registeredTimers(
object);
546 qWarning(
"QEventDispatcherGlib::remainingTimeTime: invalid argument");
547 return Duration::min();
552 return d->timerSource->timerList.remainingDuration(timerId);
563 d->postEventSource->serialNumber.ref();
564 g_main_context_wakeup(
d->mainContext);
569#if !defined(GLIB_MAJOR_VERSION) || !defined(GLIB_MINOR_VERSION) || !defined(GLIB_MICRO_VERSION)
572 return ((GLIB_MAJOR_VERSION << 16) + (GLIB_MINOR_VERSION << 8) + GLIB_MICRO_VERSION) >= 0x020301;
583#include "moc_qeventdispatcher_glib_p.cpp"
DarwinBluetooth::LECBManagerNotifier * notifier
void aboutToBlock()
This signal is emitted before the event loop calls a function that could block.
std::chrono::nanoseconds Duration
A {std::chrono::duration} type that is used in various API in this class.
void awake()
This signal is emitted after the event loop returns from a function that could block.
void storeRelaxed(T newValue) noexcept
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
static QCoreApplication * instance() noexcept
Returns a pointer to the application's QCoreApplication (or QGuiApplication/QApplication) instance.
static void sendPostedEvents(QObject *receiver=nullptr, int event_type=0)
Immediately dispatches all events which have been previously queued with QCoreApplication::postEvent(...
GSocketNotifierSource * socketNotifierSource
QEventDispatcherGlibPrivate(GMainContext *context=nullptr)
GPostEventSource * postEventSource
GTimerSource * timerSource
void runTimersOnceWithNormalPriority()
GIdleTimerSource * idleTimerSource
GMainContext * mainContext
void unregisterSocketNotifier(QSocketNotifier *socketNotifier) final
Unregisters notifier from the event dispatcher.
void wakeUp() final
\threadsafe
bool unregisterTimers(QObject *object) override final
Unregisters all the timers associated with the given object.
void registerSocketNotifier(QSocketNotifier *socketNotifier) final
Registers notifier with the event loop.
static bool versionSupported()
bool processEvents(QEventLoop::ProcessEventsFlags flags) override
Processes pending events that match flags until there are no more events to process.
QList< TimerInfoV2 > timersForObject(QObject *object) const override final
Duration remainingTime(Qt::TimerId timerId) const override final
Returns the remaining time of the timer with the given timerId.
void registerTimer(Qt::TimerId timerId, Duration interval, Qt::TimerType timerType, QObject *object) override final
QEventDispatcherGlib(QObject *parent=nullptr)
bool unregisterTimer(Qt::TimerId timerId) override final
void interrupt() final
Interrupts event dispatching.
QThread * thread() const
Returns the thread in which the object lives.
static Q_AUTOTEST_EXPORT QThreadData * current(bool createIfNecessary=true)
static QThread * currentThread()
static gboolean timerSourcePrepareHelper(GTimerSource *src, gint *timeout)
static gboolean postEventSourceDispatch(GSource *s, GSourceFunc, gpointer)
static gboolean timerSourceCheck(GSource *source)
static gboolean idleTimerSourcePrepare(GSource *source, gint *timeout)
static gboolean socketNotifierSourcePrepare(GSource *, gint *timeout)
static gboolean idleTimerSourceDispatch(GSource *source, GSourceFunc, gpointer)
static gboolean postEventSourcePrepare(GSource *s, gint *timeout)
static Q_CONSTINIT GSourceFuncs postEventSourceFuncs
static gboolean idleTimerSourceCheck(GSource *source)
static gboolean timerSourceCheckHelper(GTimerSource *src)
static gboolean socketNotifierSourceCheck(GSource *source)
static gboolean postEventSourceCheck(GSource *source)
static gboolean socketNotifierSourceDispatch(GSource *source, GSourceFunc, gpointer)
static gboolean timerSourcePrepare(GSource *source, gint *timeout)
static gboolean timerSourceDispatch(GSource *source, GSourceFunc, gpointer)
static Q_CONSTINIT GSourceFuncs timerSourceFuncs
static Q_CONSTINIT GSourceFuncs socketNotifierSourceFuncs
static Q_CONSTINIT GSourceFuncs idleTimerSourceFuncs
struct _GMainContext GMainContext
Combined button and popup list for selecting options.
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char return DBusMessage return DBusMessage const char return DBusMessage dbus_bool_t return DBusMessage dbus_uint32_t return DBusMessage void
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char return DBusMessage return DBusMessage const char return DBusMessage dbus_bool_t return DBusMessage dbus_uint32_t return DBusMessage return DBusPendingCall * pending
GLenum GLenum GLsizei count
GLbitfield GLuint64 timeout
[4]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLsizei GLsizei GLchar * source
Q_CORE_EXPORT bool qEnvironmentVariableIsEmpty(const char *varName) noexcept
QT_BEGIN_NAMESPACE constexpr std::underlying_type_t< Enum > qToUnderlying(Enum e) noexcept
QApplication app(argc, argv)
[0]
GTimerSource * timerSource
QSocketNotifier * socketNotifier
QEventDispatcherGlibPrivate * d
QList< GPollFDWithQSocketNotifier * > pollfds
QEventLoop::ProcessEventsFlags processEventsFlags