10#include <private/qthread_p.h>
11#include <private/qcoreapplication_p.h>
12#include <private/qfreelist_p.h>
14#include <QtCore/q26numeric.h>
18using namespace std::chrono_literals;
45 Size5 = QtTimerIdFreeListConstants::MaxIndex - Offset5
58Q_GLOBAL_STATIC(QtTimerIdFreeList, timerIdFreeList)
60template <
typename T>
static T fromDuration(std::chrono::nanoseconds interval)
62 using namespace std::chrono;
63 qint64 value = ceil<milliseconds>(interval).count();
64 return q26::saturate_cast<T>(value);
67#if QT_VERSION < QT_VERSION_CHECK(7
, 0
, 0
)
68static inline QAbstractEventDispatcherV2 *v2(QAbstractEventDispatcher *self)
70 if (QAbstractEventDispatcherPrivate::get(self)->isV2)
71 return static_cast<QAbstractEventDispatcherV2 *>(self);
75static inline const QAbstractEventDispatcherV2 *v2(
const QAbstractEventDispatcher *self)
77 if (QAbstractEventDispatcherPrivate::get(self)->isV2)
78 return static_cast<
const QAbstractEventDispatcherV2 *>(self);
83QAbstractEventDispatcherPrivate::QAbstractEventDispatcherPrivate()
88 if (!timerIdFreeList.isDestroyed())
89 (
void)timerIdFreeList();
92QAbstractEventDispatcherPrivate::~QAbstractEventDispatcherPrivate()
95Qt::TimerId QAbstractEventDispatcherPrivate::allocateTimerId()
102 if (QtTimerIdFreeList *fl = timerIdFreeList())
103 return Qt::TimerId{fl->next()};
104 return Qt::TimerId{0};
107void QAbstractEventDispatcherPrivate::releaseTimerId(Qt::TimerId timerId)
111 if (QtTimerIdFreeList *fl = timerIdFreeList())
112 fl->release(qToUnderlying(timerId));
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
153
154
155
156
157
158
159
160
163
164
165QAbstractEventDispatcher::QAbstractEventDispatcher(QObject *parent)
166 : QObject(*
new QAbstractEventDispatcherPrivate, parent) {}
169
170
171QAbstractEventDispatcher::QAbstractEventDispatcher(QAbstractEventDispatcherPrivate &dd,
173 : QObject(dd, parent) {}
176
177
178QAbstractEventDispatcher::~QAbstractEventDispatcher()
181 QThreadData *data = QThreadData::currentThreadData();
182 if (data && data->eventDispatcher.loadRelaxed() ==
this)
183 data->eventDispatcher.storeRelaxed(
nullptr);
187
188
189
190
191
192
193
194
195QAbstractEventDispatcher *QAbstractEventDispatcher::instance(QThread *thread)
198 QThreadData *data = thread ? QThreadData::get2(thread) : QThreadData::current();
199 return data->eventDispatcher.loadRelaxed();
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
235
236
237
238
239
240
241
244
245
246
247
248
249
252
253
254
255
256
257
260
261
262
263
264
265int QAbstractEventDispatcher::registerTimer(qint64 interval, Qt::TimerType timerType, QObject *object)
267 return int(registerTimer(interval * 1ms, timerType, object));
271
272
273
274
275
276
277Qt::TimerId QAbstractEventDispatcher::registerTimer(Duration interval, Qt::TimerType timerType,
280 auto id = QAbstractEventDispatcherPrivate::allocateTimerId();
281#if QT_VERSION < QT_VERSION_CHECK(7
, 0
, 0
)
282 if (QAbstractEventDispatcherV2 *self = v2(
this))
283 self->registerTimer(id, interval, timerType, object);
285 registerTimer(qToUnderlying(id), fromDuration<qint64>(interval), timerType, object);
287 registerTimer(id, interval, timerType, object);
292#if QT_VERSION < QT_VERSION_CHECK(7
, 0
, 0
)
294
295
296
297
298
301
302
303
304
305
306
307
310
311
312
313
314
315
316
319
320
321
322
323
324
325
326
329
330
331
332
333
334
335
336
339
340
341
342
343
344
345
346
349
350
351
352
353
354
355
356
359
360
361
362
363
364
365
366
370
371
372
373
374
375
376
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
397
398
399
400
401
406
407
408void QAbstractEventDispatcher::startingUp()
412
413
414void QAbstractEventDispatcher::closingDown()
418
419
420
421
422
423
424
425
426
427
428
430
431
432
433
435
436
437
438
440
441
442
443
445
446
447
448
449
450
453
454
455
456
457
458
459
460
461
462
464
465
466
467
468
469
471
472
473
474
476
477
478
479
480
481
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508void QAbstractEventDispatcher::installNativeEventFilter(QAbstractNativeEventFilter *filterObj)
510 Q_D(QAbstractEventDispatcher);
513 d->eventFilters.removeAll(
nullptr);
514 d->eventFilters.removeAll(filterObj);
515 d->eventFilters.prepend(filterObj);
519
520
521
522
523
524
525
526
527
528
529
530
531void QAbstractEventDispatcher::removeNativeEventFilter(QAbstractNativeEventFilter *filter)
533 Q_D(QAbstractEventDispatcher);
534 if (
const auto idx = d->eventFilters.indexOf(filter); idx >= 0)
535 d->eventFilters[idx] =
nullptr;
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557bool QAbstractEventDispatcher::filterNativeEvent(
const QByteArray &eventType,
void *message, qintptr *result)
559 Q_D(QAbstractEventDispatcher);
560 if (!d->eventFilters.isEmpty()) {
563 QScopedScopeLevelCounter scopeLevelCounter(d->threadData.loadAcquire());
564 for (qsizetype i = 0; i < d->eventFilters.size(); ++i) {
565 QAbstractNativeEventFilter *filter = d->eventFilters.at(i);
568 if (filter->nativeEventFilter(eventType, message, result))
576
577
578
579
580
581
584
585
586
587
588
589
591#if QT_VERSION < QT_VERSION_CHECK(7
, 0
, 0
)
592void QAbstractEventDispatcher::registerTimer(Qt::TimerId timerId, Duration interval,
593 Qt::TimerType timerType, QObject *object)
595 if (QAbstractEventDispatcherV2 *self = v2(
this))
596 self->registerTimer(timerId, interval, timerType, object);
598 registerTimer(
int(timerId), fromDuration<qint64>(interval), timerType, object);
601bool QAbstractEventDispatcher::unregisterTimer(Qt::TimerId timerId)
603 if (QAbstractEventDispatcherV2 *self = v2(
this))
604 return self->unregisterTimer(timerId);
605 return unregisterTimer(
int(timerId));
608QList<QAbstractEventDispatcher::TimerInfoV2>
609QAbstractEventDispatcher::timersForObject(QObject *object)
const
611 if (
const QAbstractEventDispatcherV2 *self = v2(
this))
612 return self->timersForObject(object);
613 QList<TimerInfo> timers = registeredTimers(object);
614 QList<TimerInfoV2> result;
615 result.reserve(timers.size());
616 for (
const TimerInfo &t : timers)
617 result.emplaceBack(TimerInfoV2{ t.interval * 1ms, Qt::TimerId(t.timerId), t.timerType });
621QAbstractEventDispatcher::Duration
622QAbstractEventDispatcher::remainingTime(Qt::TimerId timerId)
const
624 if (
const QAbstractEventDispatcherV2 *self = v2(
this))
625 return self->remainingTime(timerId);
626 return const_cast<QAbstractEventDispatcher *>(
this)->remainingTime(
int(timerId)) * 1ms;
630
631
632
633
634
635
636
637
638
639
640
643
644
645QAbstractEventDispatcherV2::QAbstractEventDispatcherV2(QObject *parent)
646 : QAbstractEventDispatcherV2(*
new QAbstractEventDispatcherPrivate, parent)
651
652
653QAbstractEventDispatcherV2::QAbstractEventDispatcherV2(QAbstractEventDispatcherPrivate &dd,
655 : QAbstractEventDispatcher((dd.isV2 =
true, dd), parent)
660
661
662QAbstractEventDispatcherV2::~QAbstractEventDispatcherV2() =
default;
665
666
667
668void QAbstractEventDispatcherV2::registerTimer(
int timerId, qint64 interval,
669 Qt::TimerType timerType, QObject *object)
671 auto self =
static_cast<QAbstractEventDispatcherV2 *>(
this);
672 self->registerTimer(Qt::TimerId(timerId), interval * 1ms, timerType, object);
676
677
678
679bool QAbstractEventDispatcherV2::unregisterTimer(
int timerId)
681 auto self =
static_cast<QAbstractEventDispatcherV2 *>(
this);
682 return self->unregisterTimer(Qt::TimerId(timerId));
686
687
688
689auto QAbstractEventDispatcherV2::registeredTimers(QObject *object)
const -> QList<TimerInfo>
691 auto self =
static_cast<
const QAbstractEventDispatcherV2 *>(
this);
692 QList<TimerInfoV2> timers = self->timersForObject(object);
693 QList<TimerInfo> result;
694 result.reserve(timers.size());
695 for (
const TimerInfoV2 &t : timers)
696 result.emplaceBack(qToUnderlying(t.timerId), fromDuration<
int>(t.interval), t.timerType);
701
702
703
704int QAbstractEventDispatcherV2::remainingTime(
int timerId)
706 auto self =
static_cast<QAbstractEventDispatcherV2 *>(
this);
707 return fromDuration<
int>(self->remainingTime(Qt::TimerId(timerId)));
711
712
713
714bool QAbstractEventDispatcherV2::processEventsWithDeadline(QEventLoop::ProcessEventsFlags flags, QDeadlineTimer deadline)
717 return processEvents(flags);
723#include "moc_qabstracteventdispatcher.cpp"
Combined button and popup list for selecting options.
QFreeList< void, QtTimerIdFreeListConstants > QtTimerIdFreeList
static const int Sizes[BlockCount]