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
444
445
448
449
450
451
452
453
454
455
456
457
459
460
461
462
463
464
466
467
468
469
471
472
473
474
475
476
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503void QAbstractEventDispatcher::installNativeEventFilter(QAbstractNativeEventFilter *filterObj)
505 Q_D(QAbstractEventDispatcher);
508 d->eventFilters.removeAll(
nullptr);
509 d->eventFilters.removeAll(filterObj);
510 d->eventFilters.prepend(filterObj);
514
515
516
517
518
519
520
521
522
523
524
525
526void QAbstractEventDispatcher::removeNativeEventFilter(QAbstractNativeEventFilter *filter)
528 Q_D(QAbstractEventDispatcher);
529 if (
const auto idx = d->eventFilters.indexOf(filter); idx >= 0)
530 d->eventFilters[idx] =
nullptr;
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552bool QAbstractEventDispatcher::filterNativeEvent(
const QByteArray &eventType,
void *message, qintptr *result)
554 Q_D(QAbstractEventDispatcher);
555 if (!d->eventFilters.isEmpty()) {
558 QScopedScopeLevelCounter scopeLevelCounter(d->threadData.loadAcquire());
559 for (qsizetype i = 0; i < d->eventFilters.size(); ++i) {
560 QAbstractNativeEventFilter *filter = d->eventFilters.at(i);
563 if (filter->nativeEventFilter(eventType, message, result))
571
572
573
574
575
576
579
580
581
582
583
584
586#if QT_VERSION < QT_VERSION_CHECK(7
, 0
, 0
)
587void QAbstractEventDispatcher::registerTimer(Qt::TimerId timerId, Duration interval,
588 Qt::TimerType timerType, QObject *object)
590 if (QAbstractEventDispatcherV2 *self = v2(
this))
591 self->registerTimer(timerId, interval, timerType, object);
593 registerTimer(
int(timerId), fromDuration<qint64>(interval), timerType, object);
596bool QAbstractEventDispatcher::unregisterTimer(Qt::TimerId timerId)
598 if (QAbstractEventDispatcherV2 *self = v2(
this))
599 return self->unregisterTimer(timerId);
600 return unregisterTimer(
int(timerId));
603QList<QAbstractEventDispatcher::TimerInfoV2>
604QAbstractEventDispatcher::timersForObject(QObject *object)
const
606 if (
const QAbstractEventDispatcherV2 *self = v2(
this))
607 return self->timersForObject(object);
608 QList<TimerInfo> timers = registeredTimers(object);
609 QList<TimerInfoV2> result;
610 result.reserve(timers.size());
611 for (
const TimerInfo &t : timers)
612 result.emplaceBack(TimerInfoV2{ t.interval * 1ms, Qt::TimerId(t.timerId), t.timerType });
616QAbstractEventDispatcher::Duration
617QAbstractEventDispatcher::remainingTime(Qt::TimerId timerId)
const
619 if (
const QAbstractEventDispatcherV2 *self = v2(
this))
620 return self->remainingTime(timerId);
621 return const_cast<QAbstractEventDispatcher *>(
this)->remainingTime(
int(timerId)) * 1ms;
625
626
627
628
629
630
631
632
633
634
635
638
639
640QAbstractEventDispatcherV2::QAbstractEventDispatcherV2(QObject *parent)
641 : QAbstractEventDispatcherV2(*
new QAbstractEventDispatcherPrivate, parent)
646
647
648QAbstractEventDispatcherV2::QAbstractEventDispatcherV2(QAbstractEventDispatcherPrivate &dd,
650 : QAbstractEventDispatcher((dd.isV2 =
true, dd), parent)
655
656
657QAbstractEventDispatcherV2::~QAbstractEventDispatcherV2() =
default;
660
661
662
663void QAbstractEventDispatcherV2::registerTimer(
int timerId, qint64 interval,
664 Qt::TimerType timerType, QObject *object)
666 auto self =
static_cast<QAbstractEventDispatcherV2 *>(
this);
667 self->registerTimer(Qt::TimerId(timerId), interval * 1ms, timerType, object);
671
672
673
674bool QAbstractEventDispatcherV2::unregisterTimer(
int timerId)
676 auto self =
static_cast<QAbstractEventDispatcherV2 *>(
this);
677 return self->unregisterTimer(Qt::TimerId(timerId));
681
682
683
684auto QAbstractEventDispatcherV2::registeredTimers(QObject *object)
const -> QList<TimerInfo>
686 auto self =
static_cast<
const QAbstractEventDispatcherV2 *>(
this);
687 QList<TimerInfoV2> timers = self->timersForObject(object);
688 QList<TimerInfo> result;
689 result.reserve(timers.size());
690 for (
const TimerInfoV2 &t : timers)
691 result.emplaceBack(qToUnderlying(t.timerId), fromDuration<
int>(t.interval), t.timerType);
696
697
698
699int QAbstractEventDispatcherV2::remainingTime(
int timerId)
701 auto self =
static_cast<QAbstractEventDispatcherV2 *>(
this);
702 return fromDuration<
int>(self->remainingTime(Qt::TimerId(timerId)));
706
707
708
709bool QAbstractEventDispatcherV2::processEventsWithDeadline(QEventLoop::ProcessEventsFlags flags, QDeadlineTimer deadline)
712 return processEvents(flags);
718#include "moc_qabstracteventdispatcher.cpp"
Combined button and popup list for selecting options.
QFreeList< void, QtTimerIdFreeListConstants > QtTimerIdFreeList
static const int Sizes[BlockCount]