summaryrefslogtreecommitdiffstats
path: root/src/corelib/thread
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/thread')
-rw-r--r--src/corelib/thread/qatomic.cpp77
-rw-r--r--src/corelib/thread/qatomic.h4
-rw-r--r--src/corelib/thread/qmutex.cpp42
-rw-r--r--src/corelib/thread/qmutex.h1
-rw-r--r--src/corelib/thread/qmutex_linux.cpp9
-rw-r--r--src/corelib/thread/qmutexpool.cpp4
-rw-r--r--src/corelib/thread/qreadwritelock.cpp24
-rw-r--r--src/corelib/thread/qsemaphore.cpp8
-rw-r--r--src/corelib/thread/qthread.cpp12
-rw-r--r--src/corelib/thread/qthread_unix.cpp27
-rw-r--r--src/corelib/thread/qthread_win.cpp2
-rw-r--r--src/corelib/thread/qthreadpool.cpp43
-rw-r--r--src/corelib/thread/qthreadpool.h3
-rw-r--r--src/corelib/thread/qthreadpool_p.h2
-rw-r--r--src/corelib/thread/qthreadstorage.cpp6
-rw-r--r--src/corelib/thread/qwaitcondition.qdoc8
16 files changed, 90 insertions, 182 deletions
diff --git a/src/corelib/thread/qatomic.cpp b/src/corelib/thread/qatomic.cpp
index 2e3029f3fa..abd2cc1c93 100644
--- a/src/corelib/thread/qatomic.cpp
+++ b/src/corelib/thread/qatomic.cpp
@@ -68,7 +68,7 @@
functions allow you to implement your own implicitly shared
classes.
- \snippet doc/src/snippets/code/src_corelib_thread_qatomic.cpp 0
+ \snippet code/src_corelib_thread_qatomic.cpp 0
\section2 Memory ordering
@@ -104,7 +104,7 @@
nothing and return false. This operation equates to the following
code:
- \snippet doc/src/snippets/code/src_corelib_thread_qatomic.cpp 1
+ \snippet code/src_corelib_thread_qatomic.cpp 1
There are 4 test-and-set functions: testAndSetRelaxed(),
testAndSetAcquire(), testAndSetRelease(), and
@@ -117,7 +117,7 @@
QAtomicInt and then assign a new value, returning the original
value. This operation equates to the following code:
- \snippet doc/src/snippets/code/src_corelib_thread_qatomic.cpp 2
+ \snippet code/src_corelib_thread_qatomic.cpp 2
There are 4 fetch-and-store functions: fetchAndStoreRelaxed(),
fetchAndStoreAcquire(), fetchAndStoreRelease(), and
@@ -131,7 +131,7 @@
returning the original value. This operation equates to the
following code:
- \snippet doc/src/snippets/code/src_corelib_thread_qatomic.cpp 3
+ \snippet code/src_corelib_thread_qatomic.cpp 3
There are 4 fetch-and-add functions: fetchAndAddRelaxed(),
fetchAndAddAcquire(), fetchAndAddRelease(), and
@@ -215,41 +215,12 @@
Constructs a copy of \a other.
*/
-/*! \fn QAtomicInt &QAtomicInt::operator=(int value)
-
- Assigns the \a value to this QAtomicInt and returns a reference to
- this QAtomicInt.
-*/
-
/*! \fn QAtomicInt &QAtomicInt::operator=(const QAtomicInt &other)
Assigns \a other to this QAtomicInt and returns a reference to
this QAtomicInt.
*/
-/*! \fn bool QAtomicInt::operator==(int value) const
-
- Returns true if the \a value is equal to the value in this
- QAtomicInt; otherwise returns false.
-*/
-
-/*! \fn bool QAtomicInt::operator!=(int value) const
-
- Returns true if the value of this QAtomicInt is not equal to \a
- value; otherwise returns false.
-*/
-
-/*! \fn bool QAtomicInt::operator!() const
-
- Returns true is the value of this QAtomicInt is zero; otherwise
- returns false.
-*/
-
-/*! \fn QAtomicInt::operator int() const
-
- Returns the value stored by the QAtomicInt object as an integer.
-*/
-
/*! \fn bool QAtomicInt::isReferenceCountingNative()
Returns true if reference counting is implemented using atomic
@@ -679,7 +650,7 @@
these functions do nothing and return false. This operation
equates to the following code:
- \snippet doc/src/snippets/code/src_corelib_thread_qatomic.cpp 4
+ \snippet code/src_corelib_thread_qatomic.cpp 4
There are 4 test-and-set functions: testAndSetRelaxed(),
testAndSetAcquire(), testAndSetRelease(), and
@@ -692,7 +663,7 @@
QAtomicPointer and then assign a new value, returning the original
value. This operation equates to the following code:
- \snippet doc/src/snippets/code/src_corelib_thread_qatomic.cpp 5
+ \snippet code/src_corelib_thread_qatomic.cpp 5
There are 4 fetch-and-store functions: fetchAndStoreRelaxed(),
fetchAndStoreAcquire(), fetchAndStoreRelease(), and
@@ -706,7 +677,7 @@
returning the original value. This operation equates to the
following code:
- \snippet doc/src/snippets/code/src_corelib_thread_qatomic.cpp 6
+ \snippet code/src_corelib_thread_qatomic.cpp 6
There are 4 fetch-and-add functions: fetchAndAddRelaxed(),
fetchAndAddAcquire(), fetchAndAddRelease(), and
@@ -783,46 +754,12 @@
Constructs a copy of \a other.
*/
-/*! \fn QAtomicPointer<T> &QAtomicPointer::operator=(T *value)
-
- Assigns the \a value to this QAtomicPointer and returns a
- reference to this QAtomicPointer.
-*/
-
/*! \fn QAtomicPointer<T> &QAtomicPointer::operator=(const QAtomicPointer<T> &other)
Assigns \a other to this QAtomicPointer and returns a reference to
this QAtomicPointer.
*/
-/*! \fn bool QAtomicPointer::operator==(T *value) const
-
- Returns true if the \a value is equal to the value in this
- QAtomicPointer; otherwise returns false.
-*/
-
-/*! \fn bool QAtomicPointer::operator!=(T *value) const
-
- Returns true if the value of this QAtomicPointer is not equal to
- \a value; otherwise returns false.
-*/
-
-/*! \fn bool QAtomicPointer::operator!() const
-
- Returns true is the current value of this QAtomicPointer is zero;
- otherwise returns false.
-*/
-
-/*! \fn QAtomicPointer::operator T *() const
-
- Returns the current pointer value stored by this QAtomicPointer
- object.
-*/
-
-/*! \fn T *QAtomicPointer::operator->() const
-
-*/
-
/*! \fn bool QAtomicPointer::isTestAndSetNative()
Returns true if test-and-set is implemented using atomic processor
diff --git a/src/corelib/thread/qatomic.h b/src/corelib/thread/qatomic.h
index a8e321b46a..5cd9a6a5c4 100644
--- a/src/corelib/thread/qatomic.h
+++ b/src/corelib/thread/qatomic.h
@@ -165,7 +165,7 @@ public:
This is a helper for the assignment operators of implicitly
shared classes. Your assignment operator should look like this:
- \snippet doc/src/snippets/code/src.corelib.thread.qatomic.h 0
+ \snippet code/src.corelib.thread.qatomic.h 0
*/
template <typename T>
inline void qAtomicAssign(T *&d, T *x)
@@ -184,7 +184,7 @@ inline void qAtomicAssign(T *&d, T *x)
the members and sets the refcount to 1. After that, your detach
function should look like this:
- \snippet doc/src/snippets/code/src.corelib.thread.qatomic.h 1
+ \snippet code/src.corelib.thread.qatomic.h 1
*/
template <typename T>
inline void qAtomicDetach(T *&d)
diff --git a/src/corelib/thread/qmutex.cpp b/src/corelib/thread/qmutex.cpp
index 049230f7a4..145916d750 100644
--- a/src/corelib/thread/qmutex.cpp
+++ b/src/corelib/thread/qmutex.cpp
@@ -55,7 +55,7 @@
QT_BEGIN_NAMESPACE
-/*!
+/*
\class QBasicMutex
\brief QMutex POD
\internal
@@ -86,20 +86,20 @@ QT_BEGIN_NAMESPACE
For example, say there is a method that prints a message to the
user on two lines:
- \snippet doc/src/snippets/code/src_corelib_thread_qmutex.cpp 0
+ \snippet code/src_corelib_thread_qmutex.cpp 0
If these two methods are called in succession, the following happens:
- \snippet doc/src/snippets/code/src_corelib_thread_qmutex.cpp 1
+ \snippet code/src_corelib_thread_qmutex.cpp 1
If these two methods are called simultaneously from two threads then the
following sequence could result:
- \snippet doc/src/snippets/code/src_corelib_thread_qmutex.cpp 2
+ \snippet code/src_corelib_thread_qmutex.cpp 2
If we add a mutex, we should get the result we want:
- \snippet doc/src/snippets/code/src_corelib_thread_qmutex.cpp 3
+ \snippet code/src_corelib_thread_qmutex.cpp 3
Then only one thread can modify \c number at any given time and
the result is correct. This is a trivial example, of course, but
@@ -178,26 +178,7 @@ QMutex::~QMutex()
\sa unlock()
*/
-/*!\fn bool QMutex::trylock()
- Attempts to lock the mutex. If the lock was obtained, this function
- returns true. If another thread has locked the mutex, this
- function returns false immediately.
-
- If the lock was obtained, the mutex must be unlocked with unlock()
- before another thread can successfully lock it.
-
- Calling this function multiple times on the same mutex from the
- same thread is allowed if this mutex is a
- \l{QMutex::Recursive}{recursive mutex}. If this mutex is a
- \l{QMutex::NonRecursive}{non-recursive mutex}, this function will
- \e always return false when attempting to lock the mutex
- recursively.
-
- \sa lock(), unlock()
-*/
-
/*! \fn bool QMutex::tryLock(int timeout)
- \overload
Attempts to lock the mutex. This function returns true if the lock
was obtained; otherwise it returns false. If another thread has
@@ -268,7 +249,7 @@ bool QBasicMutex::isRecursive() {
For example, this complex function locks a QMutex upon entering
the function and unlocks the mutex at all the exit points:
- \snippet doc/src/snippets/code/src_corelib_thread_qmutex.cpp 4
+ \snippet code/src_corelib_thread_qmutex.cpp 4
This example function will get more complicated as it is
developed, which increases the likelihood that errors will occur.
@@ -276,7 +257,7 @@ bool QBasicMutex::isRecursive() {
Using QMutexLocker greatly simplifies the code, and makes it more
readable:
- \snippet doc/src/snippets/code/src_corelib_thread_qmutex.cpp 5
+ \snippet code/src_corelib_thread_qmutex.cpp 5
Now, the mutex will always be unlocked when the QMutexLocker
object is destroyed (when the function returns since \c locker is
@@ -292,7 +273,7 @@ bool QBasicMutex::isRecursive() {
for code that needs access to the mutex, such as
QWaitCondition::wait(). For example:
- \snippet doc/src/snippets/code/src_corelib_thread_qmutex.cpp 6
+ \snippet code/src_corelib_thread_qmutex.cpp 6
\sa QReadLocker, QWriteLocker, QMutex
*/
@@ -317,13 +298,6 @@ bool QBasicMutex::isRecursive() {
*/
/*!
- \fn QMutex *QMutexLocker::mutex() const
-
- Returns a pointer to the mutex that was locked in the
- constructor.
-*/
-
-/*!
\fn void QMutexLocker::unlock()
Unlocks this mutex locker. You can use \c relock() to lock
diff --git a/src/corelib/thread/qmutex.h b/src/corelib/thread/qmutex.h
index 9a81b3d4bd..0743c36457 100644
--- a/src/corelib/thread/qmutex.h
+++ b/src/corelib/thread/qmutex.h
@@ -158,7 +158,6 @@ private:
#else // QT_NO_THREAD or qdoc
-
class Q_CORE_EXPORT QMutex
{
public:
diff --git a/src/corelib/thread/qmutex_linux.cpp b/src/corelib/thread/qmutex_linux.cpp
index 1bb5e77e77..a10bd35eff 100644
--- a/src/corelib/thread/qmutex_linux.cpp
+++ b/src/corelib/thread/qmutex_linux.cpp
@@ -51,6 +51,7 @@
#include <sys/syscall.h>
#include <unistd.h>
#include <errno.h>
+#include <asm/unistd.h>
#ifndef QT_LINUX_FUTEX
# error "Qt build is broken: qmutex_linux.cpp is being built but futex support is not wanted"
@@ -71,7 +72,7 @@ static inline int futexFlags()
// try an operation that has no side-effects: wake up 42 threads
// futex will return -1 (errno==ENOSYS) if the flag isn't supported
// there should be no other error conditions
- value = syscall(SYS_futex, &futexFlagSupport,
+ value = syscall(__NR_futex, &futexFlagSupport,
FUTEX_WAKE | FUTEX_PRIVATE_FLAG,
42, 0, 0, 0);
if (value != -1) {
@@ -95,7 +96,9 @@ static inline int _q_futex(void *addr, int op, int val, const struct timespec *t
int *addr2 = 0;
int val2 = 0;
- return syscall(SYS_futex, int_addr, op | futexFlags(), val, timeout, addr2, val2);
+ // we use __NR_futex because some libcs (like Android's bionic) don't
+ // provide SYS_futex etc.
+ return syscall(__NR_futex, int_addr, op | futexFlags(), val, timeout, addr2, val2);
}
static inline QMutexData *dummyFutexValue()
@@ -121,7 +124,7 @@ bool QBasicMutex::lockInternal(int timeout)
struct timespec ts, *pts = 0;
if (timeout >= 1) {
// recalculate the timeout
- qint64 xtimeout = timeout * 1000 * 1000;
+ qint64 xtimeout = qint64(timeout) * 1000 * 1000;
xtimeout -= elapsedTimer.nsecsElapsed();
if (xtimeout <= 0) {
// timer expired after we returned
diff --git a/src/corelib/thread/qmutexpool.cpp b/src/corelib/thread/qmutexpool.cpp
index 6b6674ccdf..4d24f8c7c7 100644
--- a/src/corelib/thread/qmutexpool.cpp
+++ b/src/corelib/thread/qmutexpool.cpp
@@ -66,7 +66,7 @@ Q_GLOBAL_STATIC_WITH_ARGS(QMutexPool, globalMutexPool, (QMutex::Recursive))
For example, consider this simple class:
- \snippet doc/src/snippets/code/src_corelib_thread_qmutexpool.cpp 0
+ \snippet code/src_corelib_thread_qmutexpool.cpp 0
Adding a QMutex member to the Number class does not make sense,
because it is so small. However, in order to ensure that access to
@@ -76,7 +76,7 @@ Q_GLOBAL_STATIC_WITH_ARGS(QMutexPool, globalMutexPool, (QMutex::Recursive))
Code to calculate the square of a number would then look something
like this:
- \snippet doc/src/snippets/code/src_corelib_thread_qmutexpool.cpp 1
+ \snippet code/src_corelib_thread_qmutexpool.cpp 1
This function will safely calculate the square of a number, since
it uses a mutex from a QMutexPool. The mutex is locked and
diff --git a/src/corelib/thread/qreadwritelock.cpp b/src/corelib/thread/qreadwritelock.cpp
index 519bae9fa6..1aba2f537e 100644
--- a/src/corelib/thread/qreadwritelock.cpp
+++ b/src/corelib/thread/qreadwritelock.cpp
@@ -71,7 +71,7 @@ QT_BEGIN_NAMESPACE
Example:
- \snippet doc/src/snippets/code/src_corelib_thread_qreadwritelock.cpp 0
+ \snippet code/src_corelib_thread_qreadwritelock.cpp 0
To ensure that writers aren't blocked forever by readers, readers
attempting to obtain a lock will not succeed if there is a blocked
@@ -135,7 +135,7 @@ QReadWriteLock::~QReadWriteLock()
thread if any thread (including the current) has locked for
writing.
- \sa unlock() lockForWrite() tryLockForRead()
+ \sa unlock(), lockForWrite(), tryLockForRead()
*/
void QReadWriteLock::lockForRead()
{
@@ -178,7 +178,7 @@ void QReadWriteLock::lockForRead()
If the lock was obtained, the lock must be unlocked with unlock()
before another thread can successfully lock it.
- \sa unlock() lockForRead()
+ \sa unlock(), lockForRead()
*/
bool QReadWriteLock::tryLockForRead()
{
@@ -223,7 +223,7 @@ bool QReadWriteLock::tryLockForRead()
If the lock was obtained, the lock must be unlocked with unlock()
before another thread can successfully lock it.
- \sa unlock() lockForRead()
+ \sa unlock(), lockForRead()
*/
bool QReadWriteLock::tryLockForRead(int timeout)
{
@@ -263,7 +263,7 @@ bool QReadWriteLock::tryLockForRead(int timeout)
Locks the lock for writing. This function will block the current
thread if another thread has locked for reading or writing.
- \sa unlock() lockForRead() tryLockForWrite()
+ \sa unlock(), lockForRead(), tryLockForWrite()
*/
void QReadWriteLock::lockForWrite()
{
@@ -303,7 +303,7 @@ void QReadWriteLock::lockForWrite()
If the lock was obtained, the lock must be unlocked with unlock()
before another thread can successfully lock it.
- \sa unlock() lockForWrite()
+ \sa unlock(), lockForWrite()
*/
bool QReadWriteLock::tryLockForWrite()
{
@@ -347,7 +347,7 @@ bool QReadWriteLock::tryLockForWrite()
If the lock was obtained, the lock must be unlocked with unlock()
before another thread can successfully lock it.
- \sa unlock() lockForWrite()
+ \sa unlock(), lockForWrite()
*/
bool QReadWriteLock::tryLockForWrite(int timeout)
{
@@ -389,7 +389,7 @@ bool QReadWriteLock::tryLockForWrite(int timeout)
Attempting to unlock a lock that is not locked is an error, and will result
in program termination.
- \sa lockForRead() lockForWrite() tryLockForRead() tryLockForWrite()
+ \sa lockForRead(), lockForWrite(), tryLockForRead(), tryLockForWrite()
*/
void QReadWriteLock::unlock()
{
@@ -443,11 +443,11 @@ void QReadWriteLock::unlock()
Here's an example that uses QReadLocker to lock and unlock a
read-write lock for reading:
- \snippet doc/src/snippets/code/src_corelib_thread_qreadwritelock.cpp 1
+ \snippet code/src_corelib_thread_qreadwritelock.cpp 1
It is equivalent to the following code:
- \snippet doc/src/snippets/code/src_corelib_thread_qreadwritelock.cpp 2
+ \snippet code/src_corelib_thread_qreadwritelock.cpp 2
The QMutexLocker documentation shows examples where the use of a
locker object greatly simplifies programming.
@@ -515,11 +515,11 @@ void QReadWriteLock::unlock()
Here's an example that uses QWriteLocker to lock and unlock a
read-write lock for writing:
- \snippet doc/src/snippets/code/src_corelib_thread_qreadwritelock.cpp 3
+ \snippet code/src_corelib_thread_qreadwritelock.cpp 3
It is equivalent to the following code:
- \snippet doc/src/snippets/code/src_corelib_thread_qreadwritelock.cpp 4
+ \snippet code/src_corelib_thread_qreadwritelock.cpp 4
The QMutexLocker documentation shows examples where the use of a
locker object greatly simplifies programming.
diff --git a/src/corelib/thread/qsemaphore.cpp b/src/corelib/thread/qsemaphore.cpp
index 08952eeaa3..e5b460b725 100644
--- a/src/corelib/thread/qsemaphore.cpp
+++ b/src/corelib/thread/qsemaphore.cpp
@@ -78,7 +78,7 @@ QT_BEGIN_NAMESPACE
Example:
- \snippet doc/src/snippets/code/src_corelib_thread_qsemaphore.cpp 0
+ \snippet code/src_corelib_thread_qsemaphore.cpp 0
A typical application of semaphores is for controlling access to
a circular buffer shared by a producer thread and a consumer
@@ -151,7 +151,7 @@ void QSemaphore::acquire(int n)
This function can be used to "create" resources as well. For
example:
- \snippet doc/src/snippets/code/src_corelib_thread_qsemaphore.cpp 1
+ \snippet code/src_corelib_thread_qsemaphore.cpp 1
\sa acquire(), available()
*/
@@ -182,7 +182,7 @@ int QSemaphore::available() const
Example:
- \snippet doc/src/snippets/code/src_corelib_thread_qsemaphore.cpp 2
+ \snippet code/src_corelib_thread_qsemaphore.cpp 2
\sa acquire()
*/
@@ -208,7 +208,7 @@ bool QSemaphore::tryAcquire(int n)
Example:
- \snippet doc/src/snippets/code/src_corelib_thread_qsemaphore.cpp 3
+ \snippet code/src_corelib_thread_qsemaphore.cpp 3
\sa acquire()
*/
diff --git a/src/corelib/thread/qthread.cpp b/src/corelib/thread/qthread.cpp
index ea6760a1b9..f93f383d3c 100644
--- a/src/corelib/thread/qthread.cpp
+++ b/src/corelib/thread/qthread.cpp
@@ -184,7 +184,7 @@ QThreadPrivate::~QThreadPrivate()
below). To create your own threads, subclass QThread and
reimplement run(). For example:
- \snippet doc/src/snippets/code/src_corelib_thread_qthread.cpp 0
+ \snippet code/src_corelib_thread_qthread.cpp 0
This will create a QTcpSocket in the thread and then execute the
thread's event loop. Use the start() method to begin execution.
@@ -493,7 +493,7 @@ int QThread::exec()
is not running then the next call to QThread::exec() will also return
immediately.
- \sa quit() QEventLoop
+ \sa quit(), QEventLoop
*/
void QThread::exit(int returnCode)
{
@@ -515,7 +515,7 @@ void QThread::exit(int returnCode)
This function does nothing if the thread does not have an event
loop.
- \sa exit() QEventLoop
+ \sa exit(), QEventLoop
*/
void QThread::quit()
{ exit(); }
@@ -529,7 +529,7 @@ void QThread::quit()
work. Returning from this method will end the execution of the
thread.
- \sa start() wait()
+ \sa start(), wait()
*/
void QThread::run()
{
@@ -553,7 +553,7 @@ void QThread::run()
(such as on Linux, see http://linux.die.net/man/2/sched_setscheduler
for more details).
- \sa Priority priority() start()
+ \sa Priority, priority(), start()
*/
/*!
@@ -562,7 +562,7 @@ void QThread::run()
Returns the priority for a running thread. If the thread is not
running, this function returns \c InheritPriority.
- \sa Priority setPriority() start()
+ \sa Priority, setPriority(), start()
*/
QThread::Priority QThread::priority() const
{
diff --git a/src/corelib/thread/qthread_unix.cpp b/src/corelib/thread/qthread_unix.cpp
index 21ed8131df..a47115cfac 100644
--- a/src/corelib/thread/qthread_unix.cpp
+++ b/src/corelib/thread/qthread_unix.cpp
@@ -44,11 +44,15 @@
#include "qplatformdefs.h"
#include <private/qcoreapplication_p.h>
-#if !defined(QT_NO_GLIB)
-# include "../kernel/qeventdispatcher_glib_p.h"
-#endif
-#include <private/qeventdispatcher_unix_p.h>
+#if defined(Q_OS_BLACKBERRY)
+# include <private/qeventdispatcher_blackberry_p.h>
+#else
+# if !defined(QT_NO_GLIB)
+# include "../kernel/qeventdispatcher_glib_p.h"
+# endif
+# include <private/qeventdispatcher_unix_p.h>
+#endif
#include "qthreadstorage.h"
@@ -79,9 +83,9 @@
# define old_qDebug qDebug
# undef qDebug
# endif
-#ifndef QT_NO_CORESERVICES
+#ifndef Q_OS_IOS
# include <CoreServices/CoreServices.h>
-#endif //QT_NO_CORESERVICES
+#endif //Q_OS_IOS
# ifdef old_qDebug
# undef qDebug
@@ -248,6 +252,9 @@ typedef void*(*QtThreadCallback)(void*);
void QThreadPrivate::createEventDispatcher(QThreadData *data)
{
+#if defined(Q_OS_BLACKBERRY)
+ data->eventDispatcher = new QEventDispatcherBlackberry;
+#else
#if !defined(QT_NO_GLIB)
if (qgetenv("QT_NO_GLIB").isEmpty()
&& qgetenv("QT_NO_THREADED_GLIB").isEmpty()
@@ -256,6 +263,8 @@ void QThreadPrivate::createEventDispatcher(QThreadData *data)
else
#endif
data->eventDispatcher = new QEventDispatcherUNIX;
+#endif
+
data->eventDispatcher->startingUp();
}
@@ -288,7 +297,7 @@ void *QThreadPrivate::start(void *arg)
else
createEventDispatcher(data);
-#if (defined(Q_OS_LINUX) || defined(Q_OS_MAC))
+#if (defined(Q_OS_LINUX) || defined(Q_OS_MAC) || defined(Q_OS_QNX))
// sets the name of the current thread.
QByteArray objectName = thr->objectName().toLocal8Bit();
@@ -299,6 +308,8 @@ void *QThreadPrivate::start(void *arg)
prctl(PR_SET_NAME, (unsigned long)objectName.constData(), 0, 0, 0);
#elif defined(Q_OS_MAC)
pthread_setname_np(objectName.constData());
+#elif defined(Q_OS_QNX)
+ pthread_setname_np(thr->d_func()->thread_id, objectName.constData());
#endif
#endif
@@ -371,7 +382,7 @@ int QThread::idealThreadCount()
{
int cores = -1;
-#if defined(Q_OS_MAC) && !defined(QT_NO_CORESERVICES)
+#if defined(Q_OS_MAC) && !defined(Q_OS_IOS)
// Mac OS X
cores = MPProcessorsScheduled();
#elif defined(Q_OS_HPUX)
diff --git a/src/corelib/thread/qthread_win.cpp b/src/corelib/thread/qthread_win.cpp
index 1cde07e330..433c561f1f 100644
--- a/src/corelib/thread/qthread_win.cpp
+++ b/src/corelib/thread/qthread_win.cpp
@@ -182,7 +182,7 @@ void qt_watch_adopted_thread(const HANDLE adoptedThreadHandle, QThread *qthread)
}
}
-/*! \internal
+/*
This function loops and waits for native adopted threads to finish.
When this happens it derefs the QThreadData for the adopted thread
to make sure it gets cleaned up properly.
diff --git a/src/corelib/thread/qthreadpool.cpp b/src/corelib/thread/qthreadpool.cpp
index b7021817c5..c913146122 100644
--- a/src/corelib/thread/qthreadpool.cpp
+++ b/src/corelib/thread/qthreadpool.cpp
@@ -47,15 +47,6 @@
QT_BEGIN_NAMESPACE
-inline bool operator<(int priority, const QPair<QRunnable *, int> &p)
-{
- return p.second < priority;
-}
-inline bool operator<(const QPair<QRunnable *, int> &p, int priority)
-{
- return priority < p.second;
-}
-
Q_GLOBAL_STATIC(QThreadPool, theInstance)
/*
@@ -209,15 +200,22 @@ bool QThreadPoolPrivate::tryStart(QRunnable *task)
return true;
}
+inline bool operator<(int priority, const QPair<QRunnable *, int> &p)
+{ return p.second < priority; }
+inline bool operator<(const QPair<QRunnable *, int> &p, int priority)
+{ return priority < p.second; }
+
void QThreadPoolPrivate::enqueueTask(QRunnable *runnable, int priority)
{
if (runnable->autoDelete())
++runnable->ref;
// put it on the queue
- QList<QPair<QRunnable *, int> >::iterator at =
- qUpperBound(queue.begin(), queue.end(), priority);
- queue.insert(at, qMakePair(runnable, priority));
+ QList<QPair<QRunnable *, int> >::const_iterator begin = queue.constBegin();
+ QList<QPair<QRunnable *, int> >::const_iterator it = queue.constEnd();
+ if (it != begin && priority < (*(it - 1)).second)
+ it = qUpperBound(begin, --it, priority);
+ queue.insert(it - begin, qMakePair(runnable, priority));
runnableReady.wakeOne();
}
@@ -362,7 +360,7 @@ void QThreadPoolPrivate::stealRunnable(QRunnable *runnable)
the run() virtual function. Then create an object of that class and pass
it to QThreadPool::start().
- \snippet doc/src/snippets/code/src_corelib_concurrent_qthreadpool.cpp 0
+ \snippet code/src_corelib_concurrent_qthreadpool.cpp 0
QThreadPool deletes the QRunnable automatically by default. Use
QRunnable::setAutoDelete() to change the auto-deletion flag.
@@ -412,8 +410,7 @@ QThreadPool::QThreadPool(QObject *parent)
*/
QThreadPool::~QThreadPool()
{
- d_func()->waitForDone();
- d_func()->reset();
+ waitForDone();
}
/*!
@@ -595,22 +592,10 @@ void QThreadPool::releaseThread()
}
/*!
- Waits for each thread to exit and removes all threads from the thread pool.
-*/
-void QThreadPool::waitForDone()
-{
- Q_D(QThreadPool);
- d->waitForDone();
- d->reset();
-}
-
-/*!
- \overload waitForDone()
- \since 4.8
-
Waits up to \a msecs milliseconds for all threads to exit and removes all
threads from the thread pool. Returns true if all threads were removed;
- otherwise it returns false.
+ otherwise it returns false. If \a msecs is -1 (the default), the timeout
+ is ignored (waits for the last thread to exit).
*/
bool QThreadPool::waitForDone(int msecs)
{
diff --git a/src/corelib/thread/qthreadpool.h b/src/corelib/thread/qthreadpool.h
index 9fc023c56d..dd931713f7 100644
--- a/src/corelib/thread/qthreadpool.h
+++ b/src/corelib/thread/qthreadpool.h
@@ -83,8 +83,7 @@ public:
void reserveThread();
void releaseThread();
- void waitForDone();
- bool waitForDone(int msecs);
+ bool waitForDone(int msecs = -1);
};
QT_END_NAMESPACE
diff --git a/src/corelib/thread/qthreadpool_p.h b/src/corelib/thread/qthreadpool_p.h
index 910e0b0714..760732993d 100644
--- a/src/corelib/thread/qthreadpool_p.h
+++ b/src/corelib/thread/qthreadpool_p.h
@@ -82,7 +82,7 @@ public:
void startThread(QRunnable *runnable = 0);
void reset();
- bool waitForDone(int msecs = -1);
+ bool waitForDone(int msecs);
void stealRunnable(QRunnable *);
mutable QMutex mutex;
diff --git a/src/corelib/thread/qthreadstorage.cpp b/src/corelib/thread/qthreadstorage.cpp
index 68db8fe261..caa2ac907f 100644
--- a/src/corelib/thread/qthreadstorage.cpp
+++ b/src/corelib/thread/qthreadstorage.cpp
@@ -238,9 +238,9 @@ void QThreadStorageData::finish(void **p)
removeFromCache() functions. The cache is automatically
deleted when the calling thread exits.
- \snippet doc/src/snippets/threads/threads.cpp 7
- \snippet doc/src/snippets/threads/threads.cpp 8
- \snippet doc/src/snippets/threads/threads.cpp 9
+ \snippet threads/threads.cpp 7
+ \snippet threads/threads.cpp 8
+ \snippet threads/threads.cpp 9
\section1 Caveats
diff --git a/src/corelib/thread/qwaitcondition.qdoc b/src/corelib/thread/qwaitcondition.qdoc
index 81c095f394..58679c4543 100644
--- a/src/corelib/thread/qwaitcondition.qdoc
+++ b/src/corelib/thread/qwaitcondition.qdoc
@@ -45,7 +45,7 @@
split into a thread, each of which would have a
\l{QThread::run()}{run()} body like this:
- \snippet doc/src/snippets/code/src_corelib_thread_qwaitcondition_unix.cpp 0
+ \snippet code/src_corelib_thread_qwaitcondition_unix.cpp 0
Here, the \c keyPressed variable is a global variable of type
QWaitCondition.
@@ -53,7 +53,7 @@
A fourth thread would read key presses and wake the other three
threads up every time it receives one, like this:
- \snippet doc/src/snippets/code/src_corelib_thread_qwaitcondition_unix.cpp 1
+ \snippet code/src_corelib_thread_qwaitcondition_unix.cpp 1
The order in which the three threads are woken up is undefined.
Also, if some of the threads are still in \c do_something() when
@@ -63,11 +63,11 @@
counter and a QMutex to guard it. For example, here's the new
code for the worker threads:
- \snippet doc/src/snippets/code/src_corelib_thread_qwaitcondition_unix.cpp 2
+ \snippet code/src_corelib_thread_qwaitcondition_unix.cpp 2
Here's the code for the fourth thread:
- \snippet doc/src/snippets/code/src_corelib_thread_qwaitcondition_unix.cpp 3
+ \snippet code/src_corelib_thread_qwaitcondition_unix.cpp 3
The mutex is necessary because the results of two threads
attempting to change the value of the same variable