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 Pick-to: 6.6 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>
This commit is contained in:
parent
c70257e9b2
commit
8c2c4f178a
@ -312,6 +312,7 @@ void QEventLoop::quit()
|
|||||||
|
|
||||||
class QEventLoopLockerPrivate
|
class QEventLoopLockerPrivate
|
||||||
{
|
{
|
||||||
|
friend class QEventLoopLocker;
|
||||||
public:
|
public:
|
||||||
explicit QEventLoopLockerPrivate(QEventLoopPrivate *loop)
|
explicit QEventLoopLockerPrivate(QEventLoopPrivate *loop)
|
||||||
: QEventLoopLockerPrivate(loop, EventLoop)
|
: QEventLoopLockerPrivate(loop, EventLoop)
|
||||||
@ -331,22 +332,6 @@ public:
|
|||||||
app->ref();
|
app->ref();
|
||||||
}
|
}
|
||||||
|
|
||||||
~QEventLoopLockerPrivate()
|
|
||||||
{
|
|
||||||
switch (type())
|
|
||||||
{
|
|
||||||
case EventLoop:
|
|
||||||
loop()->deref();
|
|
||||||
break;
|
|
||||||
case Thread:
|
|
||||||
thread()->deref();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
app()->deref();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QEventLoopPrivate *loop() const { return static_cast<QEventLoopPrivate *>(pointer()); }
|
QEventLoopPrivate *loop() const { return static_cast<QEventLoopPrivate *>(pointer()); }
|
||||||
QThreadPrivate *thread() const { return static_cast<QThreadPrivate *>(pointer()); }
|
QThreadPrivate *thread() const { return static_cast<QThreadPrivate *>(pointer()); }
|
||||||
@ -432,9 +417,26 @@ QEventLoopLocker::QEventLoopLocker(QThread *thread)
|
|||||||
*/
|
*/
|
||||||
QEventLoopLocker::~QEventLoopLocker()
|
QEventLoopLocker::~QEventLoopLocker()
|
||||||
{
|
{
|
||||||
|
visit([](auto p) { p->deref(); });
|
||||||
delete d_ptr;
|
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
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
#include "moc_qeventloop.cpp"
|
#include "moc_qeventloop.cpp"
|
||||||
|
@ -63,7 +63,14 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
Q_DISABLE_COPY(QEventLoopLocker)
|
Q_DISABLE_COPY(QEventLoopLocker)
|
||||||
|
|
||||||
|
//
|
||||||
|
// Private implementation details.
|
||||||
|
// Do not call from public inline API!
|
||||||
|
//
|
||||||
QEventLoopLockerPrivate *d_ptr;
|
QEventLoopLockerPrivate *d_ptr;
|
||||||
|
template <typename Func>
|
||||||
|
void visit(Func func) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
Loading…
Reference in New Issue
Block a user