QEventLoopLocker: add a visit() member
Still suffers from a bit of an impedance mismatch, because it's the first step in making QEventLoopLocker shed its Private, but will be used in a subsequent commit to DRY more code. Task-number: QTBUG-114793 Change-Id: Ia14effb6255961edae68eaf941fece9dca0cb844 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> (cherry picked from commit 8c2c4f178a1722fc8c749ca6ee894df151808138)
This commit is contained in:
parent
9c7b9f9f58
commit
74571f3455
@ -296,6 +296,7 @@ void QEventLoop::quit()
|
||||
|
||||
class QEventLoopLockerPrivate
|
||||
{
|
||||
friend class QEventLoopLocker;
|
||||
public:
|
||||
explicit QEventLoopLockerPrivate(QEventLoopPrivate *loop)
|
||||
: QEventLoopLockerPrivate(loop, EventLoop)
|
||||
@ -315,22 +316,6 @@ public:
|
||||
app->ref();
|
||||
}
|
||||
|
||||
~QEventLoopLockerPrivate()
|
||||
{
|
||||
switch (type())
|
||||
{
|
||||
case EventLoop:
|
||||
loop()->deref();
|
||||
break;
|
||||
case Thread:
|
||||
thread()->deref();
|
||||
break;
|
||||
default:
|
||||
app()->deref();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
QEventLoopPrivate *loop() const { return static_cast<QEventLoopPrivate *>(pointer()); }
|
||||
QThreadPrivate *thread() const { return static_cast<QThreadPrivate *>(pointer()); }
|
||||
@ -416,9 +401,26 @@ QEventLoopLocker::QEventLoopLocker(QThread *thread)
|
||||
*/
|
||||
QEventLoopLocker::~QEventLoopLocker()
|
||||
{
|
||||
visit([](auto p) { p->deref(); });
|
||||
delete d_ptr;
|
||||
}
|
||||
|
||||
/*!
|
||||
\internal
|
||||
*/
|
||||
template <typename Func>
|
||||
void QEventLoopLocker::visit(Func f) const
|
||||
{
|
||||
using Type = QEventLoopLockerPrivate::Type;
|
||||
const auto ptr = d_ptr->pointer();
|
||||
switch (d_ptr->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));
|
||||
}
|
||||
Q_UNREACHABLE();
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#include "moc_qeventloop.cpp"
|
||||
|
@ -61,7 +61,14 @@ public:
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(QEventLoopLocker)
|
||||
|
||||
//
|
||||
// Private implementation details.
|
||||
// Do not call from public inline API!
|
||||
//
|
||||
QEventLoopLockerPrivate *d_ptr;
|
||||
template <typename Func>
|
||||
void visit(Func func) const;
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
Loading…
x
Reference in New Issue
Block a user