|
|
|
@ -72,6 +72,7 @@ typedef pthread_mutex_t Q_MUTEX_T;
|
|
|
|
|
#include "qmutex_p.h"
|
|
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
// Private class declarations
|
|
|
|
@ -105,8 +106,7 @@ public:
|
|
|
|
|
int level();
|
|
|
|
|
|
|
|
|
|
int count;
|
|
|
|
|
pthread_t owner;
|
|
|
|
|
bool is_owned;
|
|
|
|
|
unsigned long owner;
|
|
|
|
|
pthread_mutex_t handle2;
|
|
|
|
|
};
|
|
|
|
|
#endif // !Q_RECURSIVE_MUTEX_TYPE
|
|
|
|
@ -207,7 +207,7 @@ int QRealMutexPrivate::level()
|
|
|
|
|
|
|
|
|
|
#ifndef Q_RECURSIVE_MUTEX_TYPE
|
|
|
|
|
QRecursiveMutexPrivate::QRecursiveMutexPrivate()
|
|
|
|
|
: count(0), is_owned(false)
|
|
|
|
|
: count(0), owner(0)
|
|
|
|
|
{
|
|
|
|
|
pthread_mutexattr_t attr;
|
|
|
|
|
pthread_mutexattr_init(&attr);
|
|
|
|
@ -244,15 +244,14 @@ void QRecursiveMutexPrivate::lock()
|
|
|
|
|
{
|
|
|
|
|
pthread_mutex_lock(&handle2);
|
|
|
|
|
|
|
|
|
|
if (count > 0 && pthread_equal(owner, pthread_self()) ) {
|
|
|
|
|
if (count > 0 && owner == (unsigned long) pthread_self()) {
|
|
|
|
|
count++;
|
|
|
|
|
} else {
|
|
|
|
|
pthread_mutex_unlock(&handle2);
|
|
|
|
|
pthread_mutex_lock(&handle);
|
|
|
|
|
pthread_mutex_lock(&handle2);
|
|
|
|
|
count = 1;
|
|
|
|
|
owner = pthread_self();
|
|
|
|
|
is_owned = true;
|
|
|
|
|
owner = (unsigned long) pthread_self();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pthread_mutex_unlock(&handle2);
|
|
|
|
@ -262,7 +261,7 @@ void QRecursiveMutexPrivate::unlock()
|
|
|
|
|
{
|
|
|
|
|
pthread_mutex_lock(&handle2);
|
|
|
|
|
|
|
|
|
|
if ( is_owned && pthread_equal(owner, pthread_self()) ) {
|
|
|
|
|
if (owner == (unsigned long) pthread_self()) {
|
|
|
|
|
// do nothing if the count is already 0... to reflect the behaviour described
|
|
|
|
|
// in the docs
|
|
|
|
|
if (count && (--count) < 1) {
|
|
|
|
@ -272,6 +271,8 @@ void QRecursiveMutexPrivate::unlock()
|
|
|
|
|
} else {
|
|
|
|
|
#ifdef QT_CHECK_RANGE
|
|
|
|
|
qWarning("QMutex::unlock: unlock from different thread than locker");
|
|
|
|
|
qWarning(" was locked by %d, unlock attempt from %lu",
|
|
|
|
|
(int)owner, (uintptr_t)pthread_self());
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -308,7 +309,7 @@ bool QRecursiveMutexPrivate::trylock()
|
|
|
|
|
|
|
|
|
|
pthread_mutex_lock(&handle2);
|
|
|
|
|
|
|
|
|
|
if ( count > 0 && pthread_equal(owner, pthread_self()) ) {
|
|
|
|
|
if ( count > 0 && owner == (unsigned long) pthread_self() ) {
|
|
|
|
|
count++;
|
|
|
|
|
} else {
|
|
|
|
|
int code = pthread_mutex_trylock(&handle);
|
|
|
|
@ -322,8 +323,7 @@ bool QRecursiveMutexPrivate::trylock()
|
|
|
|
|
ret = FALSE;
|
|
|
|
|
} else {
|
|
|
|
|
count = 1;
|
|
|
|
|
owner = pthread_self();
|
|
|
|
|
is_owned = true;
|
|
|
|
|
owner = (unsigned long) pthread_self();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|