[*] a050d42e replacement - add a thread local event dispatcher provider instead

Change-Id: Idca428809312dc95c80096e2a08a21ff233c03cb
This commit is contained in:
Reece Wilson 2023-12-06 09:16:41 +00:00
parent a95f64ef44
commit c37f6d7e03
6 changed files with 12 additions and 27 deletions

View File

@ -160,7 +160,7 @@ void QBasicTimer::start(std::chrono::milliseconds duration, Qt::TimerType timerT
return;
}
if (!gGlobalEventDispatcher)
if (!gGetLocalEventDispatcher)
{
if (Q_UNLIKELY(obj && obj->thread() != eventDispatcher->thread())) {
qWarning("QBasicTimer::start: Timers cannot be started from another thread");
@ -183,20 +183,10 @@ void QBasicTimer::stop()
if (id) {
QAbstractEventDispatcher *eventDispatcher = QAbstractEventDispatcher::instance();
if (!gGlobalEventDispatcher)
{
if (eventDispatcher && !eventDispatcher->unregisterTimer(id)) {
qWarning("QBasicTimer::stop: Failed. Possibly trying to stop from a different thread");
return;
}
}
else
{
if (!gGlobalEventDispatcher->unregisterTimer(id)) {
qWarning("QBasicTimer::stop: Failed. Possibly trying to stop from a different thread");
return;
}
}
QAbstractEventDispatcherPrivate::releaseTimerId(id);
}

View File

@ -509,10 +509,6 @@ void QCoreApplicationPrivate::createEventDispatcher()
{
Q_Q(QCoreApplication);
if (gGlobalEventDispatcher) {
return;
}
QThreadData *data = QThreadData::current();
Q_ASSERT(!data->hasEventDispatcher());
eventDispatcher = data->createEventDispatcher();
@ -907,8 +903,8 @@ void Q_TRACE_INSTRUMENT(qtcore) QCoreApplicationPrivate::init()
auto thisThreadData = threadData.loadRelaxed();
eventDispatcher = thisThreadData->eventDispatcher.loadRelaxed();
if (gGlobalEventDispatcher) {
eventDispatcher = gGlobalEventDispatcher;
if (gGetLocalEventDispatcher) {
eventDispatcher = gGetLocalEventDispatcher();
} else {
// otherwise we create one
if (!eventDispatcher)

View File

@ -1,3 +1,3 @@
#include "qthreadawareeventdispatcher_i.hpp"
SECRET_PLATFORM_EXPORT QAbstractEventDispatcher *gGlobalEventDispatcher = {};
SECRET_PLATFORM_EXPORT QAbstractEventDispatcher *(*gGetLocalEventDispatcher)() = {};

View File

@ -4,5 +4,4 @@
#define SECRET_PLATFORM_EXPORT __declspec(dllexport)
#endif
extern SECRET_PLATFORM_EXPORT QAbstractEventDispatcher *gGlobalEventDispatcher;
extern SECRET_PLATFORM_EXPORT QAbstractEventDispatcher *(*gGetLocalEventDispatcher)();

View File

@ -113,8 +113,8 @@ void QThreadData::deref()
QAbstractEventDispatcher *QThreadData::createEventDispatcher()
{
QAbstractEventDispatcher *ed = gGlobalEventDispatcher ?
gGlobalEventDispatcher :
QAbstractEventDispatcher *ed = gGetLocalEventDispatcher ?
gGetLocalEventDispatcher() :
QThreadPrivate::createEventDispatcher(this);
eventDispatcher.storeRelease(ed);
return ed;

View File

@ -330,7 +330,7 @@ void QThreadPrivate::finish(void *arg, bool lockAnyway) noexcept
locker.unlock();
eventDispatcher->closingDown();
if (gGlobalEventDispatcher != eventDispatcher)
if (!gGetLocalEventDispatcher)
{
delete eventDispatcher;
}