9#include <private/qthread_p.h>
10#include <private/qcoreapplication_p.h>
11#include <private/qfreelist_p.h>
13#include <QtCore/q26numeric.h>
17using namespace std::chrono_literals;
44 Size5 = QtTimerIdFreeListConstants::MaxIndex - Offset5
57Q_GLOBAL_STATIC(QtTimerIdFreeList, timerIdFreeList)
59template <
typename T>
static T fromDuration(std::chrono::nanoseconds interval)
61 using namespace std::chrono;
62 qint64 value = ceil<milliseconds>(interval).count();
63 return q26::saturate_cast<T>(value);
66#if QT_VERSION < QT_VERSION_CHECK(7
, 0
, 0
)
67static inline QAbstractEventDispatcherV2 *v2(QAbstractEventDispatcher *self)
69 if (QAbstractEventDispatcherPrivate::get(self)->isV2)
70 return static_cast<QAbstractEventDispatcherV2 *>(self);
74static inline const QAbstractEventDispatcherV2 *v2(
const QAbstractEventDispatcher *self)
76 if (QAbstractEventDispatcherPrivate::get(self)->isV2)
77 return static_cast<
const QAbstractEventDispatcherV2 *>(self);
82QAbstractEventDispatcherPrivate::QAbstractEventDispatcherPrivate()
87 if (!timerIdFreeList.isDestroyed())
88 (
void)timerIdFreeList();
91QAbstractEventDispatcherPrivate::~QAbstractEventDispatcherPrivate()
94int QAbstractEventDispatcherPrivate::allocateTimerId()
101 if (QtTimerIdFreeList *fl = timerIdFreeList())
106void QAbstractEventDispatcherPrivate::releaseTimerId(
int timerId)
110 if (QtTimerIdFreeList *fl = timerIdFreeList())
111 fl->release(timerId);
115
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
152
153
154
155
156
157
158
159
162
163
164QAbstractEventDispatcher::QAbstractEventDispatcher(QObject *parent)
165 : QObject(*
new QAbstractEventDispatcherPrivate, parent) {}
168
169
170QAbstractEventDispatcher::QAbstractEventDispatcher(QAbstractEventDispatcherPrivate &dd,
172 : QObject(dd, parent) {}
175
176
177QAbstractEventDispatcher::~QAbstractEventDispatcher()
180 QThreadData *data = QThreadData::currentThreadData();
181 if (data && data->eventDispatcher.loadRelaxed() ==
this)
182 data->eventDispatcher.storeRelaxed(
nullptr);
186
187
188
189
190
191
192
193
194QAbstractEventDispatcher *QAbstractEventDispatcher::instance(QThread *thread)
197 QThreadData *data = thread ? QThreadData::get2(thread) : QThreadData::current();
198 return data->eventDispatcher.loadRelaxed();
202
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
234
235
236
237
238
239
240
243
244
245
246
247
248
251
252
253
254
255
256
259
260
261
262
263
264int QAbstractEventDispatcher::registerTimer(qint64 interval, Qt::TimerType timerType, QObject *object)
266 return int(registerTimer(interval * 1ms, timerType, object));
270
271
272
273
274
275
276Qt::TimerId QAbstractEventDispatcher::registerTimer(Duration interval, Qt::TimerType timerType,
279 auto id = Qt::TimerId(QAbstractEventDispatcherPrivate::allocateTimerId());
280#if QT_VERSION < QT_VERSION_CHECK(7
, 0
, 0
)
281 if (QAbstractEventDispatcherV2 *self = v2(
this))
282 self->registerTimer(id, interval, timerType, object);
284 registerTimer(qToUnderlying(id), fromDuration<qint64>(interval), timerType, object);
286 registerTimer(id, interval, timerType, object);
291#if QT_VERSION < QT_VERSION_CHECK(7
, 0
, 0
)
293
294
295
296
297
300
301
302
303
304
305
306
309
310
311
312
313
314
315
318
319
320
321
322
323
324
325
328
329
330
331
332
333
334
335
338
339
340
341
342
343
344
345
348
349
350
351
352
353
354
355
358
359
360
361
362
363
364
365
369
370
371
372
373
374
375
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
396
397
398
399
400
405
406
407void QAbstractEventDispatcher::startingUp()
411
412
413void QAbstractEventDispatcher::closingDown()
417
418
419
420
421
422
423
424
425
426
427
429
430
431
432
434
435
436
437
439
440
441
442
444
445
446
447
448
449
452
453
454
455
456
457
458
459
460
461
463
464
465
466
467
468
470
471
472
473
475
476
477
478
479
480
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507void QAbstractEventDispatcher::installNativeEventFilter(QAbstractNativeEventFilter *filterObj)
509 Q_D(QAbstractEventDispatcher);
512 d->eventFilters.removeAll(
nullptr);
513 d->eventFilters.removeAll(filterObj);
514 d->eventFilters.prepend(filterObj);
518
519
520
521
522
523
524
525
526
527
528
529
530void QAbstractEventDispatcher::removeNativeEventFilter(QAbstractNativeEventFilter *filter)
532 Q_D(QAbstractEventDispatcher);
533 for (
int i = 0; i < d->eventFilters.size(); ++i) {
534 if (d->eventFilters.at(i) == filter) {
535 d->eventFilters[i] =
nullptr;
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560bool QAbstractEventDispatcher::filterNativeEvent(
const QByteArray &eventType,
void *message, qintptr *result)
562 Q_D(QAbstractEventDispatcher);
563 if (!d->eventFilters.isEmpty()) {
566 QScopedScopeLevelCounter scopeLevelCounter(d->threadData.loadAcquire());
567 for (
int i = 0; i < d->eventFilters.size(); ++i) {
568 QAbstractNativeEventFilter *filter = d->eventFilters.at(i);
571 if (filter->nativeEventFilter(eventType, message, result))
579
580
581
582
583
584
587
588
589
590
591
592
594#if QT_VERSION < QT_VERSION_CHECK(7
, 0
, 0
)
595void QAbstractEventDispatcher::registerTimer(Qt::TimerId timerId, Duration interval,
596 Qt::TimerType timerType, QObject *object)
598 if (QAbstractEventDispatcherV2 *self = v2(
this))
599 self->registerTimer(timerId, interval, timerType, object);
601 registerTimer(
int(timerId), fromDuration<qint64>(interval), timerType, object);
604bool QAbstractEventDispatcher::unregisterTimer(Qt::TimerId timerId)
606 if (QAbstractEventDispatcherV2 *self = v2(
this))
607 return self->unregisterTimer(timerId);
608 return unregisterTimer(
int(timerId));
611QList<QAbstractEventDispatcher::TimerInfoV2>
612QAbstractEventDispatcher::timersForObject(QObject *object)
const
614 if (
const QAbstractEventDispatcherV2 *self = v2(
this))
615 return self->timersForObject(object);
616 QList<TimerInfo> timers = registeredTimers(object);
617 QList<TimerInfoV2> result;
618 result.reserve(timers.size());
619 for (
const TimerInfo &t : timers)
620 result.emplaceBack(TimerInfoV2{ t.interval * 1ms, Qt::TimerId(t.timerId), t.timerType });
624QAbstractEventDispatcher::Duration
625QAbstractEventDispatcher::remainingTime(Qt::TimerId timerId)
const
627 if (
const QAbstractEventDispatcherV2 *self = v2(
this))
628 return self->remainingTime(timerId);
629 return const_cast<QAbstractEventDispatcher *>(
this)->remainingTime(
int(timerId)) * 1ms;
633
634
635
636
637
638
639
640
641
642
643
646
647
648QAbstractEventDispatcherV2::QAbstractEventDispatcherV2(QObject *parent)
649 : QAbstractEventDispatcherV2(*
new QAbstractEventDispatcherPrivate, parent)
654
655
656QAbstractEventDispatcherV2::QAbstractEventDispatcherV2(QAbstractEventDispatcherPrivate &dd,
658 : QAbstractEventDispatcher((dd.isV2 =
true, dd), parent)
663
664
665QAbstractEventDispatcherV2::~QAbstractEventDispatcherV2() =
default;
668
669
670
671void QAbstractEventDispatcherV2::registerTimer(
int timerId, qint64 interval,
672 Qt::TimerType timerType, QObject *object)
674 auto self =
static_cast<QAbstractEventDispatcherV2 *>(
this);
675 self->registerTimer(Qt::TimerId(timerId), interval * 1ms, timerType, object);
679
680
681
682bool QAbstractEventDispatcherV2::unregisterTimer(
int timerId)
684 auto self =
static_cast<QAbstractEventDispatcherV2 *>(
this);
685 return self->unregisterTimer(Qt::TimerId(timerId));
689
690
691
692auto QAbstractEventDispatcherV2::registeredTimers(QObject *object)
const -> QList<TimerInfo>
694 auto self =
static_cast<
const QAbstractEventDispatcherV2 *>(
this);
695 QList<TimerInfoV2> timers = self->timersForObject(object);
696 QList<TimerInfo> result;
697 result.reserve(timers.size());
698 for (
const TimerInfoV2 &t : timers)
699 result.emplaceBack(qToUnderlying(t.timerId), fromDuration<
int>(t.interval), t.timerType);
704
705
706
707int QAbstractEventDispatcherV2::remainingTime(
int timerId)
709 auto self =
static_cast<QAbstractEventDispatcherV2 *>(
this);
710 return fromDuration<
int>(self->remainingTime(Qt::TimerId(timerId)));
714
715
716
717bool QAbstractEventDispatcherV2::processEventsWithDeadline(QEventLoop::ProcessEventsFlags flags, QDeadlineTimer deadline)
720 return processEvents(flags);
726#include "moc_qabstracteventdispatcher.cpp"
QFreeList< void, QtTimerIdFreeListConstants > QtTimerIdFreeList
static const int Sizes[BlockCount]