Move QBasicFutureWatcher behind the ABI boundary
... and out of QtPrivate.
No inline API requires it anymore, so move it into the only TU using
it. Can't move it into the unnamed namespace because of the friend
declaration in QFutureInterfaceBase.
Change-Id: I27452960492bc1193a4d0eaeb2acd913d4dd02a5
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
(cherry picked from commit d41db62154
)
This commit is contained in:
parent
b386b5b00b
commit
fde0d8a017
@ -683,7 +683,6 @@ qt_internal_extend_target(Core CONDITION QT_FEATURE_thread AND UNIX AND NOT APPL
|
||||
qt_internal_extend_target(Core CONDITION QT_FEATURE_future
|
||||
SOURCES
|
||||
thread/qexception.cpp thread/qexception.h
|
||||
thread/qbasicfuturewatcher.cpp thread/qbasicfuturewatcher.h
|
||||
thread/qfuture.h
|
||||
thread/qfuture_impl.h
|
||||
thread/qfutureinterface.cpp thread/qfutureinterface.h thread/qfutureinterface_p.h
|
||||
|
@ -1,80 +0,0 @@
|
||||
// Copyright (C) 2023 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
|
||||
|
||||
#include "qbasicfuturewatcher.h"
|
||||
#include "qcoreapplication.h"
|
||||
#include "qfutureinterface.h"
|
||||
#include "qfutureinterface_p.h"
|
||||
|
||||
#include <QtCore/private/qobject_p.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
namespace QtPrivate {
|
||||
|
||||
class QBasicFutureWatcherPrivate : public QObjectPrivate, QFutureCallOutInterface
|
||||
{
|
||||
public:
|
||||
Q_DECLARE_PUBLIC(QBasicFutureWatcher)
|
||||
|
||||
QFutureInterfaceBase future;
|
||||
|
||||
void postCallOutEvent(const QFutureCallOutEvent &event) override;
|
||||
void callOutInterfaceDisconnected() override;
|
||||
};
|
||||
|
||||
void QBasicFutureWatcherPrivate::postCallOutEvent(const QFutureCallOutEvent &event)
|
||||
{
|
||||
Q_Q(QBasicFutureWatcher);
|
||||
if (q->thread() == QThread::currentThread()) {
|
||||
// If we are in the same thread, don't queue up anything.
|
||||
std::unique_ptr<QFutureCallOutEvent> clonedEvent(event.clone());
|
||||
QCoreApplication::sendEvent(q, clonedEvent.get());
|
||||
} else {
|
||||
QCoreApplication::postEvent(q, event.clone());
|
||||
}
|
||||
}
|
||||
|
||||
void QBasicFutureWatcherPrivate::callOutInterfaceDisconnected()
|
||||
{
|
||||
Q_Q(QBasicFutureWatcher);
|
||||
QCoreApplication::removePostedEvents(q, QEvent::FutureCallOut);
|
||||
}
|
||||
|
||||
/*
|
||||
* QBasicFutureWatcher is a more lightweight version of QFutureWatcher for internal use
|
||||
*/
|
||||
QBasicFutureWatcher::QBasicFutureWatcher(QObject *parent)
|
||||
: QObject(*new QBasicFutureWatcherPrivate, parent)
|
||||
{
|
||||
}
|
||||
|
||||
QBasicFutureWatcher::~QBasicFutureWatcher()
|
||||
{
|
||||
Q_D(QBasicFutureWatcher);
|
||||
d->future.d->disconnectOutputInterface(d);
|
||||
}
|
||||
|
||||
void QBasicFutureWatcher::setFuture(QFutureInterfaceBase &fi)
|
||||
{
|
||||
Q_D(QBasicFutureWatcher);
|
||||
d->future = fi;
|
||||
d->future.d->connectOutputInterface(d);
|
||||
}
|
||||
|
||||
bool QtPrivate::QBasicFutureWatcher::event(QEvent *event)
|
||||
{
|
||||
if (event->type() == QEvent::FutureCallOut) {
|
||||
QFutureCallOutEvent *callOutEvent = static_cast<QFutureCallOutEvent *>(event);
|
||||
if (callOutEvent->callOutType == QFutureCallOutEvent::Finished)
|
||||
emit finished();
|
||||
return true;
|
||||
}
|
||||
return QObject::event(event);
|
||||
}
|
||||
|
||||
} // namespace QtPrivate
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#include "moc_qbasicfuturewatcher.cpp"
|
@ -1,39 +0,0 @@
|
||||
// Copyright (C) 2023 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
|
||||
|
||||
#ifndef QBASICFUTUREWATCHER_H
|
||||
#define QBASICFUTUREWATCHER_H
|
||||
|
||||
#include <QtCore/qobject.h>
|
||||
|
||||
QT_REQUIRE_CONFIG(future);
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class QFutureInterfaceBase;
|
||||
|
||||
namespace QtPrivate {
|
||||
|
||||
class QBasicFutureWatcherPrivate;
|
||||
|
||||
class Q_CORE_EXPORT QBasicFutureWatcher : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_DECLARE_PRIVATE(QBasicFutureWatcher)
|
||||
public:
|
||||
explicit QBasicFutureWatcher(QObject *parent = nullptr);
|
||||
~QBasicFutureWatcher() override;
|
||||
|
||||
void setFuture(QFutureInterfaceBase &fi);
|
||||
|
||||
bool event(QEvent *event) override;
|
||||
|
||||
Q_SIGNALS:
|
||||
void finished();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // QBASICFUTUREWATCHER_H
|
@ -11,7 +11,6 @@
|
||||
#endif
|
||||
|
||||
#include <QtCore/qglobal.h>
|
||||
#include <QtCore/qbasicfuturewatcher.h>
|
||||
#include <QtCore/qfutureinterface.h>
|
||||
#include <QtCore/qthreadpool.h>
|
||||
#include <QtCore/qexception.h>
|
||||
|
@ -4,9 +4,9 @@
|
||||
// qfutureinterface.h included from qfuture.h
|
||||
#include "qfuture.h"
|
||||
#include "qfutureinterface_p.h"
|
||||
#include "qbasicfuturewatcher.h"
|
||||
|
||||
#include <QtCore/qatomic.h>
|
||||
#include <QtCore/qcoreapplication.h>
|
||||
#include <QtCore/qthread.h>
|
||||
#include <QtCore/qvarlengtharray.h>
|
||||
#include <QtCore/private/qsimd_p.h> // for qYieldCpu()
|
||||
@ -45,6 +45,84 @@ const auto suspendingOrSuspended =
|
||||
|
||||
} // unnamed namespace
|
||||
|
||||
class QBasicFutureWatcherPrivate;
|
||||
class QBasicFutureWatcher : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_DECLARE_PRIVATE(QBasicFutureWatcher)
|
||||
public:
|
||||
explicit QBasicFutureWatcher(QObject *parent = nullptr);
|
||||
~QBasicFutureWatcher() override;
|
||||
|
||||
void setFuture(QFutureInterfaceBase &fi);
|
||||
|
||||
bool event(QEvent *event) override;
|
||||
|
||||
Q_SIGNALS:
|
||||
void finished();
|
||||
};
|
||||
|
||||
class QBasicFutureWatcherPrivate : public QObjectPrivate, QFutureCallOutInterface
|
||||
{
|
||||
public:
|
||||
Q_DECLARE_PUBLIC(QBasicFutureWatcher)
|
||||
|
||||
QFutureInterfaceBase future;
|
||||
|
||||
void postCallOutEvent(const QFutureCallOutEvent &event) override;
|
||||
void callOutInterfaceDisconnected() override;
|
||||
};
|
||||
|
||||
void QBasicFutureWatcherPrivate::postCallOutEvent(const QFutureCallOutEvent &event)
|
||||
{
|
||||
Q_Q(QBasicFutureWatcher);
|
||||
if (q->thread() == QThread::currentThread()) {
|
||||
// If we are in the same thread, don't queue up anything.
|
||||
std::unique_ptr<QFutureCallOutEvent> clonedEvent(event.clone());
|
||||
QCoreApplication::sendEvent(q, clonedEvent.get());
|
||||
} else {
|
||||
QCoreApplication::postEvent(q, event.clone());
|
||||
}
|
||||
}
|
||||
|
||||
void QBasicFutureWatcherPrivate::callOutInterfaceDisconnected()
|
||||
{
|
||||
Q_Q(QBasicFutureWatcher);
|
||||
QCoreApplication::removePostedEvents(q, QEvent::FutureCallOut);
|
||||
}
|
||||
|
||||
/*
|
||||
* QBasicFutureWatcher is a more lightweight version of QFutureWatcher for internal use
|
||||
*/
|
||||
QBasicFutureWatcher::QBasicFutureWatcher(QObject *parent)
|
||||
: QObject(*new QBasicFutureWatcherPrivate, parent)
|
||||
{
|
||||
}
|
||||
|
||||
QBasicFutureWatcher::~QBasicFutureWatcher()
|
||||
{
|
||||
Q_D(QBasicFutureWatcher);
|
||||
d->future.d->disconnectOutputInterface(d);
|
||||
}
|
||||
|
||||
void QBasicFutureWatcher::setFuture(QFutureInterfaceBase &fi)
|
||||
{
|
||||
Q_D(QBasicFutureWatcher);
|
||||
d->future = fi;
|
||||
d->future.d->connectOutputInterface(d);
|
||||
}
|
||||
|
||||
bool QBasicFutureWatcher::event(QEvent *event)
|
||||
{
|
||||
if (event->type() == QEvent::FutureCallOut) {
|
||||
QFutureCallOutEvent *callOutEvent = static_cast<QFutureCallOutEvent *>(event);
|
||||
if (callOutEvent->callOutType == QFutureCallOutEvent::Finished)
|
||||
emit finished();
|
||||
return true;
|
||||
}
|
||||
return QObject::event(event);
|
||||
}
|
||||
|
||||
void QtPrivate::watchContinuationImpl(const QObject *context, QSlotObjectBase *slotObj,
|
||||
QFutureInterfaceBase &fi)
|
||||
{
|
||||
@ -942,3 +1020,5 @@ QFuture<void> makeReadyVoidFuture()
|
||||
} // namespace QtFuture
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#include "qfutureinterface.moc"
|
||||
|
@ -39,8 +39,8 @@ template<class Function, class ResultType>
|
||||
class FailureHandler;
|
||||
#endif
|
||||
|
||||
class QBasicFutureWatcher;
|
||||
}
|
||||
class QBasicFutureWatcher;
|
||||
|
||||
class Q_CORE_EXPORT QFutureInterfaceBase
|
||||
{
|
||||
@ -178,7 +178,7 @@ private:
|
||||
friend class QtPrivate::FailureHandler;
|
||||
#endif
|
||||
|
||||
friend class QtPrivate::QBasicFutureWatcher;
|
||||
friend class QBasicFutureWatcher;
|
||||
|
||||
template<class T>
|
||||
friend class QPromise;
|
||||
|
Loading…
Reference in New Issue
Block a user