Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/QtCore/qfuturesynchronizer.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // Copyright (C) 2016 The Qt Company Ltd.
0002 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
0003 
0004 #ifndef QFUTURESYNCHRONIZER_H
0005 #define QFUTURESYNCHRONIZER_H
0006 
0007 #include <QtCore/qfuture.h>
0008 
0009 QT_REQUIRE_CONFIG(future);
0010 
0011 QT_BEGIN_NAMESPACE
0012 
0013 
0014 template <typename T>
0015 class QFutureSynchronizer
0016 {
0017     Q_DISABLE_COPY(QFutureSynchronizer)
0018 
0019 public:
0020     Q_NODISCARD_CTOR QFutureSynchronizer() : m_cancelOnWait(false) { }
0021     Q_NODISCARD_CTOR_X("Use future.waitForFinished() instead.")
0022     explicit QFutureSynchronizer(QFuture<T> future)
0023         : m_cancelOnWait(false)
0024     { addFuture(std::move(future)); }
0025     ~QFutureSynchronizer()  { waitForFinished(); }
0026 
0027     void setFuture(QFuture<T> future)
0028     {
0029         waitForFinished();
0030         m_futures.clear();
0031         addFuture(std::move(future));
0032     }
0033 
0034     void addFuture(QFuture<T> future)
0035     {
0036         m_futures.append(std::move(future));
0037     }
0038 
0039     void waitForFinished()
0040     {
0041         if (m_cancelOnWait) {
0042             for (int i = 0; i < m_futures.size(); ++i) {
0043                  m_futures[i].cancel();
0044             }
0045         }
0046 
0047         for (int i = 0; i < m_futures.size(); ++i) {
0048              m_futures[i].waitForFinished();
0049          }
0050     }
0051 
0052     void clearFutures()
0053     {
0054         m_futures.clear();
0055     }
0056 
0057     QList<QFuture<T> > futures() const
0058     {
0059         return m_futures;
0060     }
0061 
0062     void setCancelOnWait(bool enabled)
0063     {
0064         m_cancelOnWait = enabled;
0065     }
0066 
0067     bool cancelOnWait() const
0068     {
0069         return m_cancelOnWait;
0070     }
0071 
0072 protected:
0073     QList<QFuture<T>> m_futures;
0074     bool m_cancelOnWait;
0075 };
0076 
0077 QT_END_NAMESPACE
0078 
0079 #endif // QFUTURESYNCHRONIZER_H