summaryrefslogtreecommitdiffstats
path: root/src/corelib/thread
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/thread')
-rw-r--r--src/corelib/thread/qatomic.h11
-rw-r--r--src/corelib/thread/qexception.h4
-rw-r--r--src/corelib/thread/qfutureinterface.cpp4
-rw-r--r--src/corelib/thread/qfuturewatcher.h14
-rw-r--r--src/corelib/thread/qfuturewatcher_p.h4
-rw-r--r--src/corelib/thread/qthread.h2
-rw-r--r--src/corelib/thread/qthread_p.h2
-rw-r--r--src/corelib/thread/qthreadpool.cpp46
-rw-r--r--src/corelib/thread/qthreadpool.h1
-rw-r--r--src/corelib/thread/qthreadpool_p.h3
10 files changed, 57 insertions, 34 deletions
diff --git a/src/corelib/thread/qatomic.h b/src/corelib/thread/qatomic.h
index 7526cfe0e6..a665746db4 100644
--- a/src/corelib/thread/qatomic.h
+++ b/src/corelib/thread/qatomic.h
@@ -40,11 +40,8 @@
QT_BEGIN_NAMESPACE
-
-#if defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 406) && !defined(Q_CC_INTEL)
-# pragma GCC diagnostic push
-# pragma GCC diagnostic ignored "-Wextra"
-#endif
+QT_WARNING_PUSH
+QT_WARNING_DISABLE_GCC("-Wextra")
// High-level atomic integer operations
template <typename T>
@@ -214,9 +211,7 @@ public:
#endif
};
-#if defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 406) && !defined(Q_CC_INTEL)
-# pragma GCC diagnostic pop
-#endif
+QT_WARNING_POP
#ifdef QT_BASIC_ATOMIC_HAS_CONSTRUCTORS
# undef QT_BASIC_ATOMIC_HAS_CONSTRUCTORS
diff --git a/src/corelib/thread/qexception.h b/src/corelib/thread/qexception.h
index 6c48b94a88..a1c3bbeb27 100644
--- a/src/corelib/thread/qexception.h
+++ b/src/corelib/thread/qexception.h
@@ -60,8 +60,8 @@ public:
class Q_CORE_EXPORT QUnhandledException : public QException
{
public:
- void raise() const;
- QUnhandledException *clone() const;
+ void raise() const Q_DECL_OVERRIDE;
+ QUnhandledException *clone() const Q_DECL_OVERRIDE;
};
namespace QtPrivate {
diff --git a/src/corelib/thread/qfutureinterface.cpp b/src/corelib/thread/qfutureinterface.cpp
index 1f417d3d74..a23c32a73b 100644
--- a/src/corelib/thread/qfutureinterface.cpp
+++ b/src/corelib/thread/qfutureinterface.cpp
@@ -292,7 +292,7 @@ void QFutureInterfaceBase::waitForResult(int resultIndex)
// To avoid deadlocks and reduce the number of threads used, try to
// run the runnable in the current thread.
- d->pool()->d_func()->stealRunnable(d->runnable);
+ d->pool()->d_func()->stealAndRunRunnable(d->runnable);
lock.relock();
@@ -313,7 +313,7 @@ void QFutureInterfaceBase::waitForFinished()
lock.unlock();
if (!alreadyFinished) {
- d->pool()->d_func()->stealRunnable(d->runnable);
+ d->pool()->d_func()->stealAndRunRunnable(d->runnable);
lock.relock();
diff --git a/src/corelib/thread/qfuturewatcher.h b/src/corelib/thread/qfuturewatcher.h
index 3ea4c4df4f..f84af0507a 100644
--- a/src/corelib/thread/qfuturewatcher.h
+++ b/src/corelib/thread/qfuturewatcher.h
@@ -70,7 +70,7 @@ public:
void setPendingResultsLimit(int limit);
- bool event(QEvent *event);
+ bool event(QEvent *event) Q_DECL_OVERRIDE;
Q_SIGNALS:
void started();
@@ -92,8 +92,8 @@ public Q_SLOTS:
void togglePaused();
protected:
- void connectNotify (const QMetaMethod &signal);
- void disconnectNotify (const QMetaMethod &signal);
+ void connectNotify (const QMetaMethod &signal) Q_DECL_OVERRIDE;
+ void disconnectNotify (const QMetaMethod &signal) Q_DECL_OVERRIDE;
// called from setFuture() implemented in template sub-classes
void connectOutputInterface();
@@ -160,8 +160,8 @@ public Q_SLOTS:
private:
QFuture<T> m_future;
- const QFutureInterfaceBase &futureInterface() const { return m_future.d; }
- QFutureInterfaceBase &futureInterface() { return m_future.d; }
+ const QFutureInterfaceBase &futureInterface() const Q_DECL_OVERRIDE { return m_future.d; }
+ QFutureInterfaceBase &futureInterface() Q_DECL_OVERRIDE { return m_future.d; }
};
template <typename T>
@@ -191,8 +191,8 @@ public:
private:
QFuture<void> m_future;
- const QFutureInterfaceBase &futureInterface() const { return m_future.d; }
- QFutureInterfaceBase &futureInterface() { return m_future.d; }
+ const QFutureInterfaceBase &futureInterface() const Q_DECL_OVERRIDE { return m_future.d; }
+ QFutureInterfaceBase &futureInterface() Q_DECL_OVERRIDE { return m_future.d; }
};
Q_INLINE_TEMPLATE void QFutureWatcher<void>::setFuture(const QFuture<void> &_future)
diff --git a/src/corelib/thread/qfuturewatcher_p.h b/src/corelib/thread/qfuturewatcher_p.h
index 226642119a..84c608d1e0 100644
--- a/src/corelib/thread/qfuturewatcher_p.h
+++ b/src/corelib/thread/qfuturewatcher_p.h
@@ -63,8 +63,8 @@ class QFutureWatcherBasePrivate : public QObjectPrivate,
public:
QFutureWatcherBasePrivate();
- void postCallOutEvent(const QFutureCallOutEvent &callOutEvent);
- void callOutInterfaceDisconnected();
+ void postCallOutEvent(const QFutureCallOutEvent &callOutEvent) Q_DECL_OVERRIDE;
+ void callOutInterfaceDisconnected() Q_DECL_OVERRIDE;
void sendCallOutEvent(QFutureCallOutEvent *event);
diff --git a/src/corelib/thread/qthread.h b/src/corelib/thread/qthread.h
index 1d32580670..f9df407f72 100644
--- a/src/corelib/thread/qthread.h
+++ b/src/corelib/thread/qthread.h
@@ -89,7 +89,7 @@ public:
QAbstractEventDispatcher *eventDispatcher() const;
void setEventDispatcher(QAbstractEventDispatcher *eventDispatcher);
- bool event(QEvent *event);
+ bool event(QEvent *event) Q_DECL_OVERRIDE;
public Q_SLOTS:
void start(Priority = InheritPriority);
diff --git a/src/corelib/thread/qthread_p.h b/src/corelib/thread/qthread_p.h
index 83693921be..9c67ce4471 100644
--- a/src/corelib/thread/qthread_p.h
+++ b/src/corelib/thread/qthread_p.h
@@ -305,7 +305,7 @@ public:
void init();
private:
- void run();
+ void run() Q_DECL_OVERRIDE;
};
QT_END_NAMESPACE
diff --git a/src/corelib/thread/qthreadpool.cpp b/src/corelib/thread/qthreadpool.cpp
index c2a8bb0595..aaffdc2a4c 100644
--- a/src/corelib/thread/qthreadpool.cpp
+++ b/src/corelib/thread/qthreadpool.cpp
@@ -50,7 +50,7 @@ class QThreadPoolThread : public QThread
{
public:
QThreadPoolThread(QThreadPoolPrivate *manager);
- void run();
+ void run() Q_DECL_OVERRIDE;
void registerThreadInactive();
QWaitCondition runnableReady;
@@ -311,14 +311,12 @@ void QThreadPoolPrivate::clear()
/*!
\internal
Searches for \a runnable in the queue, removes it from the queue and
- runs it if found. This function does not return until the runnable
- has completed.
+ returns \c true if it was found in the queue
*/
-void QThreadPoolPrivate::stealRunnable(QRunnable *runnable)
+bool QThreadPoolPrivate::stealRunnable(QRunnable *runnable)
{
if (runnable == 0)
- return;
- bool found = false;
+ return false;
{
QMutexLocker locker(&mutex);
QList<QPair<QRunnable *, int> >::iterator it = queue.begin();
@@ -326,17 +324,26 @@ void QThreadPoolPrivate::stealRunnable(QRunnable *runnable)
while (it != end) {
if (it->first == runnable) {
- found = true;
queue.erase(it);
- break;
+ return true;
}
++it;
}
}
- if (!found)
- return;
+ return false;
+}
+ /*!
+ \internal
+ Searches for \a runnable in the queue, removes it from the queue and
+ runs it if found. This function does not return until the runnable
+ has completed.
+ */
+void QThreadPoolPrivate::stealAndRunRunnable(QRunnable *runnable)
+{
+ if (!stealRunnable(runnable))
+ return;
const bool autoDelete = runnable->autoDelete();
bool del = autoDelete && !--runnable->ref;
@@ -628,6 +635,25 @@ void QThreadPool::clear()
d->clear();
}
+/*!
+ \since 5.5
+
+ Removes the specified \a runnable from the queue if it is not yet started.
+ The runnables for which \l{QRunnable::autoDelete()}{runnable->autoDelete()}
+ returns \c true are deleted.
+
+ \sa start()
+*/
+void QThreadPool::cancel(QRunnable *runnable)
+{
+ Q_D(QThreadPool);
+ if (!d->stealRunnable(runnable))
+ return;
+ if (runnable->autoDelete() && !--runnable->ref) {
+ delete runnable;
+ }
+}
+
QT_END_NAMESPACE
#endif
diff --git a/src/corelib/thread/qthreadpool.h b/src/corelib/thread/qthreadpool.h
index e4d23cc200..c8cc5dfd89 100644
--- a/src/corelib/thread/qthreadpool.h
+++ b/src/corelib/thread/qthreadpool.h
@@ -77,6 +77,7 @@ public:
bool waitForDone(int msecs = -1);
void clear();
+ void cancel(QRunnable *runnable);
};
QT_END_NAMESPACE
diff --git a/src/corelib/thread/qthreadpool_p.h b/src/corelib/thread/qthreadpool_p.h
index d4308266a2..de2727adc1 100644
--- a/src/corelib/thread/qthreadpool_p.h
+++ b/src/corelib/thread/qthreadpool_p.h
@@ -76,7 +76,8 @@ public:
void reset();
bool waitForDone(int msecs);
void clear();
- void stealRunnable(QRunnable *);
+ bool stealRunnable(QRunnable *runnable);
+ void stealAndRunRunnable(QRunnable *runnable);
mutable QMutex mutex;
QSet<QThreadPoolThread *> allThreads;