summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorOBATA Akio <obache@wizdas.com>2021-12-27 17:29:50 +0900
committerSlávek Banko <slavek.banko@axis.cz>2021-12-30 17:34:55 +0100
commitaf8acc4fc3ac3e4b0681077796ad831048674988 (patch)
tree88cf57c67ce1a339962d760113398b75eaaa7b74 /src
parentfeeca8d3d14ef661d28a2217ca35b3e100838027 (diff)
downloadqt3-af8acc4fc3ac3e4b0681077796ad831048674988.tar.gz
qt3-af8acc4fc3ac3e4b0681077796ad831048674988.zip
tools: fix to use `pthread_t` for Thread ID
Thread ID is opaque type pthread_t, it may not be compatible with integer, and may integer with valid id `0`. Change to store mutex owner thread ID as `pthread_t` type with valid flag and compare with `pthread_equal()`, and don't try to print it. Signed-off-by: OBATA Akio <obache@wizdas.com> (cherry picked from commit 1e77a5569b098c6b81c54d165cb189a316669dce)
Diffstat (limited to 'src')
-rw-r--r--src/tools/qmutex_unix.cpp20
1 files changed, 10 insertions, 10 deletions
diff --git a/src/tools/qmutex_unix.cpp b/src/tools/qmutex_unix.cpp
index c392d29..e201f41 100644
--- a/src/tools/qmutex_unix.cpp
+++ b/src/tools/qmutex_unix.cpp
@@ -72,7 +72,6 @@ typedef pthread_mutex_t Q_MUTEX_T;
#include "qmutex_p.h"
#include <errno.h>
-#include <stdint.h>
#include <string.h>
@@ -105,7 +104,8 @@ public:
int type() const;
int count;
- unsigned long owner;
+ pthread_t owner;
+ bool is_owned;
pthread_mutex_t handle2;
};
#endif // !Q_RECURSIVE_MUTEX_TYPE
@@ -201,7 +201,7 @@ int QRealMutexPrivate::type() const
#ifndef Q_RECURSIVE_MUTEX_TYPE
QRecursiveMutexPrivate::QRecursiveMutexPrivate()
- : count(0), owner(0)
+ : count(0), is_owned(false)
{
pthread_mutexattr_t attr;
pthread_mutexattr_init(&attr);
@@ -238,14 +238,15 @@ void QRecursiveMutexPrivate::lock()
{
pthread_mutex_lock(&handle2);
- if (count > 0 && owner == (unsigned long) pthread_self()) {
+ if (count > 0 && pthread_equal(owner, pthread_self()) ) {
count++;
} else {
pthread_mutex_unlock(&handle2);
pthread_mutex_lock(&handle);
pthread_mutex_lock(&handle2);
count = 1;
- owner = (unsigned long) pthread_self();
+ owner = pthread_self();
+ is_owned = true;
}
pthread_mutex_unlock(&handle2);
@@ -255,7 +256,7 @@ void QRecursiveMutexPrivate::unlock()
{
pthread_mutex_lock(&handle2);
- if (owner == (unsigned long) pthread_self()) {
+ if ( is_owned && pthread_equal(owner, pthread_self()) ) {
// do nothing if the count is already 0... to reflect the behaviour described
// in the docs
if (count && (--count) < 1) {
@@ -265,8 +266,6 @@ 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
}
@@ -303,7 +302,7 @@ bool QRecursiveMutexPrivate::trylock()
pthread_mutex_lock(&handle2);
- if ( count > 0 && owner == (unsigned long) pthread_self() ) {
+ if ( count > 0 && pthread_equal(owner, pthread_self()) ) {
count++;
} else {
int code = pthread_mutex_trylock(&handle);
@@ -317,7 +316,8 @@ bool QRecursiveMutexPrivate::trylock()
ret = FALSE;
} else {
count = 1;
- owner = (unsigned long) pthread_self();
+ owner = pthread_self();
+ is_owned = true;
}
}