summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--doc/src/snippets/threads/threads.cpp9
-rw-r--r--src/corelib/global/qnamespace.h2
-rw-r--r--src/corelib/global/qnamespace.qdoc3
-rw-r--r--src/corelib/io/qfilesystemwatcher.cpp7
-rw-r--r--src/corelib/io/qfilesystemwatcher_inotify.cpp2
-rw-r--r--src/corelib/io/qfilesystemwatcher_symbian.cpp2
-rw-r--r--src/corelib/kernel/qobjectdefs.h8
-rw-r--r--src/corelib/thread/qthread.cpp8
-rw-r--r--src/corelib/thread/qthread_p.h1
-rw-r--r--src/corelib/thread/qthread_unix.cpp41
-rw-r--r--src/corelib/thread/qthread_win.cpp36
-rw-r--r--src/corelib/thread/qthreadstorage.cpp59
-rw-r--r--src/corelib/thread/qthreadstorage.h13
-rw-r--r--src/corelib/tools/qchar.cpp26
-rw-r--r--src/corelib/tools/qstring.cpp6
-rw-r--r--src/gui/accessible/qaccessible_mac.mm2
-rw-r--r--src/gui/dialogs/qcolordialog_mac.mm4
-rw-r--r--src/gui/dialogs/qfontdialog_mac.mm2
-rw-r--r--src/gui/dialogs/qpagesetupdialog_mac.mm4
-rw-r--r--src/gui/image/qnativeimage.cpp2
-rw-r--r--src/gui/kernel/qcocoaapplicationdelegate_mac.mm5
-rw-r--r--src/gui/kernel/qcocoamenuloader_mac.mm4
-rw-r--r--src/gui/kernel/qcocoaview_mac.mm30
-rw-r--r--src/gui/kernel/qcocoawindow_mac.mm2
-rw-r--r--src/gui/kernel/qcocoawindowdelegate_mac.mm2
-rw-r--r--src/gui/kernel/qwidget_mac.mm7
-rw-r--r--src/gui/styles/qmacstyle_mac.mm10
-rw-r--r--src/gui/styles/qstyle.cpp2
-rw-r--r--src/gui/styles/qstyleoption.cpp4
-rw-r--r--src/gui/widgets/qcocoamenu_mac.mm9
-rw-r--r--tests/auto/qfilesystemwatcher/tst_qfilesystemwatcher.cpp20
-rw-r--r--tests/auto/qthread/tst_qthread.cpp123
-rw-r--r--tests/auto/qthreadstorage/tst_qthreadstorage.cpp190
33 files changed, 513 insertions, 132 deletions
diff --git a/doc/src/snippets/threads/threads.cpp b/doc/src/snippets/threads/threads.cpp
index d8d1270..d16c398 100644
--- a/doc/src/snippets/threads/threads.cpp
+++ b/doc/src/snippets/threads/threads.cpp
@@ -93,15 +93,12 @@ private:
typedef int SomeClass;
//! [7]
-QThreadStorage<QCache<QString, SomeClass> *> caches;
+QThreadStorage<QCache<QString, SomeClass> > caches;
void cacheObject(const QString &key, SomeClass *object)
//! [7] //! [8]
{
- if (!caches.hasLocalData())
- caches.setLocalData(new QCache<QString, SomeClass>);
-
- caches.localData()->insert(key, object);
+ caches.localData().insert(key, object);
}
void removeFromCache(const QString &key)
@@ -110,7 +107,7 @@ void removeFromCache(const QString &key)
if (!caches.hasLocalData())
return;
- caches.localData()->remove(key);
+ caches.localData().remove(key);
}
//! [9]
diff --git a/src/corelib/global/qnamespace.h b/src/corelib/global/qnamespace.h
index 3ed6291..6afc9a2 100644
--- a/src/corelib/global/qnamespace.h
+++ b/src/corelib/global/qnamespace.h
@@ -519,6 +519,8 @@ public:
WA_X11DoNotAcceptFocus = 132,
+ WA_MacNoShadow = 133,
+
// Add new attributes before this line
WA_AttributeCount
};
diff --git a/src/corelib/global/qnamespace.qdoc b/src/corelib/global/qnamespace.qdoc
index f097f2a..b9939b6 100644
--- a/src/corelib/global/qnamespace.qdoc
+++ b/src/corelib/global/qnamespace.qdoc
@@ -1257,6 +1257,9 @@
to this top level window. This attribute has no effect on non-X11
platforms.
+ \value WA_MacNoShadow Since Qt 4.8, this attribute disables drop shadows
+ for this top level window. Only affects Cocoa builds of Qt for Mac OS X.
+
\omitvalue WA_SetLayoutDirection
\omitvalue WA_InputMethodTransparent
\omitvalue WA_WState_CompressKeys
diff --git a/src/corelib/io/qfilesystemwatcher.cpp b/src/corelib/io/qfilesystemwatcher.cpp
index 18c3c9f..3a7d795 100644
--- a/src/corelib/io/qfilesystemwatcher.cpp
+++ b/src/corelib/io/qfilesystemwatcher.cpp
@@ -198,7 +198,7 @@ QStringList QPollingFileSystemWatcherEngine::removePaths(const QStringList &path
void QPollingFileSystemWatcherEngine::stop()
{
- QMetaObject::invokeMethod(this, "quit");
+ quit();
}
void QPollingFileSystemWatcherEngine::timeout()
@@ -426,11 +426,6 @@ QFileSystemWatcher::QFileSystemWatcher(const QStringList &paths, QObject *parent
/*!
Destroys the file system watcher.
-
- \note To avoid deadlocks on shutdown, all instances of QFileSystemWatcher
- need to be destroyed before QCoreApplication. Note that passing
- QCoreApplication::instance() as the parent object when creating
- QFileSystemWatcher is not sufficient.
*/
QFileSystemWatcher::~QFileSystemWatcher()
{
diff --git a/src/corelib/io/qfilesystemwatcher_inotify.cpp b/src/corelib/io/qfilesystemwatcher_inotify.cpp
index 25ff2b6..ab53431 100644
--- a/src/corelib/io/qfilesystemwatcher_inotify.cpp
+++ b/src/corelib/io/qfilesystemwatcher_inotify.cpp
@@ -340,7 +340,7 @@ QStringList QInotifyFileSystemWatcherEngine::removePaths(const QStringList &path
void QInotifyFileSystemWatcherEngine::stop()
{
- QMetaObject::invokeMethod(this, "quit");
+ quit();
}
void QInotifyFileSystemWatcherEngine::readFromInotify()
diff --git a/src/corelib/io/qfilesystemwatcher_symbian.cpp b/src/corelib/io/qfilesystemwatcher_symbian.cpp
index 6136742..ee66c36 100644
--- a/src/corelib/io/qfilesystemwatcher_symbian.cpp
+++ b/src/corelib/io/qfilesystemwatcher_symbian.cpp
@@ -215,7 +215,7 @@ void QSymbianFileSystemWatcherEngine::emitPathChanged(QNotifyChangeEvent *e)
void QSymbianFileSystemWatcherEngine::stop()
{
- QMetaObject::invokeMethod(this, "quit");
+ quit();
wait();
}
diff --git a/src/corelib/kernel/qobjectdefs.h b/src/corelib/kernel/qobjectdefs.h
index db46ba5..b4e4aa5 100644
--- a/src/corelib/kernel/qobjectdefs.h
+++ b/src/corelib/kernel/qobjectdefs.h
@@ -215,11 +215,15 @@ Q_CORE_EXPORT const char *qFlagLocation(const char *method);
#define QTOSTRING(s) QTOSTRING_HELPER(s)
#ifndef QT_NO_DEBUG
# define QLOCATION "\0"__FILE__":"QTOSTRING(__LINE__)
-# define METHOD(a) qFlagLocation("0"#a QLOCATION)
+# ifndef QT_NO_KEYWORDS
+# define METHOD(a) qFlagLocation("0"#a QLOCATION)
+# endif
# define SLOT(a) qFlagLocation("1"#a QLOCATION)
# define SIGNAL(a) qFlagLocation("2"#a QLOCATION)
#else
-# define METHOD(a) "0"#a
+# ifndef QT_NO_KEYWORDS
+# define METHOD(a) "0"#a
+# endif
# define SLOT(a) "1"#a
# define SIGNAL(a) "2"#a
#endif
diff --git a/src/corelib/thread/qthread.cpp b/src/corelib/thread/qthread.cpp
index 69b70cb..71a4896 100644
--- a/src/corelib/thread/qthread.cpp
+++ b/src/corelib/thread/qthread.cpp
@@ -173,7 +173,8 @@ void QAdoptedThread::run()
*/
QThreadPrivate::QThreadPrivate(QThreadData *d)
- : QObjectPrivate(), running(false), finished(false), terminated(false), exited(false), returnCode(-1),
+ : QObjectPrivate(), running(false), finished(false), terminated(false),
+ isInFinish(false), exited(false), returnCode(-1),
stackSize(0), priority(QThread::InheritPriority), data(d)
{
#if defined (Q_OS_UNIX)
@@ -403,6 +404,11 @@ QThread::~QThread()
Q_D(QThread);
{
QMutexLocker locker(&d->mutex);
+ if (d->isInFinish) {
+ locker.unlock();
+ wait();
+ locker.relock();
+ }
if (d->running && !d->finished)
qWarning("QThread: Destroyed while thread is still running");
diff --git a/src/corelib/thread/qthread_p.h b/src/corelib/thread/qthread_p.h
index d816aef..51c6991 100644
--- a/src/corelib/thread/qthread_p.h
+++ b/src/corelib/thread/qthread_p.h
@@ -126,6 +126,7 @@ public:
bool running;
bool finished;
bool terminated;
+ bool isInFinish; //when in QThreadPrivate::finish
bool exited;
int returnCode;
diff --git a/src/corelib/thread/qthread_unix.cpp b/src/corelib/thread/qthread_unix.cpp
index adbbad2..b674ab8 100644
--- a/src/corelib/thread/qthread_unix.cpp
+++ b/src/corelib/thread/qthread_unix.cpp
@@ -334,40 +334,45 @@ void QThreadPrivate::finish(void *arg)
{
QThread *thr = reinterpret_cast<QThread *>(arg);
QThreadPrivate *d = thr->d_func();
+
#ifdef Q_OS_SYMBIAN
- if (lockAnyway)
+ QMutexLocker locker(lockAnyway ? &d->mutex : 0);
+#else
+ QMutexLocker locker(&d->mutex);
#endif
- d->mutex.lock();
+ d->isInFinish = true;
d->priority = QThread::InheritPriority;
- d->running = false;
- d->finished = true;
- if (d->terminated)
+ bool terminated = d->terminated;
+ void *data = &d->data->tls;
+ locker.unlock();
+ if (terminated)
emit thr->terminated();
- d->terminated = false;
emit thr->finished();
QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete);
+ QThreadStorageData::finish((void **)data);
+ locker.relock();
+ d->terminated = false;
- if (d->data->eventDispatcher) {
- d->data->eventDispatcher->closingDown();
- QAbstractEventDispatcher *eventDispatcher = d->data->eventDispatcher;
+ QAbstractEventDispatcher *eventDispatcher = d->data->eventDispatcher;
+ if (eventDispatcher) {
d->data->eventDispatcher = 0;
+ locker.unlock();
+ eventDispatcher->closingDown();
delete eventDispatcher;
+ locker.relock();
}
- void *data = &d->data->tls;
- QThreadStorageData::finish((void **)data);
-
d->thread_id = 0;
#ifdef Q_OS_SYMBIAN
if (closeNativeHandle)
d->data->symbian_thread_handle.Close();
#endif
+ d->running = false;
+ d->finished = true;
+
+ d->isInFinish = false;
d->thread_done.wakeAll();
-#ifdef Q_OS_SYMBIAN
- if (lockAnyway)
-#endif
- d->mutex.unlock();
}
@@ -544,6 +549,10 @@ void QThread::start(Priority priority)
{
Q_D(QThread);
QMutexLocker locker(&d->mutex);
+
+ if (d->isInFinish)
+ d->thread_done.wait(locker.mutex());
+
if (d->running)
return;
diff --git a/src/corelib/thread/qthread_win.cpp b/src/corelib/thread/qthread_win.cpp
index 4a967ed..74fedd3 100644
--- a/src/corelib/thread/qthread_win.cpp
+++ b/src/corelib/thread/qthread_win.cpp
@@ -323,25 +323,33 @@ void QThreadPrivate::finish(void *arg, bool lockAnyway)
QThread *thr = reinterpret_cast<QThread *>(arg);
QThreadPrivate *d = thr->d_func();
- if (lockAnyway)
- d->mutex.lock();
+ QMutexLocker locker(lockAnyway ? &d->mutex : 0);
+ d->isInFinish = true;
d->priority = QThread::InheritPriority;
- d->running = false;
- d->finished = true;
- if (d->terminated)
+ bool terminated = d->terminated;
+ void **tls_data = reinterpret_cast<void **>(&d->data->tls);
+ locker.unlock();
+ if (terminated)
emit thr->terminated();
- d->terminated = false;
emit thr->finished();
QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete);
+ QThreadStorageData::finish(tls_data);
+ locker.relock();
+
+ d->terminated = false;
- if (d->data->eventDispatcher) {
- d->data->eventDispatcher->closingDown();
- QAbstractEventDispatcher *eventDispatcher = d->data->eventDispatcher;
+ QAbstractEventDispatcher *eventDispatcher = d->data->eventDispatcher;
+ if (eventDispatcher) {
d->data->eventDispatcher = 0;
+ locker.unlock();
+ eventDispatcher->closingDown();
delete eventDispatcher;
+ locker.relock();
}
- QThreadStorageData::finish(reinterpret_cast<void **>(&d->data->tls));
+ d->running = false;
+ d->finished = true;
+ d->isInFinish = false;
if (!d->waiters) {
CloseHandle(d->handle);
@@ -350,8 +358,6 @@ void QThreadPrivate::finish(void *arg, bool lockAnyway)
d->id = 0;
- if (lockAnyway)
- d->mutex.unlock();
}
/**************************************************************************
@@ -400,6 +406,12 @@ void QThread::start(Priority priority)
Q_D(QThread);
QMutexLocker locker(&d->mutex);
+ if (d->isInFinish) {
+ locker.unlock();
+ wait();
+ locker.relock();
+ }
+
if (d->running)
return;
diff --git a/src/corelib/thread/qthreadstorage.cpp b/src/corelib/thread/qthreadstorage.cpp
index 2fc04f5..416fcfb 100644
--- a/src/corelib/thread/qthreadstorage.cpp
+++ b/src/corelib/thread/qthreadstorage.cpp
@@ -178,11 +178,12 @@ void QThreadStorageData::finish(void **p)
return; // nothing to do
DEBUG_MSG("QThreadStorageData: Destroying storage for thread %p", QThread::currentThread());
-
- for(int i = tls->size() - 1; i >= 0; i--) {
- void *&value = (*tls)[i];
+ while (!tls->isEmpty()) {
+ void *&value = tls->last();
void *q = value;
value = 0;
+ int i = tls->size() - 1;
+ tls->resize(i);
if (!q) {
// data already deleted
@@ -200,6 +201,11 @@ void QThreadStorageData::finish(void **p)
continue;
}
destructor(q); //crash here might mean the thread exited after qthreadstorage was destroyed
+
+ if (tls->size() > i) {
+ //re reset the tls in case it has been recreated by its own destructor.
+ (*tls)[i] = 0;
+ }
}
tls->clear();
}
@@ -215,19 +221,18 @@ void QThreadStorageData::finish(void **p)
QThreadStorage is a template class that provides per-thread data
storage.
- \e{Note that due to compiler limitations, QThreadStorage can only
- store pointers.}
-
The setLocalData() function stores a single thread-specific value
for the calling thread. The data can be accessed later using
- localData(). QThreadStorage takes ownership of the data (which
- must be created on the heap with \c new) and deletes it when the
- thread exits, either normally or via termination.
+ localData().
The hasLocalData() function allows the programmer to determine if
data has previously been set using the setLocalData() function.
This is also useful for lazy initializiation.
+ If T is a pointer type, QThreadStorage takes ownership of the data
+ (which must be created on the heap with \c new) and deletes it when
+ the thread exits, either normally or via termination.
+
For example, the following code uses QThreadStorage to store a
single cache for each thread that calls the cacheObject() and
removeFromCache() functions. The cache is automatically
@@ -241,9 +246,6 @@ void QThreadStorageData::finish(void **p)
\list
- \o As noted above, QThreadStorage can only store pointers due to
- compiler limitations.
-
\o The QThreadStorage destructor does not delete per-thread data.
QThreadStorage only deletes per-thread data when the thread exits
or when setLocalData() is called multiple times.
@@ -279,8 +281,11 @@ void QThreadStorageData::finish(void **p)
/*!
\fn bool QThreadStorage::hasLocalData() const
- Returns true if the calling thread has non-zero data available;
- otherwise returns false.
+ If T is a pointer type, returns true if the calling thread has
+ non-zero data available.
+
+ If T is a value type, returns whether the data has already been
+ constructed by calling setLocalData or localData.
\sa localData()
*/
@@ -291,10 +296,8 @@ void QThreadStorageData::finish(void **p)
Returns a reference to the data that was set by the calling
thread.
- Note: QThreadStorage can only store pointers. This function
- returns a reference to the pointer that was set by the calling
- thread. The value of this reference is 0 if no data was set by
- the calling thread,
+ If no data has been set, this will create a default constructed
+ instance of type T.
\sa hasLocalData()
*/
@@ -305,10 +308,6 @@ void QThreadStorageData::finish(void **p)
Returns a copy of the data that was set by the calling thread.
- Note: QThreadStorage can only store pointers. This function
- returns a pointer to the data that was set by the calling thread.
- If no data was set by the calling thread, this function returns 0.
-
\sa hasLocalData()
*/
@@ -318,19 +317,9 @@ void QThreadStorageData::finish(void **p)
Sets the local data for the calling thread to \a data. It can be
accessed later using the localData() functions.
- If \a data is 0, this function deletes the previous data (if
- any) and returns immediately.
-
- If \a data is non-zero, QThreadStorage takes ownership of the \a
- data and deletes it automatically either when the thread exits
- (either normally or via termination) or when setLocalData() is
- called again.
-
- Note: QThreadStorage can only store pointers. The \a data
- argument must be either a pointer to an object created on the heap
- (i.e. using \c new) or 0. You should not delete \a data
- yourself; QThreadStorage takes ownership and will delete the \a
- data itself.
+ If T is a pointer type, QThreadStorage takes ownership of the data
+ and deletes it automatically either when the thread exits (either
+ normally or via termination) or when setLocalData() is called again.
\sa localData(), hasLocalData()
*/
diff --git a/src/corelib/thread/qthreadstorage.h b/src/corelib/thread/qthreadstorage.h
index 6264674..475d20d 100644
--- a/src/corelib/thread/qthreadstorage.h
+++ b/src/corelib/thread/qthreadstorage.h
@@ -91,6 +91,11 @@ inline
void qThreadStorage_setLocalData(QThreadStorageData &d, T **t)
{ (void) d.set(*t); }
+template <typename T>
+inline
+void qThreadStorage_deleteData(void *d, T **)
+{ delete static_cast<T *>(d); }
+
// value-based specialization
template <typename T>
inline
@@ -114,6 +119,12 @@ inline
void qThreadStorage_setLocalData(QThreadStorageData &d, T *t)
{ (void) d.set(new T(*t)); }
+template <typename T>
+inline
+void qThreadStorage_deleteData(void *d, T *)
+{ delete static_cast<T *>(d); }
+
+
// MOC_SKIP_END
#endif
@@ -126,7 +137,7 @@ private:
Q_DISABLE_COPY(QThreadStorage)
static inline void deleteData(void *x)
- { delete static_cast<T>(x); }
+ { qThreadStorage_deleteData(x, reinterpret_cast<T*>(0)); }
public:
inline QThreadStorage() : d(deleteData) { }
diff --git a/src/corelib/tools/qchar.cpp b/src/corelib/tools/qchar.cpp
index bb777cd..fba0bd2 100644
--- a/src/corelib/tools/qchar.cpp
+++ b/src/corelib/tools/qchar.cpp
@@ -48,11 +48,11 @@
# undef QT_NO_CAST_TO_ASCII
#endif
#include "qchar.h"
+
#include "qdatastream.h"
#include "qtextcodec.h"
#include "qunicodetables_p.h"
-
#include "qunicodetables.cpp"
QT_BEGIN_NAMESPACE
@@ -1489,6 +1489,16 @@ static void decomposeHelper(QString *str, bool canonical, QChar::UnicodeVersion
}
+struct UCS2Pair {
+ ushort u1;
+ ushort u2;
+};
+
+inline bool operator<(ushort u1, const UCS2Pair &ligature)
+{ return u1 < ligature.u1; }
+inline bool operator<(const UCS2Pair &ligature, ushort u1)
+{ return ligature.u1 < u1; }
+
static ushort ligatureHelper(ushort u1, ushort u2)
{
// hangul L-V pair
@@ -1511,12 +1521,14 @@ static ushort ligatureHelper(ushort u1, ushort u2)
if (index == 0xffff)
return 0;
const unsigned short *ligatures = uc_ligature_map+index;
- ushort length = *ligatures;
- ++ligatures;
- // ### use bsearch
- for (uint i = 0; i < length; ++i)
- if (ligatures[2*i] == u1)
- return ligatures[2*i+1];
+ ushort length = *ligatures++;
+ {
+ const UCS2Pair *data = reinterpret_cast<const UCS2Pair *>(ligatures);
+ const UCS2Pair *r = qBinaryFind(data, data + length, u1);
+ if (r != data + length)
+ return r->u2;
+ }
+
return 0;
}
diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp
index bb496c6..c30af64 100644
--- a/src/corelib/tools/qstring.cpp
+++ b/src/corelib/tools/qstring.cpp
@@ -714,7 +714,7 @@ const QString::Null QString::null = { };
formats, the \e precision represents the maximum number of
significant digits (trailing zeroes are omitted).
- \section1 More Efficient String Construction
+ \section1 More Efficient String Construction
Using the QString \c{'+'} operator, it is easy to construct a
complex string from multiple substrings. You will often write code
@@ -924,7 +924,7 @@ int QString::grow(int size)
/*!
\since 4.2
- Returns a copy of the \a string, where the encoding of \a string depends on
+ Returns a copy of the \a string, where the encoding of \a string depends on
the size of wchar. If wchar is 4 bytes, the \a string is interpreted as ucs-4,
if wchar is 2 bytes it is interpreted as ucs-2.
@@ -3606,7 +3606,7 @@ static QByteArray toLatin1_helper(const QChar *data, int length)
}
length = length % 16;
}
-#elif QT_ALWAYS_HAVE_NEON
+#elif defined(QT_ALWAYS_HAVE_NEON)
// Refer to the documentation of the SSE2 implementation
// this use eactly the same method as for SSE except:
// 1) neon has unsigned comparison
diff --git a/src/gui/accessible/qaccessible_mac.mm b/src/gui/accessible/qaccessible_mac.mm
index 57ea41b..3b1396a 100644
--- a/src/gui/accessible/qaccessible_mac.mm
+++ b/src/gui/accessible/qaccessible_mac.mm
@@ -774,7 +774,7 @@ QAInterface QAccessibleHierarchyManager::lookup(const AXUIElementRef &element)
return factory->interface(id);
#else
return QAInterface();
-#endif;
+#endif
}
QAInterface QAccessibleHierarchyManager::lookup(const QAElement &element)
diff --git a/src/gui/dialogs/qcolordialog_mac.mm b/src/gui/dialogs/qcolordialog_mac.mm
index 82cfa24..655de08 100644
--- a/src/gui/dialogs/qcolordialog_mac.mm
+++ b/src/gui/dialogs/qcolordialog_mac.mm
@@ -185,7 +185,7 @@ QT_USE_NAMESPACE
[self relayout];
}
-- (void)colorChanged:(NSNotification *)notification;
+- (void)colorChanged:(NSNotification *)notification
{
Q_UNUSED(notification);
[self updateQtColor];
@@ -439,7 +439,7 @@ void QColorDialogPrivate::openCocoaColorPanel(const QColor &initial,
priv:this];
[colorPanel setDelegate:static_cast<QT_MANGLE_NAMESPACE(QCocoaColorPanelDelegate) *>(delegate)];
}
- [delegate setResultSet:false];
+ [static_cast<QT_MANGLE_NAMESPACE(QCocoaColorPanelDelegate) *>(delegate) setResultSet:NO];
setCocoaPanelColor(initial);
[static_cast<QT_MANGLE_NAMESPACE(QCocoaColorPanelDelegate) *>(delegate) showColorPanel];
}
diff --git a/src/gui/dialogs/qfontdialog_mac.mm b/src/gui/dialogs/qfontdialog_mac.mm
index 6fb363b..e2c2fc2 100644
--- a/src/gui/dialogs/qfontdialog_mac.mm
+++ b/src/gui/dialogs/qfontdialog_mac.mm
@@ -339,7 +339,7 @@ static QFont qfontForCocoaFont(NSFont *cocoaFont, const QFont &resolveFont)
[self relayoutToContentSize:[[mStolenContentView superview] frame].size];
}
-- (void)relayoutToContentSize:(NSSize)frameSize;
+- (void)relayoutToContentSize:(NSSize)frameSize
{
Q_ASSERT(mPanelHackedWithButtons);
diff --git a/src/gui/dialogs/qpagesetupdialog_mac.mm b/src/gui/dialogs/qpagesetupdialog_mac.mm
index 0302be4..f7a9aab 100644
--- a/src/gui/dialogs/qpagesetupdialog_mac.mm
+++ b/src/gui/dialogs/qpagesetupdialog_mac.mm
@@ -61,7 +61,7 @@ QT_USE_NAMESPACE
@end
@implementation QT_MANGLE_NAMESPACE(QCocoaPageLayoutDelegate)
-- (id)initWithMacPrintEngine:(QMacPrintEnginePrivate *)printEngine;
+- (id)initWithMacPrintEngine:(QMacPrintEnginePrivate *)printEngine
{
self = [super init];
if (self) {
@@ -312,4 +312,4 @@ int QPageSetupDialog::exec()
QT_END_NAMESPACE
-#endif QT_NO_PRINTDIALOG
+#endif /* QT_NO_PRINTDIALOG */
diff --git a/src/gui/image/qnativeimage.cpp b/src/gui/image/qnativeimage.cpp
index 0f7872e..c154740 100644
--- a/src/gui/image/qnativeimage.cpp
+++ b/src/gui/image/qnativeimage.cpp
@@ -256,6 +256,8 @@ QNativeImage::QNativeImage(int width, int height, QImage::Format format, bool /*
case QImage::Format_ARGB4444_Premultiplied:
cgflags = kCGImageAlphaPremultipliedFirst;
break;
+ default:
+ break;
}
#ifdef kCGBitmapByteOrder32Host //only needed because CGImage.h added symbols in the minor version
diff --git a/src/gui/kernel/qcocoaapplicationdelegate_mac.mm b/src/gui/kernel/qcocoaapplicationdelegate_mac.mm
index 9b07d64..036cb3b 100644
--- a/src/gui/kernel/qcocoaapplicationdelegate_mac.mm
+++ b/src/gui/kernel/qcocoaapplicationdelegate_mac.mm
@@ -78,6 +78,7 @@
#import <private/qcocoaapplicationdelegate_mac_p.h>
#import <private/qcocoamenuloader_mac_p.h>
+#import <private/qcocoaapplication_mac_p.h>
#include <private/qapplication_p.h>
#include <private/qt_mac_p.h>
#include <private/qt_cocoa_helpers_mac_p.h>
@@ -173,7 +174,7 @@ static void cleanupCocoaApplicationDelegate()
qtMenuLoader = menuLoader;
}
-- (QT_MANGLE_NAMESPACE(QCocoaMenuLoader) *)menuLoader;
+- (QT_MANGLE_NAMESPACE(QCocoaMenuLoader) *)menuLoader
{
return [[qtMenuLoader retain] autorelease];
}
@@ -256,7 +257,7 @@ static void cleanupCocoaApplicationDelegate()
onApplicationChangedActivation(true);
}
-- (void)applicationDidResignActive:(NSNotification *)notification;
+- (void)applicationDidResignActive:(NSNotification *)notification
{
if (reflectionDelegate
&& [reflectionDelegate respondsToSelector:@selector(applicationDidResignActive:)])
diff --git a/src/gui/kernel/qcocoamenuloader_mac.mm b/src/gui/kernel/qcocoamenuloader_mac.mm
index b963b3c..d351831 100644
--- a/src/gui/kernel/qcocoamenuloader_mac.mm
+++ b/src/gui/kernel/qcocoamenuloader_mac.mm
@@ -170,12 +170,12 @@ QT_USE_NAMESPACE
return [[aboutQtItem retain] autorelease];
}
-- (NSMenuItem *)hideMenuItem;
+- (NSMenuItem *)hideMenuItem
{
return [[hideItem retain] autorelease];
}
-- (NSMenuItem *)appSpecificMenuItem;
+- (NSMenuItem *)appSpecificMenuItem
{
// Create an App-Specific menu item, insert it into the menu and return
// it as an autorelease item.
diff --git a/src/gui/kernel/qcocoaview_mac.mm b/src/gui/kernel/qcocoaview_mac.mm
index dfcc2e6..d5363bd 100644
--- a/src/gui/kernel/qcocoaview_mac.mm
+++ b/src/gui/kernel/qcocoaview_mac.mm
@@ -302,7 +302,6 @@ static int qCocoaViewCount = 0;
QMimeData *mimeData = dropData;
if (QDragManager::self()->source())
mimeData = QDragManager::self()->dragPrivate()->data;
- NSPoint globalPoint = [[sender draggingDestinationWindow] convertBaseToScreen:windowPoint];
NSPoint localPoint = [self convertPoint:windowPoint fromView:nil];
QPoint posDrag(localPoint.x, localPoint.y);
NSDragOperation nsActions = [sender draggingSourceOperationMask];
@@ -365,7 +364,6 @@ static int qCocoaViewCount = 0;
return NSDragOperationNone;
}
// return last value, if we are still in the answerRect.
- NSPoint globalPoint = [[sender draggingDestinationWindow] convertBaseToScreen:windowPoint];
NSPoint localPoint = [self convertPoint:windowPoint fromView:nil];
NSDragOperation nsActions = [sender draggingSourceOperationMask];
QPoint posDrag(localPoint.x, localPoint.y);
@@ -434,7 +432,6 @@ static int qCocoaViewCount = 0;
dragEnterSequence = -1;
[self addDropData:sender];
- NSPoint globalPoint = [[sender draggingDestinationWindow] convertBaseToScreen:windowPoint];
NSPoint localPoint = [self convertPoint:windowPoint fromView:nil];
QPoint posDrop(localPoint.x, localPoint.y);
@@ -470,14 +467,14 @@ static int qCocoaViewCount = 0;
[super dealloc];
}
-- (BOOL)isOpaque;
+- (BOOL)isOpaque
{
if (!qwidgetprivate)
return [super isOpaque];
return qwidgetprivate->isOpaque;
}
-- (BOOL)isFlipped;
+- (BOOL)isFlipped
{
return YES;
}
@@ -620,8 +617,8 @@ static int qCocoaViewCount = 0;
// is the case. This makes sure child widgets are drawn as well, Cocoa does not know about
// those and wont send them drawRect calls.
if (qwidget->testAttribute(Qt::WA_NativeWindow) && qt_widget_private(qwidget)->hasAlienChildren == false) {
- if (engine && !qwidget->testAttribute(Qt::WA_NoSystemBackground)
- && (qwidget->isWindow() || qwidget->autoFillBackground())
+ if ((engine && !qwidget->testAttribute(Qt::WA_NoSystemBackground)
+ && (qwidget->isWindow() || qwidget->autoFillBackground()))
|| qwidget->testAttribute(Qt::WA_TintedBackground)
|| qwidget->testAttribute(Qt::WA_StyledBackground)) {
#ifdef DEBUG_WIDGET_PAINT
@@ -978,32 +975,32 @@ static int qCocoaViewCount = 0;
}
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
-- (void)touchesBeganWithEvent:(NSEvent *)event;
+- (void)touchesBeganWithEvent:(NSEvent *)event
{
bool all = qwidget->testAttribute(Qt::WA_TouchPadAcceptSingleTouchEvents);
qt_translateRawTouchEvent(qwidget, QTouchEvent::TouchPad, QCocoaTouch::getCurrentTouchPointList(event, all));
}
-- (void)touchesMovedWithEvent:(NSEvent *)event;
+- (void)touchesMovedWithEvent:(NSEvent *)event
{
bool all = qwidget->testAttribute(Qt::WA_TouchPadAcceptSingleTouchEvents);
qt_translateRawTouchEvent(qwidget, QTouchEvent::TouchPad, QCocoaTouch::getCurrentTouchPointList(event, all));
}
-- (void)touchesEndedWithEvent:(NSEvent *)event;
+- (void)touchesEndedWithEvent:(NSEvent *)event
{
bool all = qwidget->testAttribute(Qt::WA_TouchPadAcceptSingleTouchEvents);
qt_translateRawTouchEvent(qwidget, QTouchEvent::TouchPad, QCocoaTouch::getCurrentTouchPointList(event, all));
}
-- (void)touchesCancelledWithEvent:(NSEvent *)event;
+- (void)touchesCancelledWithEvent:(NSEvent *)event
{
bool all = qwidget->testAttribute(Qt::WA_TouchPadAcceptSingleTouchEvents);
qt_translateRawTouchEvent(qwidget, QTouchEvent::TouchPad, QCocoaTouch::getCurrentTouchPointList(event, all));
}
#endif // MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
-- (void)magnifyWithEvent:(NSEvent *)event;
+- (void)magnifyWithEvent:(NSEvent *)event
{
if (!QApplicationPrivate::tryModalHelper(qwidget, 0))
return;
@@ -1018,7 +1015,7 @@ static int qCocoaViewCount = 0;
#endif // QT_NO_GESTURES
}
-- (void)rotateWithEvent:(NSEvent *)event;
+- (void)rotateWithEvent:(NSEvent *)event
{
if (!QApplicationPrivate::tryModalHelper(qwidget, 0))
return;
@@ -1033,7 +1030,7 @@ static int qCocoaViewCount = 0;
#endif // QT_NO_GESTURES
}
-- (void)swipeWithEvent:(NSEvent *)event;
+- (void)swipeWithEvent:(NSEvent *)event
{
if (!QApplicationPrivate::tryModalHelper(qwidget, 0))
return;
@@ -1055,7 +1052,7 @@ static int qCocoaViewCount = 0;
#endif // QT_NO_GESTURES
}
-- (void)beginGestureWithEvent:(NSEvent *)event;
+- (void)beginGestureWithEvent:(NSEvent *)event
{
if (!QApplicationPrivate::tryModalHelper(qwidget, 0))
return;
@@ -1069,7 +1066,7 @@ static int qCocoaViewCount = 0;
#endif // QT_NO_GESTURES
}
-- (void)endGestureWithEvent:(NSEvent *)event;
+- (void)endGestureWithEvent:(NSEvent *)event
{
if (!QApplicationPrivate::tryModalHelper(qwidget, 0))
return;
@@ -1609,7 +1606,6 @@ Qt::DropAction QDragManager::drag(QDrag *o)
dndParams.localPoint.y + pix.height() - hotspot.y()};
NSSize mouseOffset = {0.0, 0.0};
NSPasteboard *pboard = [NSPasteboard pasteboardWithName:NSDragPboard];
- NSPoint windowPoint = [dndParams.theEvent locationInWindow];
dragPrivate()->executed_action = Qt::ActionMask;
// do the drag
[dndParams.view retain];
diff --git a/src/gui/kernel/qcocoawindow_mac.mm b/src/gui/kernel/qcocoawindow_mac.mm
index f1b642b..8d44003 100644
--- a/src/gui/kernel/qcocoawindow_mac.mm
+++ b/src/gui/kernel/qcocoawindow_mac.mm
@@ -55,7 +55,7 @@ QT_USE_NAMESPACE
@implementation NSWindow (QT_MANGLE_NAMESPACE(QWidgetIntegration))
-- (id)QT_MANGLE_NAMESPACE(qt_initWithQWidget):(QWidget*)widget contentRect:(NSRect)rect styleMask:(NSUInteger)mask;
+- (id)QT_MANGLE_NAMESPACE(qt_initWithQWidget):(QWidget*)widget contentRect:(NSRect)rect styleMask:(NSUInteger)mask
{
self = [self initWithContentRect:rect styleMask:mask backing:NSBackingStoreBuffered defer:YES];
if (self) {
diff --git a/src/gui/kernel/qcocoawindowdelegate_mac.mm b/src/gui/kernel/qcocoawindowdelegate_mac.mm
index ffba6c2..6ce7b35 100644
--- a/src/gui/kernel/qcocoawindowdelegate_mac.mm
+++ b/src/gui/kernel/qcocoawindowdelegate_mac.mm
@@ -138,7 +138,7 @@ static void cleanupCocoaWindowDelegate()
}
}
-- (void)dumpMaximizedStateforWidget:(QWidget*)qwidget window:(NSWindow *)window;
+- (void)dumpMaximizedStateforWidget:(QWidget*)qwidget window:(NSWindow *)window
{
if (!window)
return; // Nothing to do.
diff --git a/src/gui/kernel/qwidget_mac.mm b/src/gui/kernel/qwidget_mac.mm
index fc94616..bcddae5 100644
--- a/src/gui/kernel/qwidget_mac.mm
+++ b/src/gui/kernel/qwidget_mac.mm
@@ -2294,7 +2294,10 @@ void QWidgetPrivate::finishCreateWindow_sys_Cocoa(void * /*NSWindow * */ voidWin
} else {
[windowRef setHidesOnDeactivate:NO];
}
- [windowRef setHasShadow:YES];
+ if (q->testAttribute(Qt::WA_MacNoShadow))
+ [windowRef setHasShadow:NO];
+ else
+ [windowRef setHasShadow:YES];
Q_UNUSED(parentWidget);
Q_UNUSED(dialog);
@@ -2931,7 +2934,7 @@ void QWidgetPrivate::setParent_sys(QWidget *parent, Qt::WindowFlags f)
// unless this is an alien widget. )
const bool nonWindowWithCreatedParent = !q->isWindow() && parent->testAttribute(Qt::WA_WState_Created);
const bool nativeWidget = q->internalWinId() != 0;
- if (wasCreated || nativeWidget && nonWindowWithCreatedParent) {
+ if (wasCreated || (nativeWidget && nonWindowWithCreatedParent)) {
createWinId();
if (q->isWindow()) {
#ifndef QT_MAC_USE_COCOA
diff --git a/src/gui/styles/qmacstyle_mac.mm b/src/gui/styles/qmacstyle_mac.mm
index a05ec6b..9ef2f02 100644
--- a/src/gui/styles/qmacstyle_mac.mm
+++ b/src/gui/styles/qmacstyle_mac.mm
@@ -1566,8 +1566,7 @@ void QMacStylePrivate::timerEvent(QTimerEvent *)
progressBars.removeAt(i);
} else {
if (QProgressBar *pb = qobject_cast<QProgressBar *>(maybeProgress)) {
- if (pb->maximum() == 0 || pb->value() > 0
- && pb->value() < pb->maximum()) {
+ if (pb->maximum() == 0 || (pb->value() > 0 && pb->value() < pb->maximum())) {
if (doAnimate(AquaProgressBar))
pb->update();
}
@@ -3608,7 +3607,7 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter
break;
}
}
- bool stretchTabs = (!verticalTabs && tabRect.height() > 22 || verticalTabs && tabRect.width() > 22);
+ bool stretchTabs = (!verticalTabs && tabRect.height() > 22) || (verticalTabs && tabRect.width() > 22);
switch (tp) {
case QStyleOptionTab::Beginning:
@@ -4033,7 +4032,6 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter
bdi.version = qt_mac_hitheme_version;
bdi.state = kThemeMenuBarNormal;
bdi.attributes = 0;
- HIRect hirect = qt_hirectForQRect(mi->rect);
HIThemeDrawMenuBarBackground(&menuRect, &bdi, cg, kHIThemeOrientationNormal);
}
@@ -5335,8 +5333,8 @@ QRect QMacStyle::subControlRect(ComplexControl cc, const QStyleOptionComplex *op
case SC_GroupBoxCheckBox: {
// Cheat and use the smaller font if we need to
bool checkable = groupBox->subControls & SC_GroupBoxCheckBox;
- bool fontIsSet = (widget && widget->testAttribute(Qt::WA_SetFont)
- || !QApplication::desktopSettingsAware());
+ bool fontIsSet = (widget && widget->testAttribute(Qt::WA_SetFont))
+ || !QApplication::desktopSettingsAware();
int tw;
int h;
int margin = flat || hasNoText ? 0 : 12;
diff --git a/src/gui/styles/qstyle.cpp b/src/gui/styles/qstyle.cpp
index 3ebfab2..be8f794 100644
--- a/src/gui/styles/qstyle.cpp
+++ b/src/gui/styles/qstyle.cpp
@@ -2456,6 +2456,8 @@ QDebug operator<<(QDebug debug, QStyle::State state)
qSort(states);
debug << states.join(QLatin1String(" | "));
debug << ')';
+#else
+ Q_UNUSED(state);
#endif
return debug;
}
diff --git a/src/gui/styles/qstyleoption.cpp b/src/gui/styles/qstyleoption.cpp
index 4780edf..05ca793 100644
--- a/src/gui/styles/qstyleoption.cpp
+++ b/src/gui/styles/qstyleoption.cpp
@@ -5483,6 +5483,8 @@ QDebug operator<<(QDebug debug, const QStyleOption::OptionType &optionType)
case QStyleOption::SO_GraphicsItem:
debug << "SO_GraphicsItem"; break;
}
+#else
+ Q_UNUSED(optionType);
#endif
return debug;
}
@@ -5496,6 +5498,8 @@ QDebug operator<<(QDebug debug, const QStyleOption &option)
debug << ',' << option.state;
debug << ',' << option.rect;
debug << ')';
+#else
+ Q_UNUSED(option);
#endif
return debug;
}
diff --git a/src/gui/widgets/qcocoamenu_mac.mm b/src/gui/widgets/qcocoamenu_mac.mm
index b670186..8e7223f 100644
--- a/src/gui/widgets/qcocoamenu_mac.mm
+++ b/src/gui/widgets/qcocoamenu_mac.mm
@@ -44,6 +44,7 @@
#ifdef QT_MAC_USE_COCOA
#import <private/qcocoamenu_mac_p.h>
#import <private/qcocoamenuloader_mac_p.h>
+#import <private/qcocoaapplication_mac_p.h>
#include <private/qt_cocoa_helpers_mac_p.h>
#include <private/qapplication_p.h>
#include <private/qaction_p.h>
@@ -60,6 +61,7 @@ QT_FORWARD_DECLARE_CLASS(QEvent)
QT_BEGIN_NAMESPACE
extern bool qt_sendSpontaneousEvent(QObject*, QEvent*); //qapplication.cpp
+extern NSString *qt_mac_removePrivateUnicode(NSString* string);
QT_END_NAMESPACE
QT_USE_NAMESPACE
@@ -78,7 +80,7 @@ QT_USE_NAMESPACE
return self;
}
-- (void)menu:(NSMenu*)menu willHighlightItem:(NSMenuItem*)item;
+- (void)menu:(NSMenu*)menu willHighlightItem:(NSMenuItem*)item
{
Q_UNUSED(menu);
@@ -99,7 +101,7 @@ QT_USE_NAMESPACE
}
}
-- (void)menuWillOpen:(NSMenu*)menu;
+- (void)menuWillOpen:(NSMenu*)menu
{
while (QWidget *popup
= QApplication::activePopupWidget())
@@ -109,7 +111,7 @@ QT_USE_NAMESPACE
qt_mac_menu_collapseSeparators(menu, qtmenu->separatorsCollapsible());
}
-- (void)menuDidClose:(NSMenu*)menu;
+- (void)menuDidClose:(NSMenu*)menu
{
qt_mac_emit_menuSignals(((QT_MANGLE_NAMESPACE(QCocoaMenu) *)menu)->qmenu, false);
if (previousAction) {
@@ -157,7 +159,6 @@ QT_USE_NAMESPACE
// (i.e., fire the menu action).
NSMenuItem *whichItem;
// Change the private unicode keys to the ones used in setting the "Key Equivalents"
- extern NSString *qt_mac_removePrivateUnicode(NSString* string);
NSString *characters = qt_mac_removePrivateUnicode([event characters]);
if ([self hasShortcut:menu
forKey:characters
diff --git a/tests/auto/qfilesystemwatcher/tst_qfilesystemwatcher.cpp b/tests/auto/qfilesystemwatcher/tst_qfilesystemwatcher.cpp
index a26e34d..fd898ee 100644
--- a/tests/auto/qfilesystemwatcher/tst_qfilesystemwatcher.cpp
+++ b/tests/auto/qfilesystemwatcher/tst_qfilesystemwatcher.cpp
@@ -82,6 +82,8 @@ private slots:
void removeFileAndUnWatch();
void cleanup();
+
+ void QTBUG15255_deadlock();
private:
QStringList do_force_engines;
bool do_force_native;
@@ -557,5 +559,23 @@ void tst_QFileSystemWatcher::removeFileAndUnWatch()
watcher.addPath(filename);
}
+class SomeSingleton : public QObject
+{
+public:
+ SomeSingleton() : mFsWatcher(new QFileSystemWatcher(this)) { mFsWatcher->addPath(QLatin1String("/usr/lib"));}
+ void bla() const {}
+ QFileSystemWatcher* mFsWatcher;
+};
+
+Q_GLOBAL_STATIC(SomeSingleton, someSingleton)
+
+void tst_QFileSystemWatcher::QTBUG15255_deadlock()
+{
+ someSingleton()->bla();
+ //the test must still finish
+ QTest::qWait(30);
+}
+
+
QTEST_MAIN(tst_QFileSystemWatcher)
#include "tst_qfilesystemwatcher.moc"
diff --git a/tests/auto/qthread/tst_qthread.cpp b/tests/auto/qthread/tst_qthread.cpp
index f290a2b..01f080f 100644
--- a/tests/auto/qthread/tst_qthread.cpp
+++ b/tests/auto/qthread/tst_qthread.cpp
@@ -107,6 +107,10 @@ private slots:
void QTBUG13810_exitAndStart();
void connectThreadFinishedSignalToObjectDeleteLaterSlot();
+ void wait2();
+ void wait3_slowDestructor();
+ void destroyFinishRace();
+ void startFinishRace();
void stressTest();
};
@@ -976,6 +980,7 @@ void tst_QThread::QTBUG13810_exitAndStart()
QCOMPARE(sync1.m_prop, 89);
}
+
void tst_QThread::connectThreadFinishedSignalToObjectDeleteLaterSlot()
{
QThread thread;
@@ -990,5 +995,123 @@ void tst_QThread::connectThreadFinishedSignalToObjectDeleteLaterSlot()
QVERIFY(p.isNull());
}
+class Waiting_Thread : public QThread
+{
+public:
+ enum { WaitTime = 800 };
+ QMutex mutex;
+ QWaitCondition cond1;
+ QWaitCondition cond2;
+
+ void run()
+ {
+ QMutexLocker locker(&mutex);
+ cond1.wait(&mutex);
+ cond2.wait(&mutex, WaitTime);
+ }
+};
+
+void tst_QThread::wait2()
+{
+ QElapsedTimer timer;
+ Waiting_Thread thread;
+ thread.start();
+ timer.start();
+ QVERIFY(!thread.wait(Waiting_Thread::WaitTime));
+ qint64 elapsed = timer.elapsed();
+
+ QVERIFY(elapsed >= Waiting_Thread::WaitTime);
+ //QVERIFY(elapsed < Waiting_Thread::WaitTime * 1.4);
+
+ timer.start();
+ thread.cond1.wakeOne();
+ QVERIFY(thread.wait(/*Waiting_Thread::WaitTime * 1.4*/));
+ elapsed = timer.elapsed();
+ QVERIFY(elapsed >= Waiting_Thread::WaitTime);
+ //QVERIFY(elapsed < Waiting_Thread::WaitTime * 1.4);
+}
+
+
+class SlowSlotObject : public QObject {
+ Q_OBJECT
+public:
+ QMutex mutex;
+ QWaitCondition cond;
+public slots:
+ void slowSlot() {
+ QMutexLocker locker(&mutex);
+ cond.wait(&mutex);
+ }
+};
+
+void tst_QThread::wait3_slowDestructor()
+{
+ SlowSlotObject slow;
+ QThread thread;
+ QObject::connect(&thread, SIGNAL(finished()), &slow, SLOT(slowSlot()), Qt::DirectConnection);
+
+ enum { WaitTime = 1800 };
+ QElapsedTimer timer;
+
+ thread.start();
+ thread.quit();
+ //the quit function will cause the thread to finish and enter the slowSlot that is blocking
+
+ timer.start();
+ QVERIFY(!thread.wait(Waiting_Thread::WaitTime));
+ qint64 elapsed = timer.elapsed();
+
+ QVERIFY(elapsed >= Waiting_Thread::WaitTime);
+ //QVERIFY(elapsed < Waiting_Thread::WaitTime * 1.4);
+
+ slow.cond.wakeOne();
+ //now the thread should finish quickly
+ QVERIFY(thread.wait(one_minute));
+}
+
+void tst_QThread::destroyFinishRace()
+{
+ class Thread : public QThread { void run() {} };
+ for (int i = 0; i < 15; i++) {
+ Thread *thr = new Thread;
+ connect(thr, SIGNAL(finished()), thr, SLOT(deleteLater()));
+ QWeakPointer<QThread> weak(static_cast<QThread*>(thr));
+ thr->start();
+ while (weak) {
+ qApp->processEvents();
+ qApp->processEvents();
+ qApp->processEvents();
+ qApp->processEvents();
+ }
+ }
+}
+
+void tst_QThread::startFinishRace()
+{
+ class Thread : public QThread {
+ public:
+ Thread() : i (50) {}
+ void run() {
+ i--;
+ if (!i) disconnect(this, SIGNAL(finished()), 0, 0);
+ }
+ int i;
+ };
+ for (int i = 0; i < 15; i++) {
+ Thread thr;
+ connect(&thr, SIGNAL(finished()), &thr, SLOT(start()));
+ thr.start();
+ while (!thr.isFinished() || thr.i != 0) {
+ qApp->processEvents();
+ qApp->processEvents();
+ qApp->processEvents();
+ qApp->processEvents();
+ }
+ QCOMPARE(thr.i, 0);
+ }
+}
+
+
+
QTEST_MAIN(tst_QThread)
#include "tst_qthread.moc"
diff --git a/tests/auto/qthreadstorage/tst_qthreadstorage.cpp b/tests/auto/qthreadstorage/tst_qthreadstorage.cpp
index ed86165..0237dac 100644
--- a/tests/auto/qthreadstorage/tst_qthreadstorage.cpp
+++ b/tests/auto/qthreadstorage/tst_qthreadstorage.cpp
@@ -77,6 +77,9 @@ private slots:
void adoptedThreads();
void ensureCleanupOrder();
void QTBUG13877_crashOnExit();
+ void QTBUG14579_leakInDestructor();
+ void QTBUG14579_resetInDestructor();
+ void valueBased();
};
class Pointer
@@ -310,5 +313,192 @@ void tst_QThreadStorage::QTBUG13877_crashOnExit()
QVERIFY(process.exitStatus() != QProcess::CrashExit);
}
+// S stands for thread Safe.
+class SPointer
+{
+public:
+ static QBasicAtomicInt count;
+ inline SPointer() { count.ref(); }
+ inline ~SPointer() { count.deref(); }
+ inline SPointer(const SPointer &other) { count.ref(); }
+};
+QBasicAtomicInt SPointer::count = Q_BASIC_ATOMIC_INITIALIZER(0);
+
+Q_GLOBAL_STATIC(QThreadStorage<SPointer *>, QTBUG14579_pointers1)
+Q_GLOBAL_STATIC(QThreadStorage<SPointer *>, QTBUG14579_pointers2)
+
+class QTBUG14579_class
+{
+public:
+ SPointer member;
+ inline ~QTBUG14579_class() {
+ QVERIFY(!QTBUG14579_pointers1()->hasLocalData());
+ QVERIFY(!QTBUG14579_pointers2()->hasLocalData());
+ QTBUG14579_pointers2()->setLocalData(new SPointer);
+ QTBUG14579_pointers1()->setLocalData(new SPointer);
+ QVERIFY(QTBUG14579_pointers1()->hasLocalData());
+ QVERIFY(QTBUG14579_pointers2()->hasLocalData());
+ }
+};
+
+
+void tst_QThreadStorage::QTBUG14579_leakInDestructor()
+{
+ class Thread : public QThread
+ {
+ public:
+ QThreadStorage<QTBUG14579_class *> &tls;
+
+ Thread(QThreadStorage<QTBUG14579_class *> &t) : tls(t) { }
+
+ void run()
+ {
+ QVERIFY(!tls.hasLocalData());
+ tls.setLocalData(new QTBUG14579_class);
+ QVERIFY(tls.hasLocalData());
+ }
+ };
+ int c = SPointer::count;
+
+ QThreadStorage<QTBUG14579_class *> tls;
+
+ QVERIFY(!QTBUG14579_pointers1()->hasLocalData());
+ QThreadStorage<int *> tls2; //add some more tls to make sure ids are not following each other too much
+ QThreadStorage<int *> tls3;
+ QVERIFY(!tls2.hasLocalData());
+ QVERIFY(!tls3.hasLocalData());
+ QVERIFY(!tls.hasLocalData());
+
+ Thread t1(tls);
+ Thread t2(tls);
+ Thread t3(tls);
+
+ t1.start();
+ t2.start();
+ t3.start();
+
+ QVERIFY(t1.wait());
+ QVERIFY(t2.wait());
+ QVERIFY(t3.wait());
+
+ //check all the constructed things have been destructed
+ QCOMPARE(int(SPointer::count), c);
+}
+
+
+class QTBUG14579_reset;
+Q_GLOBAL_STATIC(QThreadStorage<QTBUG14579_reset *>, QTBUG14579_resetTls)
+
+class QTBUG14579_reset {
+public:
+ SPointer member;
+ ~QTBUG14579_reset() {
+ //Quite stupid, but WTF::ThreadSpecific<T>::destroy does it.
+ QTBUG14579_resetTls()->setLocalData(this);
+ }
+};
+
+
+void tst_QThreadStorage::QTBUG14579_resetInDestructor()
+{
+ class Thread : public QThread
+ {
+ public:
+ void run()
+ {
+ QVERIFY(!QTBUG14579_resetTls()->hasLocalData());
+ QTBUG14579_resetTls()->setLocalData(new QTBUG14579_reset);
+ QVERIFY(QTBUG14579_resetTls()->hasLocalData());
+ }
+ };
+ int c = SPointer::count;
+
+ Thread t1;
+ Thread t2;
+ Thread t3;
+ t1.start();
+ t2.start();
+ t3.start();
+ QVERIFY(t1.wait());
+ QVERIFY(t2.wait());
+ QVERIFY(t3.wait());
+
+ //check all the constructed things have been destructed
+ QCOMPARE(int(SPointer::count), c);
+}
+
+
+void tst_QThreadStorage::valueBased()
+{
+ struct Thread : QThread {
+ QThreadStorage<SPointer> &tlsSPointer;
+ QThreadStorage<QString> &tlsString;
+ QThreadStorage<int> &tlsInt;
+
+ int someNumber;
+ QString someString;
+ Thread(QThreadStorage<SPointer> &t1, QThreadStorage<QString> &t2, QThreadStorage<int> &t3)
+ : tlsSPointer(t1), tlsString(t2), tlsInt(t3) { }
+
+ void run() {
+ /*QVERIFY(!tlsSPointer.hasLocalData());
+ QVERIFY(!tlsString.hasLocalData());
+ QVERIFY(!tlsInt.hasLocalData());*/
+ SPointer pointercopy = tlsSPointer.localData();
+
+ //Default constructed values
+ QVERIFY(tlsString.localData().isNull());
+ QCOMPARE(tlsInt.localData(), 0);
+
+ //setting
+ tlsString.setLocalData(someString);
+ tlsInt.setLocalData(someNumber);
+
+ QCOMPARE(tlsString.localData(), someString);
+ QCOMPARE(tlsInt.localData(), someNumber);
+
+ //changing
+ tlsSPointer.setLocalData(SPointer());
+ tlsInt.localData() += 42;
+ tlsString.localData().append(QLatin1String(" world"));
+
+ QCOMPARE(tlsString.localData(), (someString + QLatin1String(" world")));
+ QCOMPARE(tlsInt.localData(), (someNumber + 42));
+
+ // operator=
+ tlsString.localData() = QString::number(someNumber);
+ QCOMPARE(tlsString.localData().toInt(), someNumber);
+ }
+ };
+
+ QThreadStorage<SPointer> tlsSPointer;
+ QThreadStorage<QString> tlsString;
+ QThreadStorage<int> tlsInt;
+
+ int c = SPointer::count;
+
+ Thread t1(tlsSPointer, tlsString, tlsInt);
+ Thread t2(tlsSPointer, tlsString, tlsInt);
+ Thread t3(tlsSPointer, tlsString, tlsInt);
+ t1.someNumber = 42;
+ t2.someNumber = -128;
+ t3.someNumber = 78;
+ t1.someString = "hello";
+ t2.someString = "trolltech";
+ t3.someString = "nokia";
+
+ t1.start();
+ t2.start();
+ t3.start();
+
+ QVERIFY(t1.wait());
+ QVERIFY(t2.wait());
+ QVERIFY(t3.wait());
+
+ QCOMPARE(c, int(SPointer::count));
+
+}
+
+
QTEST_MAIN(tst_QThreadStorage)
#include "tst_qthreadstorage.moc"