From c012ee2940bc087720b4aa0d257540921cf9a139 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sat, 21 Sep 2013 17:42:33 +0200 Subject: QObject: use per-thread storage for qFlagLocation() qFlagLocation() uses a global char* array to transport source location information from the connect() side to the metaobject side. The size of the array is 2 (two), which just about suffices for a single connect() statement. Obviously, if more than one thread makes a (_any_) connection at the same time, the data is useless and, worse, there's a data race. The non-reentrancy of qFlagLocations() cannot and need not be fixed, but use a per-thread flagged_locations array in QThreadData so threads don't disturb each other. Task-number: QTBUG-3680 Change-Id: If1797c60751f551694def69afee6fbe295bbe2d2 Reviewed-by: Olivier Goffart --- src/corelib/thread/qthread_p.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/corelib/thread') diff --git a/src/corelib/thread/qthread_p.h b/src/corelib/thread/qthread_p.h index 5e4eedaac7..fa1f7414f1 100644 --- a/src/corelib/thread/qthread_p.h +++ b/src/corelib/thread/qthread_p.h @@ -242,6 +242,26 @@ public: return canWait; } + // This class provides per-thread (by way of being a QThreadData + // member) storage for qFlagLocation() + class FlaggedDebugSignatures + { + static const uint Count = 2; + + uint idx; + const char* locations[Count]; + + public: + FlaggedDebugSignatures() : idx(0) + { std::fill_n(locations, Count, static_cast(0)); } + + void store(const char* method) + { locations[idx++ % Count] = method; } + + bool contains(const char *method) const + { return std::find(locations, locations + Count, method) != locations + Count; } + }; + QThread *thread; Qt::HANDLE threadId; bool quitNow; @@ -252,6 +272,7 @@ public: bool canWait; QVector tls; bool isAdopted; + FlaggedDebugSignatures flaggedSignatures; }; class QScopedLoopLevelCounter -- cgit v1.2.3 From 4533cc994484a2308297e64e99af005fb4dca065 Mon Sep 17 00:00:00 2001 From: Jerome Pasion Date: Wed, 2 Oct 2013 16:51:05 +0200 Subject: Doc: Adding mark-up to boolean default values. Default values should have mark-up to denote that they are code. This commit changes: -"property is true" to "property is \c true". -"Returns true" to "Returns \c true". -"property is false" to "property is \c false". -"returns true" to "returns \c true". -"returns false" to "returns \c false". src/3rdparty and non-documentation instances were ignored. Task-number: QTBUG-33360 Change-Id: Ie87eaa57af947caa1230602b61c5c46292a4cf4e Reviewed-by: Oswald Buddenhagen Reviewed-by: Jerome Pasion --- src/corelib/thread/qatomic.cpp | 48 ++++++++++++++--------------- src/corelib/thread/qfuture.qdoc | 48 ++++++++++++++--------------- src/corelib/thread/qfuturesynchronizer.qdoc | 4 +-- src/corelib/thread/qfuturewatcher.cpp | 24 +++++++-------- src/corelib/thread/qmutex.cpp | 6 ++-- src/corelib/thread/qreadwritelock.cpp | 12 ++++---- src/corelib/thread/qrunnable.cpp | 4 +-- src/corelib/thread/qsemaphore.cpp | 6 ++-- src/corelib/thread/qthread.cpp | 6 ++-- src/corelib/thread/qthreadpool.cpp | 18 +++++------ src/corelib/thread/qthreadstorage.cpp | 2 +- 11 files changed, 89 insertions(+), 89 deletions(-) (limited to 'src/corelib/thread') diff --git a/src/corelib/thread/qatomic.cpp b/src/corelib/thread/qatomic.cpp index 11623f80dc..39d136c006 100644 --- a/src/corelib/thread/qatomic.cpp +++ b/src/corelib/thread/qatomic.cpp @@ -256,18 +256,18 @@ /*! \fn bool QAtomicInt::isReferenceCountingNative() - Returns true if reference counting is implemented using atomic + Returns \c true if reference counting is implemented using atomic processor instructions, false otherwise. */ /*! \fn bool QAtomicInt::isReferenceCountingWaitFree() - Returns true if atomic reference counting is wait-free, false + Returns \c true if atomic reference counting is wait-free, false otherwise. */ /*! \fn bool QAtomicInt::ref() - Atomically increments the value of this QAtomicInt. Returns true + Atomically increments the value of this QAtomicInt. Returns \c true if the new value is non-zero, false otherwise. This function uses \e ordered \l {QAtomicInt#Memory @@ -279,7 +279,7 @@ */ /*! \fn bool QAtomicInt::deref() - Atomically decrements the value of this QAtomicInt. Returns true + Atomically decrements the value of this QAtomicInt. Returns \c true if the new value is non-zero, false otherwise. This function uses \e ordered \l {QAtomicInt#Memory @@ -292,13 +292,13 @@ /*! \fn bool QAtomicInt::isTestAndSetNative() - Returns true if test-and-set is implemented using atomic processor + Returns \c true if test-and-set is implemented using atomic processor instructions, false otherwise. */ /*! \fn bool QAtomicInt::isTestAndSetWaitFree() - Returns true if atomic test-and-set is wait-free, false otherwise. + Returns \c true if atomic test-and-set is wait-free, false otherwise. */ /*! \fn bool QAtomicInt::testAndSetRelaxed(int expectedValue, int newValue) @@ -308,7 +308,7 @@ If the current value of this QAtomicInt is the \a expectedValue, the test-and-set functions assign the \a newValue to this QAtomicInt and return true. If the values are \e not the same, - this function does nothing and returns false. + this function does nothing and returns \c false. This function uses \e relaxed \l {QAtomicInt#Memory ordering}{memory ordering} semantics, leaving the compiler and @@ -322,7 +322,7 @@ If the current value of this QAtomicInt is the \a expectedValue, the test-and-set functions assign the \a newValue to this QAtomicInt and return true. If the values are \e not the same, - this function does nothing and returns false. + this function does nothing and returns \c false. This function uses \e acquire \l {QAtomicInt#Memory ordering}{memory ordering} semantics, which ensures that memory @@ -337,7 +337,7 @@ If the current value of this QAtomicInt is the \a expectedValue, the test-and-set functions assign the \a newValue to this QAtomicInt and return true. If the values are \e not the same, - this function does nothing and returns false. + this function does nothing and returns \c false. This function uses \e release \l {QAtomicInt#Memory ordering}{memory ordering} semantics, which ensures that memory @@ -352,7 +352,7 @@ If the current value of this QAtomicInt is the \a expectedValue, the test-and-set functions assign the \a newValue to this QAtomicInt and return true. If the values are \e not the same, - this function does nothing and returns false. + this function does nothing and returns \c false. This function uses \e ordered \l {QAtomicInt#Memory ordering}{memory ordering} semantics, which ensures that memory @@ -362,13 +362,13 @@ /*! \fn bool QAtomicInt::isFetchAndStoreNative() - Returns true if fetch-and-store is implemented using atomic + Returns \c true if fetch-and-store is implemented using atomic processor instructions, false otherwise. */ /*! \fn bool QAtomicInt::isFetchAndStoreWaitFree() - Returns true if atomic fetch-and-store is wait-free, false + Returns \c true if atomic fetch-and-store is wait-free, false otherwise. */ @@ -425,13 +425,13 @@ /*! \fn bool QAtomicInt::isFetchAndAddNative() - Returns true if fetch-and-add is implemented using atomic + Returns \c true if fetch-and-add is implemented using atomic processor instructions, false otherwise. */ /*! \fn bool QAtomicInt::isFetchAndAddWaitFree() - Returns true if atomic fetch-and-add is wait-free, false + Returns \c true if atomic fetch-and-add is wait-free, false otherwise. */ @@ -828,13 +828,13 @@ /*! \fn bool QAtomicPointer::isTestAndSetNative() - Returns true if test-and-set is implemented using atomic processor + Returns \c true if test-and-set is implemented using atomic processor instructions, false otherwise. */ /*! \fn bool QAtomicPointer::isTestAndSetWaitFree() - Returns true if atomic test-and-set is wait-free, false otherwise. + Returns \c true if atomic test-and-set is wait-free, false otherwise. */ /*! \fn bool QAtomicPointer::testAndSetRelaxed(T *expectedValue, T *newValue) @@ -844,7 +844,7 @@ If the current value of this QAtomicPointer is the \a expectedValue, the test-and-set functions assign the \a newValue to this QAtomicPointer and return true. If the values are \e not the same, - this function does nothing and returns false. + this function does nothing and returns \c false. This function uses \e relaxed \l {QAtomicPointer#Memory ordering}{memory ordering} semantics, leaving the compiler and @@ -858,7 +858,7 @@ If the current value of this QAtomicPointer is the \a expectedValue, the test-and-set functions assign the \a newValue to this QAtomicPointer and return true. If the values are \e not the same, - this function does nothing and returns false. + this function does nothing and returns \c false. This function uses \e acquire \l {QAtomicPointer#Memory ordering}{memory ordering} semantics, which ensures that memory @@ -873,7 +873,7 @@ If the current value of this QAtomicPointer is the \a expectedValue, the test-and-set functions assign the \a newValue to this QAtomicPointer and return true. If the values are \e not the same, - this function does nothing and returns false. + this function does nothing and returns \c false. This function uses \e release \l {QAtomicPointer#Memory ordering}{memory ordering} semantics, which ensures that memory @@ -888,7 +888,7 @@ If the current value of this QAtomicPointer is the \a expectedValue, the test-and-set functions assign the \a newValue to this QAtomicPointer and return true. If the values are \e not the same, - this function does nothing and returns false. + this function does nothing and returns \c false. This function uses \e ordered \l {QAtomicPointer#Memory ordering}{memory ordering} semantics, which ensures that memory @@ -898,13 +898,13 @@ /*! \fn bool QAtomicPointer::isFetchAndStoreNative() - Returns true if fetch-and-store is implemented using atomic + Returns \c true if fetch-and-store is implemented using atomic processor instructions, false otherwise. */ /*! \fn bool QAtomicPointer::isFetchAndStoreWaitFree() - Returns true if atomic fetch-and-store is wait-free, false + Returns \c true if atomic fetch-and-store is wait-free, false otherwise. */ @@ -961,13 +961,13 @@ /*! \fn bool QAtomicPointer::isFetchAndAddNative() - Returns true if fetch-and-add is implemented using atomic + Returns \c true if fetch-and-add is implemented using atomic processor instructions, false otherwise. */ /*! \fn bool QAtomicPointer::isFetchAndAddWaitFree() - Returns true if atomic fetch-and-add is wait-free, false + Returns \c true if atomic fetch-and-add is wait-free, false otherwise. */ diff --git a/src/corelib/thread/qfuture.qdoc b/src/corelib/thread/qfuture.qdoc index 7ae3e4a87e..951b369fad 100644 --- a/src/corelib/thread/qfuture.qdoc +++ b/src/corelib/thread/qfuture.qdoc @@ -127,12 +127,12 @@ /*! \fn bool QFuture::operator==(const QFuture &other) const - Returns true if \a other is a copy of this future; otherwise returns false. + Returns \c true if \a other is a copy of this future; otherwise returns \c false. */ /*! \fn bool QFuture::operator!=(const QFuture &other) const - Returns true if \a other is \e not a copy of this future; otherwise returns + Returns \c true if \a other is \e not a copy of this future; otherwise returns false. */ @@ -154,11 +154,11 @@ /*! \fn bool QFuture::isCanceled() const - Returns true if the asynchronous computation has been canceled with the - cancel() function; otherwise returns false. + Returns \c true if the asynchronous computation has been canceled with the + cancel() function; otherwise returns \c false. Be aware that the computation may still be running even though this - function returns true. See cancel() for more details. + function returns \c true. See cancel() for more details. */ /*! \fn void QFuture::setPaused(bool paused) @@ -182,11 +182,11 @@ /*! \fn bool QFuture::isPaused() const - Returns true if the asynchronous computation has been paused with the - pause() function; otherwise returns false. + Returns \c true if the asynchronous computation has been paused with the + pause() function; otherwise returns \c false. Be aware that the computation may still be running even though this - function returns true. See setPaused() for more details. + function returns \c true. See setPaused() for more details. \sa setPaused(), togglePaused() */ @@ -219,20 +219,20 @@ /*! \fn bool QFuture::isStarted() const - Returns true if the asynchronous computation represented by this future - has been started; otherwise returns false. + Returns \c true if the asynchronous computation represented by this future + has been started; otherwise returns \c false. */ /*! \fn bool QFuture::isFinished() const - Returns true if the asynchronous computation represented by this future - has finished; otherwise returns false. + Returns \c true if the asynchronous computation represented by this future + has finished; otherwise returns \c false. */ /*! \fn bool QFuture::isRunning() const - Returns true if the asynchronous computation represented by this future is - currently running; otherwise returns false. + Returns \c true if the asynchronous computation represented by this future is + currently running; otherwise returns \c false. */ /*! \fn int QFuture::resultCount() const @@ -301,8 +301,8 @@ /*! \fn bool QFuture::isResultReadyAt(int index) const - Returns true if the result at \a index is immediately available; otherwise - returns false. + Returns \c true if the result at \a index is immediately available; otherwise + returns \c false. \sa resultAt(), resultCount() */ @@ -441,16 +441,16 @@ /*! \fn bool QFuture::const_iterator::operator!=(const const_iterator &other) const - Returns true if \a other points to a different result than this iterator; - otherwise returns false. + Returns \c true if \a other points to a different result than this iterator; + otherwise returns \c false. \sa operator==() */ /*! \fn bool QFuture::const_iterator::operator==(const const_iterator &other) const - Returns true if \a other points to the same result as this iterator; - otherwise returns false. + Returns \c true if \a other points to the same result as this iterator; + otherwise returns \c false. \sa operator!=() */ @@ -616,7 +616,7 @@ /*! \fn bool QFutureIterator::hasNext() const - Returns true if there is at least one result ahead of the iterator, e.g., + Returns \c true if there is at least one result ahead of the iterator, e.g., the iterator is \e not at the back of the result list; otherwise returns false. @@ -645,7 +645,7 @@ /*! \fn bool QFutureIterator::hasPrevious() const - Returns true if there is at least one result ahead of the iterator, e.g., + Returns \c true if there is at least one result ahead of the iterator, e.g., the iterator is \e not at the front of the result list; otherwise returns false. @@ -675,7 +675,7 @@ /*! \fn bool QFutureIterator::findNext(const T &value) Searches for \a value starting from the current iterator position forward. - Returns true if \a value is found; otherwise returns false. + Returns \c true if \a value is found; otherwise returns \c false. After the call, if \a value was found, the iterator is positioned just after the matching result; otherwise, the iterator is positioned at the @@ -687,7 +687,7 @@ /*! \fn bool QFutureIterator::findPrevious(const T &value) Searches for \a value starting from the current iterator position - backward. Returns true if \a value is found; otherwise returns false. + backward. Returns \c true if \a value is found; otherwise returns \c false. After the call, if \a value was found, the iterator is positioned just before the matching result; otherwise, the iterator is positioned at the diff --git a/src/corelib/thread/qfuturesynchronizer.qdoc b/src/corelib/thread/qfuturesynchronizer.qdoc index cc31dff46d..0112935a00 100644 --- a/src/corelib/thread/qfuturesynchronizer.qdoc +++ b/src/corelib/thread/qfuturesynchronizer.qdoc @@ -114,7 +114,7 @@ /*! \fn void QFutureSynchronizer::waitForFinished() - Waits for all futures to finish. If cancelOnWait() returns true, each + Waits for all futures to finish. If cancelOnWait() returns \c true, each future is canceled before waiting for them to finish. \sa cancelOnWait(), setCancelOnWait() @@ -149,7 +149,7 @@ /*! \fn bool QFutureSynchronizer::cancelOnWait() const - Returns true if the cancel-on-wait feature is enabled; otherwise returns + Returns \c true if the cancel-on-wait feature is enabled; otherwise returns false. If cancel-on-wait is enabled, the waitForFinished() function will cancel all futures before waiting for them to finish. diff --git a/src/corelib/thread/qfuturewatcher.cpp b/src/corelib/thread/qfuturewatcher.cpp index a7f2dd9f73..c986d4e59f 100644 --- a/src/corelib/thread/qfuturewatcher.cpp +++ b/src/corelib/thread/qfuturewatcher.cpp @@ -245,8 +245,8 @@ QString QFutureWatcherBase::progressText() const /*! \fn bool QFutureWatcher::isStarted() const - Returns true if the asynchronous computation represented by the future() - has been started; otherwise returns false. + Returns \c true if the asynchronous computation represented by the future() + has been started; otherwise returns \c false. */ bool QFutureWatcherBase::isStarted() const { @@ -255,8 +255,8 @@ bool QFutureWatcherBase::isStarted() const /*! \fn bool QFutureWatcher::isFinished() const - Returns true if the asynchronous computation represented by the future() - has finished; otherwise returns false. + Returns \c true if the asynchronous computation represented by the future() + has finished; otherwise returns \c false. */ bool QFutureWatcherBase::isFinished() const { @@ -266,8 +266,8 @@ bool QFutureWatcherBase::isFinished() const /*! \fn bool QFutureWatcher::isRunning() const - Returns true if the asynchronous computation represented by the future() - is currently running; otherwise returns false. + Returns \c true if the asynchronous computation represented by the future() + is currently running; otherwise returns \c false. */ bool QFutureWatcherBase::isRunning() const { @@ -276,11 +276,11 @@ bool QFutureWatcherBase::isRunning() const /*! \fn bool QFutureWatcher::isCanceled() const - Returns true if the asynchronous computation has been canceled with the - cancel() function; otherwise returns false. + Returns \c true if the asynchronous computation has been canceled with the + cancel() function; otherwise returns \c false. Be aware that the computation may still be running even though this - function returns true. See cancel() for more details. + function returns \c true. See cancel() for more details. */ bool QFutureWatcherBase::isCanceled() const { @@ -289,11 +289,11 @@ bool QFutureWatcherBase::isCanceled() const /*! \fn bool QFutureWatcher::isPaused() const - Returns true if the asynchronous computation has been paused with the - pause() function; otherwise returns false. + Returns \c true if the asynchronous computation has been paused with the + pause() function; otherwise returns \c false. Be aware that the computation may still be running even though this - function returns true. See setPaused() for more details. + function returns \c true. See setPaused() for more details. \sa setPaused(), togglePaused() */ diff --git a/src/corelib/thread/qmutex.cpp b/src/corelib/thread/qmutex.cpp index ed84504a58..0f305b79af 100644 --- a/src/corelib/thread/qmutex.cpp +++ b/src/corelib/thread/qmutex.cpp @@ -227,8 +227,8 @@ void QMutex::lock() QT_MUTEX_LOCK_NOEXCEPT /*! \fn bool QMutex::tryLock(int timeout) - Attempts to lock the mutex. This function returns true if the lock - was obtained; otherwise it returns false. If another thread has + Attempts to lock the mutex. This function returns \c true if the lock + was obtained; otherwise it returns \c false. If another thread has locked the mutex, this function will wait for at most \a timeout milliseconds for the mutex to become available. @@ -281,7 +281,7 @@ void QMutex::unlock() Q_DECL_NOTHROW \fn void QMutex::isRecursive() \since 5.0 - Returns true if the mutex is recursive + Returns \c true if the mutex is recursive */ bool QBasicMutex::isRecursive() diff --git a/src/corelib/thread/qreadwritelock.cpp b/src/corelib/thread/qreadwritelock.cpp index 0de826fddf..e4cdf7a985 100644 --- a/src/corelib/thread/qreadwritelock.cpp +++ b/src/corelib/thread/qreadwritelock.cpp @@ -172,7 +172,7 @@ void QReadWriteLock::lockForRead() /*! Attempts to lock for reading. If the lock was obtained, this - function returns true, otherwise it returns false instead of + function returns \c true, otherwise it returns \c false instead of waiting for the lock to become available, i.e. it does not block. The lock attempt will fail if another thread has locked for @@ -217,8 +217,8 @@ bool QReadWriteLock::tryLockForRead() /*! \overload - Attempts to lock for reading. This function returns true if the - lock was obtained; otherwise it returns false. If another thread + Attempts to lock for reading. This function returns \c true if the + lock was obtained; otherwise it returns \c false. If another thread has locked for writing, this function will wait for at most \a timeout milliseconds for the lock to become available. @@ -309,7 +309,7 @@ void QReadWriteLock::lockForWrite() /*! Attempts to lock for writing. If the lock was obtained, this - function returns true; otherwise, it returns false immediately. + function returns \c true; otherwise, it returns \c false immediately. The lock attempt will fail if another thread has locked for reading or writing. @@ -352,8 +352,8 @@ bool QReadWriteLock::tryLockForWrite() /*! \overload - Attempts to lock for writing. This function returns true if the - lock was obtained; otherwise it returns false. If another thread + Attempts to lock for writing. This function returns \c true if the + lock was obtained; otherwise it returns \c false. If another thread has locked for reading or writing, this function will wait for at most \a timeout milliseconds for the lock to become available. diff --git a/src/corelib/thread/qrunnable.cpp b/src/corelib/thread/qrunnable.cpp index e271582b9b..c12307ab71 100644 --- a/src/corelib/thread/qrunnable.cpp +++ b/src/corelib/thread/qrunnable.cpp @@ -53,7 +53,7 @@ You can use QThreadPool to execute your code in a separate thread. QThreadPool deletes the QRunnable automatically if - autoDelete() returns true (the default). Use setAutoDelete() to + autoDelete() returns \c true (the default). Use setAutoDelete() to change the auto-deletion flag. QThreadPool supports executing the same QRunnable more than once @@ -82,7 +82,7 @@ /*! \fn bool QRunnable::autoDelete() const - Returns true is auto-deletion is enabled; false otherwise. + Returns \c true is auto-deletion is enabled; false otherwise. If auto-deletion is enabled, QThreadPool will automatically delete this runnable after calling run(); otherwise, ownership remains diff --git a/src/corelib/thread/qsemaphore.cpp b/src/corelib/thread/qsemaphore.cpp index 90e4f2a20a..9393ca0d59 100644 --- a/src/corelib/thread/qsemaphore.cpp +++ b/src/corelib/thread/qsemaphore.cpp @@ -178,8 +178,8 @@ int QSemaphore::available() const /*! Tries to acquire \c n resources guarded by the semaphore and - returns true on success. If available() < \a n, this call - immediately returns false without acquiring any resources. + returns \c true on success. If available() < \a n, this call + immediately returns \c false without acquiring any resources. Example: @@ -199,7 +199,7 @@ bool QSemaphore::tryAcquire(int n) /*! Tries to acquire \c n resources guarded by the semaphore and - returns true on success. If available() < \a n, this call will + returns \c true on success. If available() < \a n, this call will wait for at most \a timeout milliseconds for resources to become available. diff --git a/src/corelib/thread/qthread.cpp b/src/corelib/thread/qthread.cpp index 35d57b3d83..27529f8644 100644 --- a/src/corelib/thread/qthread.cpp +++ b/src/corelib/thread/qthread.cpp @@ -405,7 +405,7 @@ QThread::QThread(QThreadPrivate &dd, QObject *parent) Note that deleting a QThread object will not stop the execution of the thread it manages. Deleting a running QThread (i.e. - isFinished() returns false) will probably result in a program + isFinished() returns \c false) will probably result in a program crash. Wait for the finished() signal before deleting the QThread. */ @@ -427,7 +427,7 @@ QThread::~QThread() } /*! - Returns true if the thread is finished; otherwise returns false. + Returns \c true if the thread is finished; otherwise returns \c false. \sa isRunning() */ @@ -439,7 +439,7 @@ bool QThread::isFinished() const } /*! - Returns true if the thread is running; otherwise returns false. + Returns \c true if the thread is running; otherwise returns \c false. \sa isFinished() */ diff --git a/src/corelib/thread/qthreadpool.cpp b/src/corelib/thread/qthreadpool.cpp index 9ef40a5209..fb1d1ee7cc 100644 --- a/src/corelib/thread/qthreadpool.cpp +++ b/src/corelib/thread/qthreadpool.cpp @@ -441,10 +441,10 @@ QThreadPool *QThreadPool::globalInstance() be used to control the run queue's order of execution. Note that the thread pool takes ownership of the \a runnable if - \l{QRunnable::autoDelete()}{runnable->autoDelete()} returns true, + \l{QRunnable::autoDelete()}{runnable->autoDelete()} returns \c true, and the \a runnable will be deleted automatically by the thread pool after the \l{QRunnable::run()}{runnable->run()} returns. If - \l{QRunnable::autoDelete()}{runnable->autoDelete()} returns false, + \l{QRunnable::autoDelete()}{runnable->autoDelete()} returns \c false, ownership of \a runnable remains with the caller. Note that changing the auto-deletion on \a runnable after calling this functions results in undefined behavior. @@ -470,14 +470,14 @@ void QThreadPool::start(QRunnable *runnable, int priority) Attempts to reserve a thread to run \a runnable. If no threads are available at the time of calling, then this function - does nothing and returns false. Otherwise, \a runnable is run immediately - using one available thread and this function returns true. + does nothing and returns \c false. Otherwise, \a runnable is run immediately + using one available thread and this function returns \c true. Note that the thread pool takes ownership of the \a runnable if - \l{QRunnable::autoDelete()}{runnable->autoDelete()} returns true, + \l{QRunnable::autoDelete()}{runnable->autoDelete()} returns \c true, and the \a runnable will be deleted automatically by the thread pool after the \l{QRunnable::run()}{runnable->run()} returns. If - \l{QRunnable::autoDelete()}{runnable->autoDelete()} returns false, + \l{QRunnable::autoDelete()}{runnable->autoDelete()} returns \c false, ownership of \a runnable remains with the caller. Note that changing the auto-deletion on \a runnable after calling this function results in undefined behavior. @@ -612,8 +612,8 @@ void QThreadPool::releaseThread() /*! 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. If \a msecs is -1 (the default), the timeout + threads from the thread pool. Returns \c true if all threads were removed; + otherwise it returns \c false. If \a msecs is -1 (the default), the timeout is ignored (waits for the last thread to exit). */ bool QThreadPool::waitForDone(int msecs) @@ -630,7 +630,7 @@ bool QThreadPool::waitForDone(int msecs) Removes the runnables that are not yet started from the queue. The runnables for which \l{QRunnable::autoDelete()}{runnable->autoDelete()} - returns true are deleted. + returns \c true are deleted. \sa start() */ diff --git a/src/corelib/thread/qthreadstorage.cpp b/src/corelib/thread/qthreadstorage.cpp index 6000ece7dc..2d95b0880d 100644 --- a/src/corelib/thread/qthreadstorage.cpp +++ b/src/corelib/thread/qthreadstorage.cpp @@ -282,7 +282,7 @@ void QThreadStorageData::finish(void **p) /*! \fn bool QThreadStorage::hasLocalData() const - If T is a pointer type, returns true if the calling thread has + If T is a pointer type, returns \c true if the calling thread has non-zero data available. If T is a value type, returns whether the data has already been -- cgit v1.2.3 From 583d05863e4aa1c6af1948795ce42b928a0017d0 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Fri, 27 Sep 2013 19:40:24 -0700 Subject: Reorder the members in QThreadData to avoid padding holes Before this change, this struct had size 104 and a total of 21 padding bytes. Now it's down to 88 bytes and only 5 bytes of padding. pahole report on a 64-bit system: class QAtomicInt _ref; /* 0 4 */ /* XXX 4 bytes hole, try to pack */ public: class QThread * thread; /* 8 8 */ HANDLE threadId; /* 16 8 */ bool quitNow; /* 24 1 */ /* XXX 3 bytes hole, try to pack */ int loopLevel; /* 28 4 */ class QAtomicPointer eventDispatcher; /* 32 8 */ class QStack eventLoops; /* 40 8 */ /* --- cacheline 1 boundary (64 bytes) --- */ class QPostEventList postEventList; /* 48 32 */ bool canWait; /* 80 1 */ /* XXX 7 bytes hole, try to pack */ class QVector tls; /* 88 8 */ bool isAdopted; /* 96 1 */ /* size: 104, cachelines: 2, members: 11 */ /* sum members: 90, holes: 3, sum holes: 14 */ /* padding: 7 */ Change-Id: I1fc88e0b312f38eccdea440734fd37e0519285a2 Reviewed-by: Olivier Goffart --- src/corelib/thread/qthread.cpp | 4 ++-- src/corelib/thread/qthread_p.h | 20 ++++++++++++-------- 2 files changed, 14 insertions(+), 10 deletions(-) (limited to 'src/corelib/thread') diff --git a/src/corelib/thread/qthread.cpp b/src/corelib/thread/qthread.cpp index 27529f8644..7667aff0b2 100644 --- a/src/corelib/thread/qthread.cpp +++ b/src/corelib/thread/qthread.cpp @@ -58,8 +58,8 @@ QT_BEGIN_NAMESPACE */ QThreadData::QThreadData(int initialRefCount) - : _ref(initialRefCount), thread(0), threadId(0), - quitNow(false), loopLevel(0), eventDispatcher(0), canWait(true), isAdopted(false) + : _ref(initialRefCount), loopLevel(0), thread(0), threadId(0), + eventDispatcher(0), quitNow(false), canWait(true), isAdopted(false) { // fprintf(stderr, "QThreadData %p created\n", this); } diff --git a/src/corelib/thread/qthread_p.h b/src/corelib/thread/qthread_p.h index fa1f7414f1..8429e41433 100644 --- a/src/corelib/thread/qthread_p.h +++ b/src/corelib/thread/qthread_p.h @@ -219,8 +219,6 @@ public: class QThreadData { - QAtomicInt _ref; - public: QThreadData(int initialRefCount = 1); ~QThreadData(); @@ -262,17 +260,23 @@ public: { return std::find(locations, locations + Count, method) != locations + Count; } }; - QThread *thread; - Qt::HANDLE threadId; - bool quitNow; +private: + QAtomicInt _ref; + +public: int loopLevel; - QAtomicPointer eventDispatcher; + QStack eventLoops; QPostEventList postEventList; - bool canWait; + QThread *thread; + Qt::HANDLE threadId; + QAtomicPointer eventDispatcher; QVector tls; - bool isAdopted; FlaggedDebugSignatures flaggedSignatures; + + bool quitNow; + bool canWait; + bool isAdopted; }; class QScopedLoopLevelCounter -- cgit v1.2.3