Locking a NULL pointer using ScopedLock is a noop.

This commit is contained in:
Jonas 'Sortie' Termansen 2013-02-16 16:17:12 +01:00
parent bb284d9421
commit fd6098a3a2
1 changed files with 6 additions and 4 deletions

View File

@ -61,12 +61,14 @@ public:
ScopedLock(kthread_mutex_t* mutex)
{
this->mutex = mutex;
kthread_mutex_lock(mutex);
if ( mutex )
kthread_mutex_lock(mutex);
}
~ScopedLock()
{
kthread_mutex_unlock(mutex);
if ( mutex )
kthread_mutex_unlock(mutex);
}
private:
@ -80,12 +82,12 @@ public:
ScopedLockSignal(kthread_mutex_t* mutex)
{
this->mutex = mutex;
this->acquired = kthread_mutex_lock_signal(mutex);
this->acquired = !mutex || kthread_mutex_lock_signal(mutex);
}
~ScopedLockSignal()
{
if ( acquired )
if ( mutex && acquired )
kthread_mutex_unlock(mutex);
}