diff options
| author | Mårten Nordheim <marten.nordheim@qt.io> | 2025-12-09 15:18:07 +0100 |
|---|---|---|
| committer | Mårten Nordheim <marten.nordheim@qt.io> | 2025-12-15 15:42:49 +0100 |
| commit | eebd421a5d547ec533ffa217007ba077585e7de0 (patch) | |
| tree | 923533c4ee82b98424c4454885c5cd7cc58dad9d /src/corelib/io/qrandomaccessasyncfile.cpp | |
| parent | a13b02825d660ba060a0815ca8cb87cea8cdcf9e (diff) | |
QRandomAccessAsyncFile: fallback to threadpool on error
If the native backend (where one is supported) reports a failure in
its init() function, fall back to create a backend of the threadpool
variant.
This required changing the hierarchy a bit so they can co-exist -
without turning this into a fully plugin-ized class - as well as making
the thread and future features mandatory for the async-io feature, so
there is an actual fallback guaranteed to be available.
Task-number: QTBUG-136763
Pick-to: 6.11
Change-Id: Ib87c42bb67eec446278be2e43ca76f594155ab84
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Diffstat (limited to 'src/corelib/io/qrandomaccessasyncfile.cpp')
| -rw-r--r-- | src/corelib/io/qrandomaccessasyncfile.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/corelib/io/qrandomaccessasyncfile.cpp b/src/corelib/io/qrandomaccessasyncfile.cpp index c544585de9d..34e216efe27 100644 --- a/src/corelib/io/qrandomaccessasyncfile.cpp +++ b/src/corelib/io/qrandomaccessasyncfile.cpp @@ -7,6 +7,31 @@ QT_BEGIN_NAMESPACE +QRandomAccessAsyncFileBackend::QRandomAccessAsyncFileBackend(QRandomAccessAsyncFile *owner) + : m_owner(owner) +{ +} +QRandomAccessAsyncFileBackend::~QRandomAccessAsyncFileBackend() = default; +QRandomAccessAsyncFilePrivate::QRandomAccessAsyncFilePrivate() = default; +QRandomAccessAsyncFilePrivate::~QRandomAccessAsyncFilePrivate() = default; + +void QRandomAccessAsyncFilePrivate::init() +{ + Q_Q(QRandomAccessAsyncFile); + +#if defined(QT_RANDOMACCESSASYNCFILE_QIORING) || defined(Q_OS_DARWIN) + m_backend = std::make_unique<QRandomAccessAsyncFileNativeBackend>(q); +#endif + if (!m_backend || !m_backend->init()) { +#if QT_CONFIG(thread) && QT_CONFIG(future) + m_backend = std::make_unique<QRandomAccessAsyncFileThreadPoolBackend>(q); + [[maybe_unused]] + bool result = m_backend->init(); + Q_ASSERT(result); // it always succeeds +#endif + } +} + QRandomAccessAsyncFile::QRandomAccessAsyncFile(QObject *parent) : QObject{*new QRandomAccessAsyncFilePrivate, parent} { |
