Removed referencing of mutexes and semaphores while locked or locking.

It is unsafe without the global mutex and was hiding genuine bugs like deleting a locked Mutex.


git-svn-id: http://yate.null.ro/svn/yate/trunk@3805 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
paulc 2010-11-11 08:29:35 +00:00
parent 60f6ce8f69
commit 2c1458b67a
1 changed files with 5 additions and 12 deletions

View File

@ -252,7 +252,6 @@ bool MutexPrivate::lock(long maxwait)
}
if (s_safety)
GlobalMutex::lock();
ref();
Thread* thr = Thread::current();
if (thr)
thr->m_locking = true;
@ -317,8 +316,6 @@ bool MutexPrivate::lock(long maxwait)
else
m_owner = 0;
}
else
deref();
if (s_safety)
GlobalMutex::unlock();
if (warn && !rval)
@ -359,7 +356,6 @@ bool MutexPrivate::unlock()
#else
::pthread_mutex_unlock(&m_mutex);
#endif
deref();
ok = true;
}
else
@ -410,7 +406,6 @@ bool SemaphorePrivate::lock(long maxwait)
}
if (s_safety)
GlobalMutex::lock();
ref();
Thread* thr = Thread::current();
if (thr)
thr->m_locking = true;
@ -472,7 +467,6 @@ bool SemaphorePrivate::lock(long maxwait)
}
if (thr)
thr->m_locking = false;
deref();
if (s_safety)
GlobalMutex::unlock();
if (warn && !rval)
@ -483,10 +477,9 @@ bool SemaphorePrivate::lock(long maxwait)
bool SemaphorePrivate::unlock()
{
if (s_safety)
GlobalMutex::lock();
ref();
if (!s_unsafe) {
if (s_safety)
GlobalMutex::lock();
#ifdef _WINDOWS
::ReleaseSemaphore(m_semaphore,1,NULL);
#else
@ -494,10 +487,9 @@ bool SemaphorePrivate::unlock()
if (!::sem_getvalue(&m_semaphore,&val) && (val < (int)m_maxcount))
::sem_post(&m_semaphore);
#endif
if (s_safety)
GlobalMutex::unlock();
}
deref();
if (s_safety)
GlobalMutex::unlock();
return true;
}
@ -544,6 +536,7 @@ unsigned long Lockable::wait()
return s_maxwait;
}
Mutex::Mutex(bool recursive, const char* name)
: m_private(0)
{