summaryrefslogtreecommitdiffstats
path: root/src/tools
diff options
context:
space:
mode:
authorTimothy Pearson <kb9vqf@pearsoncomputing.net>2012-12-07 15:01:56 -0600
committerTimothy Pearson <kb9vqf@pearsoncomputing.net>2012-12-07 15:01:56 -0600
commit9bff9eeefc262c8509b2db7c1120f6001d65e64c (patch)
tree3e837032fb29614f059d2b29b18e3210d6e8c8a8 /src/tools
parent85b3c5d0ec2280393e1c5ac7af6a56abf9fc2e9a (diff)
downloadqt3-9bff9eeefc262c8509b2db7c1120f6001d65e64c.tar.gz
qt3-9bff9eeefc262c8509b2db7c1120f6001d65e64c.zip
Add level method to recursive mutex
Enhance thread safety when making event calls Minor cleanup of whitespace in glib event loop
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/qmutex.h3
-rw-r--r--src/tools/qmutex_p.h1
-rw-r--r--src/tools/qmutex_unix.cpp28
3 files changed, 32 insertions, 0 deletions
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
@@ -511,6 +523,22 @@ bool QMutex::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.