Qt 4.8
Public Types | Public Functions | Protected Functions | Properties | Friends | List of all members
QFutureInterfaceBase Class Reference

#include <qfutureinterface.h>

Inheritance diagram for QFutureInterfaceBase:
QFutureInterface< T >

Public Types

enum  State {
  NoState = 0x00, Running = 0x01, Started = 0x02, Finished = 0x04,
  Canceled = 0x08, Paused = 0x10, Throttled = 0x20
}
 

Public Functions

void cancel ()
 
QtConcurrent::internal::ExceptionStoreexceptionStore ()
 
int expectedResultCount ()
 
bool isCanceled () const
 
bool isFinished () const
 
bool isPaused () const
 
bool isProgressUpdateNeeded () const
 
bool isResultReadyAt (int index) const
 
bool isRunning () const
 
bool isStarted () const
 
bool isThrottled () const
 
QMutexmutex () const
 
bool operator!= (const QFutureInterfaceBase &other) const
 
QFutureInterfaceBaseoperator= (const QFutureInterfaceBase &other)
 
bool operator== (const QFutureInterfaceBase &other) const
 
int progressMaximum () const
 
int progressMinimum () const
 
QString progressText () const
 
int progressValue () const
 
 QFutureInterfaceBase (State initialState=NoState)
 
 QFutureInterfaceBase (const QFutureInterfaceBase &other)
 
bool queryState (State state) const
 
void reportCanceled ()
 
void reportException (const QtConcurrent::Exception &e)
 
void reportFinished ()
 
void reportResultsReady (int beginIndex, int endIndex)
 
void reportStarted ()
 
int resultCount () const
 
QtConcurrent::ResultStoreBase & resultStoreBase ()
 
const QtConcurrent::ResultStoreBase & resultStoreBase () const
 
void setExpectedResultCount (int resultCount)
 
void setFilterMode (bool enable)
 
void setPaused (bool paused)
 
void setProgressRange (int minimum, int maximum)
 
void setProgressValue (int progressValue)
 
void setProgressValueAndText (int progressValue, const QString &progressText)
 
void setRunnable (QRunnable *runnable)
 
void setThrottled (bool enable)
 
void togglePaused ()
 
void waitForFinished ()
 
bool waitForNextResult ()
 
void waitForResult (int resultIndex)
 
void waitForResume ()
 
virtual ~QFutureInterfaceBase ()
 

Protected Functions

bool referenceCountIsOne () const
 

Properties

QFutureInterfaceBasePrivated
 

Friends

class QFutureWatcherBase
 
class QFutureWatcherBasePrivate
 

Detailed Description

Definition at line 64 of file qfutureinterface.h.

Enumerations

◆ State

Enumerator
NoState 
Running 
Started 
Finished 
Canceled 
Paused 
Throttled 

Definition at line 67 of file qfutureinterface.h.

Constructors and Destructors

◆ QFutureInterfaceBase() [1/2]

QFutureInterfaceBase::QFutureInterfaceBase ( State  initialState = NoState)

Definition at line 60 of file qfutureinterface.cpp.

61  : d(new QFutureInterfaceBasePrivate(initialState))
62 { }
QFutureInterfaceBasePrivate * d

◆ QFutureInterfaceBase() [2/2]

QFutureInterfaceBase::QFutureInterfaceBase ( const QFutureInterfaceBase other)

Definition at line 64 of file qfutureinterface.cpp.

65  : d(other.d)
66 {
67  d->refCount.ref();
68 }
bool ref()
Atomically increments the value of this QAtomicInt.
QFutureInterfaceBasePrivate * d

◆ ~QFutureInterfaceBase()

QFutureInterfaceBase::~QFutureInterfaceBase ( )
virtual

Definition at line 70 of file qfutureinterface.cpp.

71 {
72  if (!d->refCount.deref())
73  delete d;
74 }
QFutureInterfaceBasePrivate * d
bool deref()
Atomically decrements the value of this QAtomicInt.

Functions

◆ cancel()

void QFutureInterfaceBase::cancel ( )

Definition at line 76 of file qfutureinterface.cpp.

Referenced by QFutureWatcherBase::cancel(), and reportCanceled().

77 {
78  QMutexLocker locker(&d->m_mutex);
79  if (d->state & Canceled)
80  return;
81 
82  d->state = State((d->state & ~Paused) | Canceled);
86 }
QFutureInterfaceBase::State state
QFutureInterfaceBasePrivate * d
void sendCallOut(const QFutureCallOutEvent &callOut)
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101

◆ exceptionStore()

QtConcurrent::internal::ExceptionStore & QFutureInterfaceBase::exceptionStore ( )

Definition at line 393 of file qfutureinterface.cpp.

394 {
395  return d->m_exceptionStore;
396 }
QFutureInterfaceBasePrivate * d
QtConcurrent::internal::ExceptionStore m_exceptionStore

◆ expectedResultCount()

int QFutureInterfaceBase::expectedResultCount ( )

Definition at line 272 of file qfutureinterface.cpp.

273 {
274  return d->m_expectedResultCount;
275 }
QFutureInterfaceBasePrivate * d

◆ isCanceled()

bool QFutureInterfaceBase::isCanceled ( ) const

Definition at line 142 of file qfutureinterface.cpp.

143 {
144  return queryState(Canceled);
145 }
bool queryState(State state) const

◆ isFinished()

bool QFutureInterfaceBase::isFinished ( ) const

Definition at line 147 of file qfutureinterface.cpp.

148 {
149  return queryState(Finished);
150 }
bool queryState(State state) const

◆ isPaused()

bool QFutureInterfaceBase::isPaused ( ) const

Definition at line 152 of file qfutureinterface.cpp.

Referenced by QFutureWatcherBase::event().

153 {
154  return queryState(Paused);
155 }
bool queryState(State state) const

◆ isProgressUpdateNeeded()

bool QFutureInterfaceBase::isProgressUpdateNeeded ( ) const

Definition at line 219 of file qfutureinterface.cpp.

220 {
221  QMutexLocker locker(&d->m_mutex);
222  return !d->progressTime.isValid() || (d->progressTime.elapsed() > (1000 / MaxProgressEmitsPerSecond));
223 }
bool isValid() const
Returns false if this object was invalidated by a call to invalidate() and has not been restarted sin...
QFutureInterfaceBasePrivate * d
qint64 elapsed() const
Returns the number of milliseconds since this QElapsedTimer was last started.
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101

◆ isResultReadyAt()

bool QFutureInterfaceBase::isResultReadyAt ( int  index) const

Definition at line 162 of file qfutureinterface.cpp.

163 {
166 }
bool internal_isResultReadyAt(int index) const
QFutureInterfaceBasePrivate * d
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
static QReadWriteLock lock
Definition: proxyconf.cpp:399
quint16 index

◆ isRunning()

bool QFutureInterfaceBase::isRunning ( ) const

Definition at line 132 of file qfutureinterface.cpp.

133 {
134  return queryState(Running);
135 }
bool queryState(State state) const

◆ isStarted()

bool QFutureInterfaceBase::isStarted ( ) const

Definition at line 137 of file qfutureinterface.cpp.

138 {
139  return queryState(Started);
140 }
bool queryState(State state) const

◆ isThrottled()

bool QFutureInterfaceBase::isThrottled ( ) const

Definition at line 157 of file qfutureinterface.cpp.

158 {
159  return queryState(Throttled);
160 }
bool queryState(State state) const

◆ mutex()

QMutex * QFutureInterfaceBase::mutex ( ) const

Definition at line 388 of file qfutureinterface.cpp.

389 {
390  return &d->m_mutex;
391 }
QFutureInterfaceBasePrivate * d

◆ operator!=()

bool QFutureInterfaceBase::operator!= ( const QFutureInterfaceBase other) const
inline

Definition at line 130 of file qfutureinterface.h.

130 { return d != other.d; }
QFutureInterfaceBasePrivate * d

◆ operator=()

QFutureInterfaceBase & QFutureInterfaceBase::operator= ( const QFutureInterfaceBase other)

Definition at line 408 of file qfutureinterface.cpp.

Referenced by QFutureInterface< T >::operator=(), and QFutureInterface< T >::results().

409 {
410  other.d->refCount.ref();
411  if (!d->refCount.deref())
412  delete d;
413  d = other.d;
414  return *this;
415 }
bool ref()
Atomically increments the value of this QAtomicInt.
QFutureInterfaceBasePrivate * d
bool deref()
Atomically decrements the value of this QAtomicInt.

◆ operator==()

bool QFutureInterfaceBase::operator== ( const QFutureInterfaceBase other) const
inline

Definition at line 129 of file qfutureinterface.h.

129 { return d == other.d; }
QFutureInterfaceBasePrivate * d

◆ progressMaximum()

int QFutureInterfaceBase::progressMaximum ( ) const

Definition at line 202 of file qfutureinterface.cpp.

Referenced by QFutureWatcherBase::progressMaximum().

203 {
204  return d->m_progressMaximum;
205 }
QFutureInterfaceBasePrivate * d

◆ progressMinimum()

int QFutureInterfaceBase::progressMinimum ( ) const

Definition at line 197 of file qfutureinterface.cpp.

Referenced by QFutureWatcherBase::progressMinimum().

198 {
199  return d->m_progressMinimum;
200 }
QFutureInterfaceBasePrivate * d

◆ progressText()

QString QFutureInterfaceBase::progressText ( ) const

Definition at line 213 of file qfutureinterface.cpp.

Referenced by QFutureWatcherBase::progressText().

214 {
215  QMutexLocker locker(&d->m_mutex);
216  return d->m_progressText;
217 }
QFutureInterfaceBasePrivate * d
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101

◆ progressValue()

int QFutureInterfaceBase::progressValue ( ) const

Definition at line 192 of file qfutureinterface.cpp.

Referenced by QFutureWatcherBase::progressValue().

193 {
194  return d->m_progressValue;
195 }
QFutureInterfaceBasePrivate * d

◆ queryState()

bool QFutureInterfaceBase::queryState ( State  state) const

◆ referenceCountIsOne()

bool QFutureInterfaceBase::referenceCountIsOne ( ) const
protected

Definition at line 417 of file qfutureinterface.cpp.

418 {
419  return d->refCount == 1;
420 }
QFutureInterfaceBasePrivate * d

◆ reportCanceled()

void QFutureInterfaceBase::reportCanceled ( )

Definition at line 235 of file qfutureinterface.cpp.

236 {
237  cancel();
238 }

◆ reportException()

void QFutureInterfaceBase::reportException ( const QtConcurrent::Exception e)

Definition at line 241 of file qfutureinterface.cpp.

242 {
243  QMutexLocker locker(&d->m_mutex);
244  if ((d->state & Canceled) || (d->state & Finished))
245  return;
246 
247  d->m_exceptionStore.setException(exception);
248  d->state = State(d->state | Canceled);
252 }
QFutureInterfaceBase::State state
QFutureInterfaceBasePrivate * d
void sendCallOut(const QFutureCallOutEvent &callOut)
QtConcurrent::internal::ExceptionStore m_exceptionStore
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
void setException(const Exception &e)

◆ reportFinished()

void QFutureInterfaceBase::reportFinished ( )

Definition at line 255 of file qfutureinterface.cpp.

Referenced by QFutureInterface< T >::reportFinished(), and QFutureInterface< T >::results().

256 {
257  QMutexLocker locker(&d->m_mutex);
258  if (!(d->state & Finished)) {
259  d->state = State((d->state & ~Running) | Finished);
262  }
263 }
QFutureInterfaceBase::State state
QFutureInterfaceBasePrivate * d
void sendCallOut(const QFutureCallOutEvent &callOut)
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101

◆ reportResultsReady()

void QFutureInterfaceBase::reportResultsReady ( int  beginIndex,
int  endIndex 
)

Definition at line 319 of file qfutureinterface.cpp.

320 {
321  if ((d->state & Canceled) || (d->state & Finished) || beginIndex == endIndex)
322  return;
323 
325 
326  if (d->manualProgress == false) {
327  if (d->internal_updateProgress(d->m_progressValue + endIndex - beginIndex) == false) {
329  beginIndex,
330  endIndex));
331  return;
332  }
333 
336  d->m_progressText),
338  beginIndex,
339  endIndex));
340  return;
341  }
343 }
void sendCallOuts(const QFutureCallOutEvent &callOut1, const QFutureCallOutEvent &callOut2)
QFutureInterfaceBase::State state
QFutureInterfaceBasePrivate * d
void sendCallOut(const QFutureCallOutEvent &callOut)
bool internal_updateProgress(int progress, const QString &progressText=QString())

◆ reportStarted()

void QFutureInterfaceBase::reportStarted ( )

Definition at line 225 of file qfutureinterface.cpp.

226 {
227  QMutexLocker locker(&d->m_mutex);
228  if ((d->state & Started) || (d->state & Canceled) || (d->state & Finished))
229  return;
230 
233 }
QFutureInterfaceBase::State state
QFutureInterfaceBasePrivate * d
void sendCallOut(const QFutureCallOutEvent &callOut)
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
void setState(QFutureInterfaceBase::State state)

◆ resultCount()

int QFutureInterfaceBase::resultCount ( ) const

Definition at line 207 of file qfutureinterface.cpp.

Referenced by setExpectedResultCount().

208 {
210  return d->internal_resultCount();
211 }
QFutureInterfaceBasePrivate * d
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
static QReadWriteLock lock
Definition: proxyconf.cpp:399

◆ resultStoreBase() [1/2]

QtConcurrent::ResultStoreBase & QFutureInterfaceBase::resultStoreBase ( )

Definition at line 398 of file qfutureinterface.cpp.

Referenced by setFilterMode().

399 {
400  return d->m_results;
401 }
QtConcurrent::ResultStoreBase m_results
QFutureInterfaceBasePrivate * d

◆ resultStoreBase() [2/2]

const QtConcurrent::ResultStoreBase & QFutureInterfaceBase::resultStoreBase ( ) const

Definition at line 403 of file qfutureinterface.cpp.

404 {
405  return d->m_results;
406 }
QtConcurrent::ResultStoreBase m_results
QFutureInterfaceBasePrivate * d

◆ setExpectedResultCount()

void QFutureInterfaceBase::setExpectedResultCount ( int  resultCount)

Definition at line 265 of file qfutureinterface.cpp.

266 {
267  if (d->manualProgress == false)
270 }
void setProgressRange(int minimum, int maximum)
QFutureInterfaceBasePrivate * d

◆ setFilterMode()

void QFutureInterfaceBase::setFilterMode ( bool  enable)

Definition at line 350 of file qfutureinterface.cpp.

351 {
352  QMutexLocker locker(&d->m_mutex);
353  resultStoreBase().setFilterMode(enable);
354 }
QFutureInterfaceBasePrivate * d
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
QtConcurrent::ResultStoreBase & resultStoreBase()

◆ setPaused()

void QFutureInterfaceBase::setPaused ( bool  paused)

Definition at line 88 of file qfutureinterface.cpp.

Referenced by QFutureWatcherBase::pause(), QFutureWatcherBase::resume(), and QFutureWatcherBase::setPaused().

89 {
90  QMutexLocker locker(&d->m_mutex);
91  if (paused) {
92  d->state = State(d->state | Paused);
94  } else {
95  d->state = State(d->state & ~Paused);
98  }
99 }
QFutureInterfaceBase::State state
QFutureInterfaceBasePrivate * d
void sendCallOut(const QFutureCallOutEvent &callOut)
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101

◆ setProgressRange()

void QFutureInterfaceBase::setProgressRange ( int  minimum,
int  maximum 
)

Definition at line 356 of file qfutureinterface.cpp.

Referenced by setExpectedResultCount().

357 {
358  QMutexLocker locker(&d->m_mutex);
359  d->m_progressMinimum = minimum;
360  d->m_progressMaximum = maximum;
362 }
QFutureInterfaceBasePrivate * d
void sendCallOut(const QFutureCallOutEvent &callOut)
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101

◆ setProgressValue()

void QFutureInterfaceBase::setProgressValue ( int  progressValue)

Definition at line 364 of file qfutureinterface.cpp.

365 {
367 }
void setProgressValueAndText(int progressValue, const QString &progressText)
The QString class provides a Unicode character string.
Definition: qstring.h:83

◆ setProgressValueAndText()

void QFutureInterfaceBase::setProgressValueAndText ( int  progressValue,
const QString progressText 
)

Definition at line 369 of file qfutureinterface.cpp.

Referenced by setProgressValue().

371 {
372  QMutexLocker locker(&d->m_mutex);
373  if (d->manualProgress == false)
374  d->manualProgress = true;
376  return;
377 
378  if ((d->state & Canceled) || (d->state & Finished))
379  return;
380 
381  if (d->internal_updateProgress(progressValue, progressText)) {
384  d->m_progressText));
385  }
386 }
QFutureInterfaceBase::State state
QFutureInterfaceBasePrivate * d
void sendCallOut(const QFutureCallOutEvent &callOut)
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
bool internal_updateProgress(int progress, const QString &progressText=QString())

◆ setRunnable()

void QFutureInterfaceBase::setRunnable ( QRunnable runnable)

Definition at line 345 of file qfutureinterface.cpp.

346 {
347  d->runnable = runnable;
348 }
QFutureInterfaceBasePrivate * d

◆ setThrottled()

void QFutureInterfaceBase::setThrottled ( bool  enable)

Definition at line 114 of file qfutureinterface.cpp.

115 {
116  // bail out if we are not changing the state
117  if ((enable && (d->state & Throttled)) || (!enable && !(d->state & Throttled)))
118  return;
119 
120  // lock and change the state
122  if (enable) {
123  d->state = State(d->state | Throttled);
124  } else {
125  d->state = State(d->state & ~Throttled);
126  if (!(d->state & Paused))
128  }
129 }
QFutureInterfaceBase::State state
QFutureInterfaceBasePrivate * d
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
static QReadWriteLock lock
Definition: proxyconf.cpp:399

◆ togglePaused()

void QFutureInterfaceBase::togglePaused ( )

Definition at line 101 of file qfutureinterface.cpp.

Referenced by QFutureWatcherBase::togglePaused().

102 {
103  QMutexLocker locker(&d->m_mutex);
104  if (d->state & Paused) {
105  d->state = State(d->state & ~Paused);
108  } else {
109  d->state = State(d->state | Paused);
111  }
112 }
QFutureInterfaceBase::State state
QFutureInterfaceBasePrivate * d
void sendCallOut(const QFutureCallOutEvent &callOut)
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101

◆ waitForFinished()

void QFutureInterfaceBase::waitForFinished ( )

Definition at line 305 of file qfutureinterface.cpp.

Referenced by QFutureWatcherBase::waitForFinished().

306 {
307  if (d->state & Running) {
308  QThreadPool::globalInstance()->d_func()->stealRunnable(d->runnable);
309 
311 
312  while (d->state & Running)
314  }
315 
317 }
QFutureInterfaceBase::State state
QFutureInterfaceBasePrivate * d
QtConcurrent::internal::ExceptionStore m_exceptionStore
bool wait(QMutex *mutex, unsigned long time=ULONG_MAX)
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
static QReadWriteLock lock
Definition: proxyconf.cpp:399
static QThreadPool * globalInstance()
Returns the global QThreadPool instance.

◆ waitForNextResult()

bool QFutureInterfaceBase::waitForNextResult ( )

Definition at line 168 of file qfutureinterface.cpp.

169 {
171  return d->internal_waitForNextResult();
172 }
QFutureInterfaceBasePrivate * d
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
static QReadWriteLock lock
Definition: proxyconf.cpp:399

◆ waitForResult()

void QFutureInterfaceBase::waitForResult ( int  resultIndex)

Definition at line 282 of file qfutureinterface.cpp.

Referenced by QFutureInterface< T >::results().

283 {
285 
286  if (!(d->state & Running))
287  return;
288 
289  // To avoid deadlocks and reduce the number of threads used, try to
290  // run the runnable in the current thread.
291  QThreadPool::globalInstance()->d_func()->stealRunnable(d->runnable);
292 
294 
295  if (!(d->state & Running))
296  return;
297 
298  const int waitIndex = (resultIndex == -1) ? INT_MAX : resultIndex;
299  while ((d->state & Running) && d->internal_isResultReadyAt(waitIndex) == false)
301 
303 }
bool internal_isResultReadyAt(int index) const
QFutureInterfaceBase::State state
QFutureInterfaceBasePrivate * d
QtConcurrent::internal::ExceptionStore m_exceptionStore
bool wait(QMutex *mutex, unsigned long time=ULONG_MAX)
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
static QReadWriteLock lock
Definition: proxyconf.cpp:399
static QThreadPool * globalInstance()
Returns the global QThreadPool instance.
#define INT_MAX

◆ waitForResume()

void QFutureInterfaceBase::waitForResume ( )

Definition at line 174 of file qfutureinterface.cpp.

175 {
176  // return early if possible to avoid taking the mutex lock.
177  if ((d->state & Paused) == false || (d->state & Canceled))
178  return;
179 
181  if ((d->state & Paused) == false || (d->state & Canceled))
182  return;
183 
184  // decrease active thread count since this thread will wait.
186 
188 
190 }
void releaseThread()
Releases a thread previously reserved by a call to reserveThread().
QFutureInterfaceBase::State state
QFutureInterfaceBasePrivate * d
bool wait(QMutex *mutex, unsigned long time=ULONG_MAX)
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
static QReadWriteLock lock
Definition: proxyconf.cpp:399
static QThreadPool * globalInstance()
Returns the global QThreadPool instance.
void reserveThread()
Reserves one thread, disregarding activeThreadCount() and maxThreadCount().

Friends and Related Functions

◆ QFutureWatcherBase

friend class QFutureWatcherBase
friend

Definition at line 143 of file qfutureinterface.h.

◆ QFutureWatcherBasePrivate

Definition at line 144 of file qfutureinterface.h.

Properties

◆ d

QFutureInterfaceBasePrivate* QFutureInterfaceBase::d
private

The documentation for this class was generated from the following files: