Index: ObjFW.xcodeproj/project.pbxproj ================================================================== --- ObjFW.xcodeproj/project.pbxproj +++ ObjFW.xcodeproj/project.pbxproj @@ -200,18 +200,18 @@ 4B55A113133AC24600B58A93 /* OFReadFailedException.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B55A10D133AC24500B58A93 /* OFReadFailedException.m */; }; 4B55A114133AC24600B58A93 /* OFReadOrWriteFailedException.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B55A10E133AC24500B58A93 /* OFReadOrWriteFailedException.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4B55A115133AC24600B58A93 /* OFReadOrWriteFailedException.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B55A10F133AC24500B58A93 /* OFReadOrWriteFailedException.m */; }; 4B55A116133AC24600B58A93 /* OFWriteFailedException.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B55A110133AC24500B58A93 /* OFWriteFailedException.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4B55A117133AC24600B58A93 /* OFWriteFailedException.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B55A111133AC24600B58A93 /* OFWriteFailedException.m */; }; + 4B7FF3B0133CE6DE00000324 /* OFMutexStillLockedException.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B7FF3AE133CE6DE00000324 /* OFMutexStillLockedException.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 4B7FF3B1133CE6DE00000324 /* OFMutexStillLockedException.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B7FF3AF133CE6DE00000324 /* OFMutexStillLockedException.m */; }; 4B8B16FE133A3B84007CD8B3 /* OFHashAlreadyCalculatedException.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B8B16FC133A3B84007CD8B3 /* OFHashAlreadyCalculatedException.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4B8B16FF133A3B84007CD8B3 /* OFHashAlreadyCalculatedException.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B8B16FD133A3B84007CD8B3 /* OFHashAlreadyCalculatedException.m */; }; 4B8B170D133A3C11007CD8B3 /* OFConditionBroadcastFailedException.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B8B1702133A3B8E007CD8B3 /* OFConditionBroadcastFailedException.m */; }; 4B8B170E133A3C11007CD8B3 /* OFConditionSignalFailedException.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B8B1704133A3B8E007CD8B3 /* OFConditionSignalFailedException.m */; }; 4B8B170F133A3C11007CD8B3 /* OFConditionWaitFailedException.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B8B1706133A3B8E007CD8B3 /* OFConditionWaitFailedException.m */; }; 4B8B1710133A3C11007CD8B3 /* OFConditionWaitingException.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B8B1708133A3B8E007CD8B3 /* OFConditionWaitingException.m */; }; - 4B8B1717133A3D04007CD8B3 /* OFMutexLockedException.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B8B1711133A3D04007CD8B3 /* OFMutexLockedException.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 4B8B1718133A3D04007CD8B3 /* OFMutexLockedException.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B8B1712133A3D04007CD8B3 /* OFMutexLockedException.m */; }; 4B8B1719133A3D04007CD8B3 /* OFMutexLockFailedException.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B8B1713133A3D04007CD8B3 /* OFMutexLockFailedException.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4B8B171A133A3D04007CD8B3 /* OFMutexLockFailedException.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B8B1714133A3D04007CD8B3 /* OFMutexLockFailedException.m */; }; 4B8B171B133A3D04007CD8B3 /* OFMutexUnlockFailedException.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B8B1715133A3D04007CD8B3 /* OFMutexUnlockFailedException.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4B8B171C133A3D04007CD8B3 /* OFMutexUnlockFailedException.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B8B1716133A3D04007CD8B3 /* OFMutexUnlockFailedException.m */; }; 4B90B78D133AD46700BD33CB /* OFAlreadyConnectedException.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B90B787133AD46700BD33CB /* OFAlreadyConnectedException.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -477,10 +477,12 @@ 4B6EF67F1235358D0076B512 /* PropertiesTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = PropertiesTests.m; path = tests/PropertiesTests.m; sourceTree = SOURCE_ROOT; }; 4B6EF6801235358D0076B512 /* TestsAppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TestsAppDelegate.h; path = tests/TestsAppDelegate.h; sourceTree = SOURCE_ROOT; }; 4B6EF6811235358D0076B512 /* TestsAppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = TestsAppDelegate.m; path = tests/TestsAppDelegate.m; sourceTree = SOURCE_ROOT; }; 4B6EF684123535B60076B512 /* TestPlugin.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = TestPlugin.m; path = tests/plugin/TestPlugin.m; sourceTree = SOURCE_ROOT; }; 4B6EF685123535C80076B512 /* test.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = test.m; path = tests/objc_sync/test.m; sourceTree = SOURCE_ROOT; }; + 4B7FF3AE133CE6DE00000324 /* OFMutexStillLockedException.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFMutexStillLockedException.h; path = src/exceptions/OFMutexStillLockedException.h; sourceTree = ""; }; + 4B7FF3AF133CE6DE00000324 /* OFMutexStillLockedException.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFMutexStillLockedException.m; path = src/exceptions/OFMutexStillLockedException.m; sourceTree = ""; }; 4B8B16FC133A3B84007CD8B3 /* OFHashAlreadyCalculatedException.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFHashAlreadyCalculatedException.h; path = src/exceptions/OFHashAlreadyCalculatedException.h; sourceTree = ""; }; 4B8B16FD133A3B84007CD8B3 /* OFHashAlreadyCalculatedException.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFHashAlreadyCalculatedException.m; path = src/exceptions/OFHashAlreadyCalculatedException.m; sourceTree = ""; }; 4B8B1701133A3B8E007CD8B3 /* OFConditionBroadcastFailedException.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFConditionBroadcastFailedException.h; path = src/exceptions/OFConditionBroadcastFailedException.h; sourceTree = ""; }; 4B8B1702133A3B8E007CD8B3 /* OFConditionBroadcastFailedException.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFConditionBroadcastFailedException.m; path = src/exceptions/OFConditionBroadcastFailedException.m; sourceTree = ""; }; 4B8B1703133A3B8E007CD8B3 /* OFConditionSignalFailedException.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFConditionSignalFailedException.h; path = src/exceptions/OFConditionSignalFailedException.h; sourceTree = ""; }; @@ -487,12 +489,10 @@ 4B8B1704133A3B8E007CD8B3 /* OFConditionSignalFailedException.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFConditionSignalFailedException.m; path = src/exceptions/OFConditionSignalFailedException.m; sourceTree = ""; }; 4B8B1705133A3B8E007CD8B3 /* OFConditionWaitFailedException.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFConditionWaitFailedException.h; path = src/exceptions/OFConditionWaitFailedException.h; sourceTree = ""; }; 4B8B1706133A3B8E007CD8B3 /* OFConditionWaitFailedException.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFConditionWaitFailedException.m; path = src/exceptions/OFConditionWaitFailedException.m; sourceTree = ""; }; 4B8B1707133A3B8E007CD8B3 /* OFConditionWaitingException.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFConditionWaitingException.h; path = src/exceptions/OFConditionWaitingException.h; sourceTree = ""; }; 4B8B1708133A3B8E007CD8B3 /* OFConditionWaitingException.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFConditionWaitingException.m; path = src/exceptions/OFConditionWaitingException.m; sourceTree = ""; }; - 4B8B1711133A3D04007CD8B3 /* OFMutexLockedException.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFMutexLockedException.h; path = src/exceptions/OFMutexLockedException.h; sourceTree = ""; }; - 4B8B1712133A3D04007CD8B3 /* OFMutexLockedException.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFMutexLockedException.m; path = src/exceptions/OFMutexLockedException.m; sourceTree = ""; }; 4B8B1713133A3D04007CD8B3 /* OFMutexLockFailedException.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFMutexLockFailedException.h; path = src/exceptions/OFMutexLockFailedException.h; sourceTree = ""; }; 4B8B1714133A3D04007CD8B3 /* OFMutexLockFailedException.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFMutexLockFailedException.m; path = src/exceptions/OFMutexLockFailedException.m; sourceTree = ""; }; 4B8B1715133A3D04007CD8B3 /* OFMutexUnlockFailedException.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFMutexUnlockFailedException.h; path = src/exceptions/OFMutexUnlockFailedException.h; sourceTree = ""; }; 4B8B1716133A3D04007CD8B3 /* OFMutexUnlockFailedException.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFMutexUnlockFailedException.m; path = src/exceptions/OFMutexUnlockFailedException.m; sourceTree = ""; }; 4B90B787133AD46700BD33CB /* OFAlreadyConnectedException.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFAlreadyConnectedException.h; path = src/exceptions/OFAlreadyConnectedException.h; sourceTree = ""; }; @@ -661,14 +661,14 @@ 4B90B79D133AD87D00BD33CB /* OFListenFailedException.m */, 4B17FF9F133A3331003E6DCD /* OFMalformedXMLException.h */, 4B17FFA0133A3332003E6DCD /* OFMalformedXMLException.m */, 4B17FF8D133A3034003E6DCD /* OFMemoryNotPartOfObjectException.h */, 4B17FF8E133A3034003E6DCD /* OFMemoryNotPartOfObjectException.m */, - 4B8B1711133A3D04007CD8B3 /* OFMutexLockedException.h */, - 4B8B1712133A3D04007CD8B3 /* OFMutexLockedException.m */, 4B8B1713133A3D04007CD8B3 /* OFMutexLockFailedException.h */, 4B8B1714133A3D04007CD8B3 /* OFMutexLockFailedException.m */, + 4B7FF3AE133CE6DE00000324 /* OFMutexStillLockedException.h */, + 4B7FF3AF133CE6DE00000324 /* OFMutexStillLockedException.m */, 4B8B1715133A3D04007CD8B3 /* OFMutexUnlockFailedException.h */, 4B8B1716133A3D04007CD8B3 /* OFMutexUnlockFailedException.m */, 4B90B789133AD46700BD33CB /* OFNotConnectedException.h */, 4B90B78A133AD46700BD33CB /* OFNotConnectedException.m */, 4B17FF75133A2B18003E6DCD /* OFNotImplementedException.h */, @@ -1001,12 +1001,12 @@ 4B17FFB9133A381D003E6DCD /* OFInvalidServerReplyException.h in Headers */, 4B29BC61133AC9CB0004B236 /* OFLinkFailedException.h in Headers */, 4B90B7A6133AD87D00BD33CB /* OFListenFailedException.h in Headers */, 4B17FFA1133A3335003E6DCD /* OFMalformedXMLException.h in Headers */, 4B17FF8F133A3036003E6DCD /* OFMemoryNotPartOfObjectException.h in Headers */, - 4B8B1717133A3D04007CD8B3 /* OFMutexLockedException.h in Headers */, 4B8B1719133A3D04007CD8B3 /* OFMutexLockFailedException.h in Headers */, + 4B7FF3B0133CE6DE00000324 /* OFMutexStillLockedException.h in Headers */, 4B8B171B133A3D04007CD8B3 /* OFMutexUnlockFailedException.h in Headers */, 4B90B78F133AD46700BD33CB /* OFNotConnectedException.h in Headers */, 4B17FF77133A2B18003E6DCD /* OFNotImplementedException.h in Headers */, 4B29BC5C133AC8540004B236 /* OFRenameFileFailedException.h in Headers */, 4B55A10A133AC05100B58A93 /* OFOpenFileFailedException.h in Headers */, @@ -1247,12 +1247,12 @@ 4B17FFBA133A381D003E6DCD /* OFInvalidServerReplyException.m in Sources */, 4B29BC62133AC9CB0004B236 /* OFLinkFailedException.m in Sources */, 4B90B7A7133AD87D00BD33CB /* OFListenFailedException.m in Sources */, 4B17FFA2133A3335003E6DCD /* OFMalformedXMLException.m in Sources */, 4B17FF90133A3036003E6DCD /* OFMemoryNotPartOfObjectException.m in Sources */, - 4B8B1718133A3D04007CD8B3 /* OFMutexLockedException.m in Sources */, 4B8B171A133A3D04007CD8B3 /* OFMutexLockFailedException.m in Sources */, + 4B7FF3B1133CE6DE00000324 /* OFMutexStillLockedException.m in Sources */, 4B8B171C133A3D04007CD8B3 /* OFMutexUnlockFailedException.m in Sources */, 4B90B790133AD46700BD33CB /* OFNotConnectedException.m in Sources */, 4B17FF78133A2B18003E6DCD /* OFNotImplementedException.m in Sources */, 4B55A10B133AC05100B58A93 /* OFOpenFileFailedException.m in Sources */, 4B17FF84133A2DFB003E6DCD /* OFOutOfMemoryException.m in Sources */, Index: src/OFThread.m ================================================================== --- src/OFThread.m +++ src/OFThread.m @@ -32,12 +32,12 @@ #import "OFConditionSignalFailedException.h" #import "OFConditionWaitFailedException.h" #import "OFConditionWaitingException.h" #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" -#import "OFMutexLockedException.h" #import "OFMutexLockFailedException.h" +#import "OFMutexStillLockedException.h" #import "OFMutexUnlockFailedException.h" #import "OFNotImplementedException.h" #import "OFOutOfRangeException.h" #import "OFThreadJoinFailedException.h" #import "OFThreadStartFailedException.h" @@ -383,11 +383,12 @@ } - (void)lock { if (!of_mutex_lock(&mutex)) - @throw [OFMutexLockFailedException newWithClass: isa]; + @throw [OFMutexLockFailedException newWithClass: isa + mutex: self]; } - (BOOL)tryLock { return of_mutex_trylock(&mutex); @@ -394,18 +395,20 @@ } - (void)unlock { if (!of_mutex_unlock(&mutex)) - @throw [OFMutexUnlockFailedException newWithClass: isa]; + @throw [OFMutexUnlockFailedException newWithClass: isa + mutex: self]; } - (void)dealloc { if (initialized) if (!of_mutex_free(&mutex)) - @throw [OFMutexLockedException newWithClass: isa]; + @throw [OFMutexStillLockedException newWithClass: isa + mutex: self]; [super dealloc]; } @end Index: src/ObjFW.h ================================================================== --- src/ObjFW.h +++ src/ObjFW.h @@ -81,12 +81,12 @@ #import "OFInvalidServerReplyException.h" #import "OFLinkFailedException.h" #import "OFListenFailedException.h" #import "OFMalformedXMLException.h" #import "OFMemoryNotPartOfObjectException.h" -#import "OFMutexLockedException.h" #import "OFMutexLockFailedException.h" +#import "OFMutexStillLockedException.h" #import "OFMutexUnlockFailedException.h" #import "OFNotConnectedException.h" #import "OFNotImplementedException.h" #import "OFOpenFileFailedException.h" #import "OFOutOfMemoryException.h" Index: src/exceptions/Makefile ================================================================== --- src/exceptions/Makefile +++ src/exceptions/Makefile @@ -32,11 +32,11 @@ OFLinkFailedException.m \ OFListenFailedException.m \ OFMalformedXMLException.m \ OFMemoryNotPartOfObjectException.m \ OFMutexLockFailedException.m \ - OFMutexLockedException.m \ + OFMutexStillLockedException.m \ OFMutexUnlockFailedException.m \ OFNotConnectedException.m \ OFNotImplementedException.m \ OFOpenFileFailedException.m \ OFOutOfMemoryException.m \ Index: src/exceptions/OFMutexLockFailedException.h ================================================================== --- src/exceptions/OFMutexLockFailedException.h +++ src/exceptions/OFMutexLockFailedException.h @@ -14,10 +14,42 @@ * file. */ #import "OFException.h" +@class OFMutex; + /** * \brief An exception indicating that locking a mutex failed. */ @interface OFMutexLockFailedException: OFException +{ + OFMutex *mutex; +} + +#ifdef OF_HAVE_PROPERTIES +@property (readonly, nonatomic) OFMutex *mutex; +#endif + +/** + * \param class_ The class of the object which caused the exception + * \param mutex The mutex which is could not be locked + * \return A new mutex lock failed exception + */ ++ newWithClass: (Class)class_ + mutex: (OFMutex*)mutex; + +/** + * Initializes an already allocated mutex lock failed exception. + * + * \param class_ The class of the object which caused the exception + * \param mutex The mutex which is could not be locked + * \return An initialized mutex lock failed exception + */ +- initWithClass: (Class)class_ + mutex: (OFMutex*)mutex; + +/** + * \param The mutex which is could not be locked + */ +- (OFMutex*)mutex; @end Index: src/exceptions/OFMutexLockFailedException.m ================================================================== --- src/exceptions/OFMutexLockFailedException.m +++ src/exceptions/OFMutexLockFailedException.m @@ -16,12 +16,51 @@ #include "config.h" #import "OFMutexLockFailedException.h" #import "OFString.h" + +#import "OFNotImplementedException.h" @implementation OFMutexLockFailedException ++ newWithClass: (Class)class_ + mutex: (OFMutex*)mutex +{ + return [[self alloc] initWithClass: class_ + mutex: mutex]; +} + +- initWithClass: (Class)class_ +{ + Class c = isa; + [self release]; + @throw [OFNotImplementedException newWithClass: c + selector: _cmd]; +} + +- initWithClass: (Class)class_ + mutex: (OFMutex*)mutex_ +{ + self = [super initWithClass: class_]; + + @try { + mutex = [mutex_ retain]; + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} + +- (void)dealloc +{ + [mutex release]; + + [super dealloc]; +} + - (OFString*)description { if (description != nil) return description; @@ -28,6 +67,11 @@ description = [[OFString alloc] initWithFormat: @"A mutex of class %@ could not be locked!", inClass]; return description; } + +- (OFMutex*)mutex +{ + return mutex; +} @end DELETED src/exceptions/OFMutexLockedException.h Index: src/exceptions/OFMutexLockedException.h ================================================================== --- src/exceptions/OFMutexLockedException.h +++ src/exceptions/OFMutexLockedException.h @@ -1,23 +0,0 @@ -/* - * Copyright (c) 2008, 2009, 2010, 2011 - * Jonathan Schleifer - * - * All rights reserved. - * - * This file is part of ObjFW. It may be distributed under the terms of the - * Q Public License 1.0, which can be found in the file LICENSE.QPL included in - * the packaging of this file. - * - * Alternatively, it may be distributed under the terms of the GNU General - * Public License, either version 2 or 3, which can be found in the file - * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this - * file. - */ - -#import "OFException.h" - -/** - * \brief An exception indicating that a mutex is still locked. - */ -@interface OFMutexLockedException: OFException -@end DELETED src/exceptions/OFMutexLockedException.m Index: src/exceptions/OFMutexLockedException.m ================================================================== --- src/exceptions/OFMutexLockedException.m +++ src/exceptions/OFMutexLockedException.m @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2008, 2009, 2010, 2011 - * Jonathan Schleifer - * - * All rights reserved. - * - * This file is part of ObjFW. It may be distributed under the terms of the - * Q Public License 1.0, which can be found in the file LICENSE.QPL included in - * the packaging of this file. - * - * Alternatively, it may be distributed under the terms of the GNU General - * Public License, either version 2 or 3, which can be found in the file - * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this - * file. - */ - -#include "config.h" - -#import "OFMutexLockedException.h" -#import "OFString.h" - -@implementation OFMutexLockedException -- (OFString*)description -{ - if (description != nil) - return description; - - description = [[OFString alloc] initWithFormat: - @"Deallocation of a mutex of type %@ was tried, even though it " - @"was still locked!", inClass]; - - return description; -} -@end ADDED src/exceptions/OFMutexStillLockedException.h Index: src/exceptions/OFMutexStillLockedException.h ================================================================== --- src/exceptions/OFMutexStillLockedException.h +++ src/exceptions/OFMutexStillLockedException.h @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011 + * Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#import "OFException.h" + +@class OFMutex; + +/** + * \brief An exception indicating that a mutex is still locked. + */ +@interface OFMutexStillLockedException: OFException +{ + OFMutex *mutex; +} + +#ifdef OF_HAVE_PROPERTIES +@property (readonly, nonatomic) OFMutex *mutex; +#endif + +/** + * \param class_ The class of the object which caused the exception + * \param mutex The mutex which is still locked + * \return A new mutex still locked exception + */ ++ newWithClass: (Class)class_ + mutex: (OFMutex*)mutex; + +/** + * Initializes an already allocated mutex still locked exception. + * + * \param class_ The class of the object which caused the exception + * \param mutex The mutex which is still locked + * \return An initialized mutex still locked exception + */ +- initWithClass: (Class)class_ + mutex: (OFMutex*)mutex; + +/** + * \return The mutex which is still locked + */ +- (OFMutex*)mutex; +@end ADDED src/exceptions/OFMutexStillLockedException.m Index: src/exceptions/OFMutexStillLockedException.m ================================================================== --- src/exceptions/OFMutexStillLockedException.m +++ src/exceptions/OFMutexStillLockedException.m @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011 + * Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#include "config.h" + +#import "OFMutexStillLockedException.h" +#import "OFString.h" + +#import "OFNotImplementedException.h" + +@implementation OFMutexStillLockedException ++ newWithClass: (Class)class_ + mutex: (OFMutex*)mutex +{ + return [[self alloc] initWithClass: class_ + mutex: mutex]; +} + +- initWithClass: (Class)class_ +{ + Class c = isa; + [self release]; + @throw [OFNotImplementedException newWithClass: c + selector: _cmd]; +} + +- initWithClass: (Class)class_ + mutex: (OFMutex*)mutex_ +{ + self = [super initWithClass: class_]; + + @try { + mutex = [mutex_ retain]; + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} + +- (void)dealloc +{ + [mutex release]; + + [super dealloc]; +} + +- (OFString*)description +{ + if (description != nil) + return description; + + description = [[OFString alloc] initWithFormat: + @"Deallocation of a mutex of type %@ was tried, even though it " + @"was still locked!", inClass]; + + return description; +} + +- (OFMutex*)mutex +{ + return mutex; +} +@end Index: src/exceptions/OFMutexUnlockFailedException.h ================================================================== --- src/exceptions/OFMutexUnlockFailedException.h +++ src/exceptions/OFMutexUnlockFailedException.h @@ -14,10 +14,42 @@ * file. */ #import "OFException.h" +@class OFMutex; + /** * \brief An exception indicating that unlocking a mutex failed. */ @interface OFMutexUnlockFailedException: OFException +{ + OFMutex *mutex; +} + +#ifdef OF_HAVE_PROPERTIES +@property (readonly, nonatomic) OFMutex *mutex; +#endif + +/** + * \param class_ The class of the object which caused the exception + * \param mutex The mutex which could not be unlocked + * \return A new mutex unlock failed exception + */ ++ newWithClass: (Class)class_ + mutex: (OFMutex*)mutex; + +/** + * Initializes an already allocated mutex unlock failed exception. + * + * \param class_ The class of the object which caused the exception + * \param mutex The mutex which could not be unlocked + * \return An initialized mutex unlock failed exception + */ +- initWithClass: (Class)class_ + mutex: (OFMutex*)mutex; + +/** + * \return The mutex which could not be unlocked + */ +- (OFMutex*)mutex; @end Index: src/exceptions/OFMutexUnlockFailedException.m ================================================================== --- src/exceptions/OFMutexUnlockFailedException.m +++ src/exceptions/OFMutexUnlockFailedException.m @@ -16,12 +16,51 @@ #include "config.h" #import "OFMutexUnlockFailedException.h" #import "OFString.h" + +#import "OFNotImplementedException.h" @implementation OFMutexUnlockFailedException ++ newWithClass: (Class)class_ + mutex: (OFMutex*)mutex +{ + return [[self alloc] initWithClass: class_ + mutex: mutex]; +} + +- initWithClass: (Class)class_ +{ + Class c = isa; + [self release]; + @throw [OFNotImplementedException newWithClass: c + selector: _cmd]; +} + +- initWithClass: (Class)class_ + mutex: (OFMutex*)mutex_ +{ + self = [super initWithClass: class_]; + + @try { + mutex = [mutex_ retain]; + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} + +- (void)dealloc +{ + [mutex release]; + + [super dealloc]; +} + - (OFString*)description { if (description != nil) return description; @@ -28,6 +67,11 @@ description = [[OFString alloc] initWithFormat: @"A mutex of class %@ could not be unlocked!", inClass]; return description; } + +- (OFMutex*)mutex +{ + return mutex; +} @end