From 78125ea2f051107b84fdc0354acdedb7885308ee Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Thu, 6 Dec 2012 16:47:27 -0600 Subject: Add real threading support, including per-thread event loops, to QThread --- src/tools/qmutex_unix.cpp | 1 - src/tools/qthreadinstance_p.h | 6 ++++++ src/tools/qucom.cpp | 24 ++++++++++++++++++++++++ src/tools/qucom_p.h | 4 +++- 4 files changed, 33 insertions(+), 2 deletions(-) (limited to 'src/tools') diff --git a/src/tools/qmutex_unix.cpp b/src/tools/qmutex_unix.cpp index 7f14e6a..fe60ac3 100644 --- a/src/tools/qmutex_unix.cpp +++ b/src/tools/qmutex_unix.cpp @@ -74,7 +74,6 @@ typedef pthread_mutex_t Q_MUTEX_T; #include #include - // Private class declarations class QRealMutexPrivate : public QMutexPrivate { diff --git a/src/tools/qthreadinstance_p.h b/src/tools/qthreadinstance_p.h index 72611b1..7580b25 100644 --- a/src/tools/qthreadinstance_p.h +++ b/src/tools/qthreadinstance_p.h @@ -62,8 +62,12 @@ #include #endif +class QThread; +class QEventLoop; + class QThreadInstance { public: + static void setCurrentThread(QThread *thread); static QThreadInstance *current(); void init(unsigned int stackSize); @@ -95,6 +99,8 @@ public: static unsigned int __stdcall start( void * ); static void finish( QThreadInstance * ); #endif // Q_OS_WIN32 + + QEventLoop* eventLoop; }; #endif // QT_THREAD_SUPPORT diff --git a/src/tools/qucom.cpp b/src/tools/qucom.cpp index f210318..c48e166 100644 --- a/src/tools/qucom.cpp +++ b/src/tools/qucom.cpp @@ -39,6 +39,9 @@ **********************************************************************/ #include "qucom_p.h" +#include "qucomextra_p.h" + +#include "qvariant.h" // Standard types @@ -545,3 +548,24 @@ void QUType_QString::clear( QUObject *o ) delete (QString*)o->payload.ptr; o->payload.ptr = 0; } + +QUObject* QUObject::deepCopy(QUObject* newLocation) { + QUObject* ret; + if (newLocation) { + ret = new(newLocation) QUObject(*this); + } + else { + ret = new QUObject(*this); + } + // Any type that has a clear() method must be copied here! + if (*(type->uuid()) == TID_QUType_charstar) { + static_QUType_charstar.set( ret, (const char *)static_QUType_charstar.get(this), true ); + } + if (*(type->uuid()) == TID_QUType_QString) { + static_QUType_QString.set( ret, (QString)static_QUType_QString.get(this) ); + } + if (*(type->uuid()) == TID_QUType_QVariant) { + static_QUType_QVariant.set( ret, (QVariant)static_QUType_QVariant.get(this) ); + } + return ret; +} diff --git a/src/tools/qucom_p.h b/src/tools/qucom_p.h index 6410ceb..3ade5d4 100644 --- a/src/tools/qucom_p.h +++ b/src/tools/qucom_p.h @@ -127,7 +127,7 @@ extern Q_EXPORT QUType_Null static_QUType_Null; struct Q_EXPORT QUObject { public: // scary MSVC bug makes this necessary - QUObject() : type( &static_QUType_Null ) {} + QUObject() : type( &static_QUType_Null ), isLastObject(false) {} ~QUObject() { type->clear( this ); } QUType *type; @@ -184,6 +184,8 @@ public: // scary MSVC bug makes this necessary } payload; + QUObject* deepCopy(QUObject*); + bool isLastObject; }; -- cgit v1.2.1 From 9bff9eeefc262c8509b2db7c1120f6001d65e64c Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Fri, 7 Dec 2012 15:01:56 -0600 Subject: Add level method to recursive mutex Enhance thread safety when making event calls Minor cleanup of whitespace in glib event loop --- src/tools/qmutex.h | 3 +++ src/tools/qmutex_p.h | 1 + src/tools/qmutex_unix.cpp | 28 ++++++++++++++++++++++++++++ 3 files changed, 32 insertions(+) (limited to 'src/tools') diff --git a/src/tools/qmutex.h b/src/tools/qmutex.h index 9eb1a69..1dec4d2 100644 --- a/src/tools/qmutex.h +++ b/src/tools/qmutex.h @@ -74,6 +74,9 @@ private: QMutex( const QMutex & ); QMutex &operator=( const QMutex & ); #endif + +public: + int level(); }; class Q_EXPORT QMutexLocker diff --git a/src/tools/qmutex_p.h b/src/tools/qmutex_p.h index c80c349..d06839c 100644 --- a/src/tools/qmutex_p.h +++ b/src/tools/qmutex_p.h @@ -67,6 +67,7 @@ public: virtual bool locked() = 0; virtual bool trylock() = 0; virtual int type() const = 0; + virtual int level() = 0; }; diff --git a/src/tools/qmutex_unix.cpp b/src/tools/qmutex_unix.cpp index fe60ac3..de0f909 100644 --- a/src/tools/qmutex_unix.cpp +++ b/src/tools/qmutex_unix.cpp @@ -85,6 +85,7 @@ public: bool locked(); bool trylock(); int type() const; + int level(); bool recursive; }; @@ -101,6 +102,7 @@ public: bool locked(); bool trylock(); int type() const; + int level(); int count; unsigned long owner; @@ -196,6 +198,11 @@ int QRealMutexPrivate::type() const return recursive ? Q_MUTEX_RECURSIVE : Q_MUTEX_NORMAL; } +int QRealMutexPrivate::level() +{ + return locked(); +} + #ifndef Q_RECURSIVE_MUTEX_TYPE QRecursiveMutexPrivate::QRecursiveMutexPrivate() @@ -329,6 +336,11 @@ int QRecursiveMutexPrivate::type() const return Q_MUTEX_RECURSIVE; } +int QRecursiveMutexPrivate::level() +{ + return count; +} + #endif // !Q_RECURSIVE_MUTEX_TYPE @@ -510,6 +522,22 @@ bool QMutex::tryLock() return d->trylock(); } +/*! + Returns the current lock level of the mutex. + 0 means the mutex is unlocked + This method should only be called when the mutex has already been locked + by lock(), otherwise the lock level could change before the next line + of code is executed. + + WARNING: Non-recursive mutexes will never exceed a lock level of 1! + + \sa lock(), unlock(), locked() +*/ +int QMutex::level() +{ + return d->level(); +} + /*! \class QMutexLocker qmutex.h \brief The QMutexLocker class simplifies locking and unlocking QMutexes. -- cgit v1.2.1