diff options
-rw-r--r-- | src/tools/qmutex_unix.cpp | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/src/tools/qmutex_unix.cpp b/src/tools/qmutex_unix.cpp index dae1533c4..5cb037a18 100644 --- a/src/tools/qmutex_unix.cpp +++ b/src/tools/qmutex_unix.cpp @@ -88,6 +88,7 @@ public: int level(); bool recursive; + int count; }; #ifndef Q_RECURSIVE_MUTEX_TYPE @@ -127,7 +128,7 @@ TQMutexPrivate::~TQMutexPrivate() // real mutex class TQRealMutexPrivate::TQRealMutexPrivate(bool recurs) - : recursive(recurs) + : count(0), recursive(recurs) { pthread_mutexattr_t attr; pthread_mutexattr_init(&attr); @@ -146,36 +147,31 @@ void TQRealMutexPrivate::lock() { int ret = pthread_mutex_lock(&handle); + if (!ret) { + count++; + } else { #ifdef QT_CHECK_RANGE - if (ret) tqWarning("Mutex lock failure: %s", strerror(ret)); #endif + } } void TQRealMutexPrivate::unlock() { + count--; int ret = pthread_mutex_unlock(&handle); + if (ret) { + count++; #ifdef QT_CHECK_RANGE - if (ret) tqWarning("Mutex unlock failure: %s", strerror(ret)); #endif + } } bool TQRealMutexPrivate::locked() { - int ret = pthread_mutex_trylock(&handle); - - if (ret == EBUSY) { - return TRUE; - } else if (ret) { -#ifdef QT_CHECK_RANGE - tqWarning("Mutex locktest failure: %s", strerror(ret)); -#endif - } else - pthread_mutex_unlock(&handle); - - return FALSE; + return count > 0; } bool TQRealMutexPrivate::trylock() @@ -201,7 +197,7 @@ int TQRealMutexPrivate::type() const int TQRealMutexPrivate::level() { - return locked(); + return count; } |