@@ -14,10 +14,12 @@ * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" + +#include #import "OFMutex.h" #import "OFString.h" #import "OFInitializationFailedException.h" @@ -48,34 +50,48 @@ return self; } - (void)dealloc { - if (_initialized) - if (!of_mutex_free(&_mutex)) + if (_initialized) { + if (!of_mutex_free(&_mutex)) { + OF_ENSURE(errno == EBUSY); + @throw [OFStillLockedException exceptionWithLock: self]; + } + } [_name release]; [super dealloc]; } - (void)lock { if (!of_mutex_lock(&_mutex)) - @throw [OFLockFailedException exceptionWithLock: self]; + @throw [OFLockFailedException exceptionWithLock: self + errNo: errno]; } - (bool)tryLock { - return of_mutex_trylock(&_mutex); + if (!of_mutex_trylock(&_mutex)) { + if (errno == EBUSY) + return false; + else + @throw [OFLockFailedException exceptionWithLock: self + errNo: errno]; + } + + return true; } - (void)unlock { if (!of_mutex_unlock(&_mutex)) - @throw [OFUnlockFailedException exceptionWithLock: self]; + @throw [OFUnlockFailedException exceptionWithLock: self + errNo: errno]; } - (OFString *)description { if (_name == nil)