summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel/qeventloop.cpp
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2023-07-04 22:28:50 +0200
committerMarc Mutz <marc.mutz@qt.io>2023-07-09 21:23:17 +0000
commit416e07e0575922323b76e4e7768409b203292837 (patch)
tree7d56ad80d6c4966165d8e9c8c208200969549623 /src/corelib/kernel/qeventloop.cpp
parent536696196c4f954ffd2848bb89ea0404938262ad (diff)
QEventLoopLocker: rewrite to hold public classes
... instead of Private ones, at the cost of having to befriend of all the lockable classes, because we need access to their d_func()'s. This simplifies the code, because we don't need the manual QClass to QClassPrivate mapping (o2p) anymore, we can just use d_func(). This also paves the way to make QEventLoopLocker almost completely inline and use a 3-pointer form of QBiPointer, once available, to hide the bit fiddling. We couldn't make such a change if the class continued to hold pointers to QClassPrivate's. Pick-to: 6.6 Task-number: QTBUG-114793 Change-Id: Id300e4d45d6cacabe090a46cd6433c5ead3c8b0c Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/corelib/kernel/qeventloop.cpp')
-rw-r--r--src/corelib/kernel/qeventloop.cpp32
1 files changed, 11 insertions, 21 deletions
diff --git a/src/corelib/kernel/qeventloop.cpp b/src/corelib/kernel/qeventloop.cpp
index bdc448fe56..f754a975b9 100644
--- a/src/corelib/kernel/qeventloop.cpp
+++ b/src/corelib/kernel/qeventloop.cpp
@@ -309,19 +309,10 @@ bool QEventLoop::event(QEvent *event)
void QEventLoop::quit()
{ exit(0); }
-
-namespace {
// If any of these trigger, the Type bits will interfere with the pointer values:
-static_assert(alignof(QEventLoopPrivate) >= 4);
-static_assert(alignof(QThreadPrivate) >= 4);
-static_assert(alignof(QCoreApplicationPrivate) >= 4);
-
-template <typename Private>
-Private *o2p(QObject *o)
-{
- return static_cast<Private*>(QObjectPrivate::get(o));
-}
-} // unnamed namespace
+static_assert(alignof(QEventLoop) >= 4);
+static_assert(alignof(QThread) >= 4);
+static_assert(alignof(QCoreApplication) >= 4);
/*!
\class QEventLoopLocker
@@ -351,8 +342,7 @@ Private *o2p(QObject *o)
\sa QCoreApplication::quit(), QCoreApplication::isQuitLockEnabled()
*/
QEventLoopLocker::QEventLoopLocker() noexcept
- : QEventLoopLocker{o2p<QCoreApplicationPrivate>(QCoreApplication::instance()),
- Type::Application}
+ : QEventLoopLocker{QCoreApplication::instance(), Type::Application}
{
}
@@ -365,7 +355,7 @@ QEventLoopLocker::QEventLoopLocker() noexcept
\sa QEventLoop::quit()
*/
QEventLoopLocker::QEventLoopLocker(QEventLoop *loop) noexcept
- : QEventLoopLocker{o2p<QEventLoopPrivate>(loop), Type::EventLoop}
+ : QEventLoopLocker{loop, Type::EventLoop}
{
}
@@ -378,7 +368,7 @@ QEventLoopLocker::QEventLoopLocker(QEventLoop *loop) noexcept
\sa QThread::quit()
*/
QEventLoopLocker::QEventLoopLocker(QThread *thread) noexcept
- : QEventLoopLocker{o2p<QThreadPrivate>(thread), Type::Thread}
+ : QEventLoopLocker{thread, Type::Thread}
{
}
@@ -425,7 +415,7 @@ QEventLoopLocker::QEventLoopLocker(QThread *thread) noexcept
*/
QEventLoopLocker::~QEventLoopLocker()
{
- visit([](auto p) { p->deref(); });
+ visit([](auto p) { p->d_func()->deref(); });
}
/*!
@@ -434,7 +424,7 @@ QEventLoopLocker::~QEventLoopLocker()
QEventLoopLocker::QEventLoopLocker(void *ptr, Type t) noexcept
: p{quintptr(ptr) | quintptr(t)}
{
- visit([](auto p) { p->ref(); });
+ visit([](auto p) { p->d_func()->ref(); });
}
/*!
@@ -447,9 +437,9 @@ void QEventLoopLocker::visit(Func f) const
if (!ptr)
return;
switch (type()) {
- case Type::EventLoop: return f(static_cast<QEventLoopPrivate *>(ptr));
- case Type::Thread: return f(static_cast<QThreadPrivate *>(ptr));
- case Type::Application: return f(static_cast<QCoreApplicationPrivate *>(ptr));
+ case Type::EventLoop: return f(static_cast<QEventLoop *>(ptr));
+ case Type::Thread: return f(static_cast<QThread *>(ptr));
+ case Type::Application: return f(static_cast<QCoreApplication *>(ptr));
}
Q_UNREACHABLE();
}