Index: src/Makefile ================================================================== --- src/Makefile +++ src/Makefile @@ -70,10 +70,11 @@ unicode.m INCLUDES := ${SRCS:.m=.h} \ OFCollection.h \ OFJSONRepresentation.h \ + OFLocking.h \ OFSerialization.h \ OFTLSSocket.h \ ObjFW.h \ asprintf.h \ autorelease.h \ Index: src/OFFile.m ================================================================== --- src/OFFile.m +++ src/OFFile.m @@ -56,19 +56,19 @@ #import "OFDeleteDirectoryFailedException.h" #import "OFDeleteFileFailedException.h" #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" #import "OFLinkFailedException.h" -#import "OFMutexLockFailedException.h" -#import "OFMutexUnlockFailedException.h" +#import "OFLockFailedException.h" #import "OFNotImplementedException.h" #import "OFOpenFileFailedException.h" #import "OFOutOfMemoryException.h" #import "OFReadFailedException.h" #import "OFRenameFileFailedException.h" #import "OFSeekFailedException.h" #import "OFSymlinkFailedException.h" +#import "OFUnlockFailedException.h" #import "OFWriteFailedException.h" #import "autorelease.h" #import "macros.h" @@ -440,12 +440,11 @@ @throw [OFInvalidArgumentException exceptionWithClass: self selector: _cmd]; # ifdef OF_THREADS if (!of_mutex_lock(&mutex)) - @throw [OFMutexLockFailedException exceptionWithClass: self - mutex: nil]; + @throw [OFLockFailedException exceptionWithClass: self]; @try { # endif if (owner != nil) { struct passwd *passwd; @@ -475,13 +474,12 @@ gid = group_->gr_gid; } # ifdef OF_THREADS } @finally { if (!of_mutex_unlock(&mutex)) - @throw [OFMutexUnlockFailedException - exceptionWithClass: self - mutex: nil]; + @throw [OFUnlockFailedException + exceptionWithClass: self]; } # endif if (chown([path cStringWithEncoding: OF_STRING_ENCODING_NATIVE], uid, gid)) ADDED src/OFLocking.h Index: src/OFLocking.h ================================================================== --- src/OFLocking.h +++ src/OFLocking.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011, 2012 + * 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 "OFObject.h" + +/** + * \brief A protocol for locks. + */ +@protocol OFLocking +/** + * \brief Locks the lock. + */ +- (void)lock; + +/** + * \brief Tries to lock the lock. + * + * \return A boolean whether the lock could be locked + */ +- (BOOL)tryLock; + +/** + * \brief Unlocks the lock. + */ +- (void)unlock; +@end Index: src/OFMutex.h ================================================================== --- src/OFMutex.h +++ src/OFMutex.h @@ -13,17 +13,18 @@ * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFObject.h" +#import "OFLocking.h" #import "threading.h" /** * \brief A class for creating mutual exclusions. */ -@interface OFMutex: OFObject +@interface OFMutex: OFObject { of_mutex_t mutex; BOOL initialized; } @@ -31,25 +32,6 @@ * \brief Creates a new mutex. * * \return A new autoreleased mutex. */ + (instancetype)mutex; - -- OF_initWithoutCreatingMutex; - -/** - * \brief Locks the mutex. - */ -- (void)lock; - -/** - * \brief Tries to lock the mutex. - * - * \return A boolean whether the mutex could be acquired - */ -- (BOOL)tryLock; - -/** - * \brief Unlocks the mutex. - */ -- (void)unlock; @end Index: src/OFMutex.m ================================================================== --- src/OFMutex.m +++ src/OFMutex.m @@ -17,13 +17,13 @@ #include "config.h" #import "OFMutex.h" #import "OFInitializationFailedException.h" -#import "OFMutexLockFailedException.h" -#import "OFMutexStillLockedException.h" -#import "OFMutexUnlockFailedException.h" +#import "OFLockFailedException.h" +#import "OFStillLockedException.h" +#import "OFUnlockFailedException.h" @implementation OFMutex + (instancetype)mutex { return [[[self alloc] init] autorelease]; @@ -42,21 +42,15 @@ initialized = YES; return self; } -- OF_initWithoutCreatingMutex -{ - return [super init]; -} - - (void)lock { if (!of_mutex_lock(&mutex)) - @throw [OFMutexLockFailedException - exceptionWithClass: [self class] - mutex: self]; + @throw [OFLockFailedException exceptionWithClass: [self class] + lock: self]; } - (BOOL)tryLock { return of_mutex_trylock(&mutex); @@ -63,22 +57,20 @@ } - (void)unlock { if (!of_mutex_unlock(&mutex)) - @throw [OFMutexUnlockFailedException - exceptionWithClass: [self class] - mutex: self]; + @throw [OFUnlockFailedException exceptionWithClass: [self class] + lock: self]; } - (void)dealloc { if (initialized) if (!of_mutex_free(&mutex)) - @throw [OFMutexStillLockedException + @throw [OFStillLockedException exceptionWithClass: [self class] - mutex: self]; + lock: self]; [super dealloc]; } @end - Index: src/OFRecursiveMutex.h ================================================================== --- src/OFRecursiveMutex.h +++ src/OFRecursiveMutex.h @@ -12,16 +12,27 @@ * 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 "OFMutex.h" +#import "OFObject.h" +#import "OFLocking.h" + +#import "threading.h" /** * \brief A class for creating mutual exclusions which can be entered * recursively. */ -@interface OFRecursiveMutex: OFMutex +@interface OFRecursiveMutex: OFObject { of_rmutex_t rmutex; + BOOL initialized; } + +/** + * \brief Creates a new recursive mutex. + * + * \return A new autoreleased recursive mutex. + */ ++ (instancetype)mutex; @end Index: src/OFRecursiveMutex.m ================================================================== --- src/OFRecursiveMutex.m +++ src/OFRecursiveMutex.m @@ -17,18 +17,23 @@ #include "config.h" #import "OFRecursiveMutex.h" #import "OFInitializationFailedException.h" -#import "OFMutexLockFailedException.h" -#import "OFMutexStillLockedException.h" -#import "OFMutexUnlockFailedException.h" +#import "OFLockFailedException.h" +#import "OFStillLockedException.h" +#import "OFUnlockFailedException.h" @implementation OFRecursiveMutex ++ (instancetype)mutex +{ + return [[[self alloc] init] autorelease]; +} + - init { - self = [super OF_initWithoutCreatingMutex]; + self = [super init]; if (!of_rmutex_new(&rmutex)) { Class c = [self class]; [self release]; @throw [OFInitializationFailedException exceptionWithClass: c]; @@ -40,13 +45,12 @@ } - (void)lock { if (!of_rmutex_lock(&rmutex)) - @throw [OFMutexLockFailedException - exceptionWithClass: [self class] - mutex: self]; + @throw [OFLockFailedException exceptionWithClass: [self class] + lock: self]; } - (BOOL)tryLock { return of_rmutex_trylock(&rmutex); @@ -53,21 +57,20 @@ } - (void)unlock { if (!of_rmutex_unlock(&rmutex)) - @throw [OFMutexUnlockFailedException - exceptionWithClass: [self class] - mutex: self]; + @throw [OFUnlockFailedException exceptionWithClass: [self class] + lock: self]; } - (void)dealloc { if (initialized) if (!of_rmutex_free(&rmutex)) - @throw [OFMutexStillLockedException + @throw [OFStillLockedException exceptionWithClass: [self class] - mutex: self]; + lock: self]; [super dealloc]; } @end Index: src/ObjFW.h ================================================================== --- src/ObjFW.h +++ src/ObjFW.h @@ -102,17 +102,13 @@ #import "OFInvalidFormatException.h" #import "OFInvalidJSONException.h" #import "OFInvalidServerReplyException.h" #import "OFLinkFailedException.h" #import "OFListenFailedException.h" +#import "OFLockFailedException.h" #import "OFMalformedXMLException.h" #import "OFMemoryNotPartOfObjectException.h" -#ifdef OF_THREADS -# import "OFMutexLockFailedException.h" -# import "OFMutexStillLockedException.h" -# import "OFMutexUnlockFailedException.h" -#endif #import "OFNotConnectedException.h" #import "OFNotImplementedException.h" #import "OFOpenFileFailedException.h" #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" @@ -119,18 +115,20 @@ #import "OFReadFailedException.h" #import "OFReadOrWriteFailedException.h" #import "OFRenameFileFailedException.h" #import "OFSeekFailedException.h" #import "OFSetOptionFailedException.h" +#import "OFStillLockedException.h" #import "OFSymlinkFailedException.h" #ifdef OF_THREADS # import "OFThreadJoinFailedException.h" # import "OFThreadStartFailedException.h" # import "OFThreadStillRunningException.h" #endif #import "OFTruncatedDataException.h" #import "OFUnboundNamespaceException.h" +#import "OFUnlockFailedException.h" #import "OFUnsupportedProtocolException.h" #import "OFWriteFailedException.h" #import "macros.h" @@ -140,10 +138,11 @@ #ifdef OF_ATOMIC_OPS # import "atomic.h" #endif +#import "OFLocking.h" #ifdef OF_THREADS # import "threading.h" # import "OFThread.h" # import "OFThreadPool.h" # import "OFTLSKey.h" Index: src/exceptions/Makefile ================================================================== --- src/exceptions/Makefile +++ src/exceptions/Makefile @@ -30,15 +30,13 @@ OFInvalidFormatException.m \ OFInvalidJSONException.m \ OFInvalidServerReplyException.m \ OFLinkFailedException.m \ OFListenFailedException.m \ + OFLockFailedException.m \ OFMalformedXMLException.m \ OFMemoryNotPartOfObjectException.m \ - OFMutexLockFailedException.m \ - OFMutexStillLockedException.m \ - OFMutexUnlockFailedException.m \ OFNotConnectedException.m \ OFNotImplementedException.m \ OFOpenFileFailedException.m \ OFOutOfMemoryException.m \ OFOutOfRangeException.m \ @@ -45,16 +43,18 @@ OFReadFailedException.m \ OFReadOrWriteFailedException.m \ OFRenameFileFailedException.m \ OFSeekFailedException.m \ OFSetOptionFailedException.m \ + OFStillLockedException.m \ OFSymlinkFailedException.m \ OFThreadJoinFailedException.m \ OFThreadStartFailedException.m \ OFThreadStillRunningException.m \ OFTruncatedDataException.m \ OFUnboundNamespaceException.m \ + OFUnlockFailedException.m \ OFUnsupportedProtocolException.m \ OFUnsupportedVersionException.m \ OFWriteFailedException.m INCLUDES = ${SRCS:.m=.h} ADDED src/exceptions/OFLockFailedException.h Index: src/exceptions/OFLockFailedException.h ================================================================== --- src/exceptions/OFLockFailedException.h +++ src/exceptions/OFLockFailedException.h @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011, 2012 + * 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" +#import "OFLocking.h" + +/** + * \brief An exception indicating that locking a lock failed. + */ +@interface OFLockFailedException: OFException +{ + id lock; +} + +#ifdef OF_HAVE_PROPERTIES +@property (readonly, retain, nonatomic) id lock; +#endif + +/** + * \param class_ The class of the object which caused the exception + * \param lock The lock which could not be locked + * \return A new lock failed exception + */ ++ (instancetype)exceptionWithClass: (Class)class_ + lock: (id )lock; + +/** + * Initializes an already allocated lock failed exception. + * + * \param class_ The class of the object which caused the exception + * \param lock The lock which could not be locked + * \return An initialized lock failed exception + */ +- initWithClass: (Class)class_ + lock: (id )lock; + +/** + * \param The lock which could not be locked + */ +- (id )lock; +@end ADDED src/exceptions/OFLockFailedException.m Index: src/exceptions/OFLockFailedException.m ================================================================== --- src/exceptions/OFLockFailedException.m +++ src/exceptions/OFLockFailedException.m @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011, 2012 + * 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 "OFLockFailedException.h" +#import "OFString.h" + +#import "OFNotImplementedException.h" + +#import "macros.h" + +@implementation OFLockFailedException ++ (instancetype)exceptionWithClass: (Class)class_ + lock: (id )lock +{ + return [[[self alloc] initWithClass: class_ + lock: lock] autorelease]; +} + +- initWithClass: (Class)class_ + lock: (id )lock_ +{ + self = [super initWithClass: class_]; + + lock = [lock_ retain]; + + return self; +} + +- (void)dealloc +{ + [lock release]; + + [super dealloc]; +} + +- (OFString*)description +{ + if (description != nil) + return description; + + description = [[OFString alloc] initWithFormat: + @"A lock of type %@ could not be locked in class %@!", + [(id)lock className], inClass]; + + return description; +} + +- (id )lock +{ + OF_GETTER(lock, NO) +} +@end DELETED src/exceptions/OFMutexLockFailedException.h Index: src/exceptions/OFMutexLockFailedException.h ================================================================== --- src/exceptions/OFMutexLockFailedException.h +++ src/exceptions/OFMutexLockFailedException.h @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2008, 2009, 2010, 2011, 2012 - * 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 locking a mutex failed. - */ -@interface OFMutexLockFailedException: OFException -{ - OFMutex *mutex; -} - -#ifdef OF_HAVE_PROPERTIES -@property (readonly, retain, 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 - */ -+ (instancetype)exceptionWithClass: (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 DELETED src/exceptions/OFMutexLockFailedException.m Index: src/exceptions/OFMutexLockFailedException.m ================================================================== --- src/exceptions/OFMutexLockFailedException.m +++ src/exceptions/OFMutexLockFailedException.m @@ -1,73 +0,0 @@ -/* - * Copyright (c) 2008, 2009, 2010, 2011, 2012 - * 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 "OFMutexLockFailedException.h" -#import "OFString.h" -#import "OFMutex.h" - -#import "OFNotImplementedException.h" - -@implementation OFMutexLockFailedException -+ (instancetype)exceptionWithClass: (Class)class_ - mutex: (OFMutex*)mutex -{ - return [[[self alloc] initWithClass: class_ - mutex: mutex] autorelease]; -} - -- initWithClass: (Class)class_ -{ - Class c = [self class]; - [self release]; - @throw [OFNotImplementedException exceptionWithClass: c - selector: _cmd]; -} - -- initWithClass: (Class)class_ - mutex: (OFMutex*)mutex_ -{ - self = [super initWithClass: class_]; - - mutex = [mutex_ retain]; - - return self; -} - -- (void)dealloc -{ - [mutex release]; - - [super dealloc]; -} - -- (OFString*)description -{ - if (description != nil) - return description; - - description = [[OFString alloc] initWithFormat: - @"A mutex of class %@ could not be locked!", inClass]; - - return description; -} - -- (OFMutex*)mutex -{ - OF_GETTER(mutex, NO) -} -@end DELETED src/exceptions/OFMutexStillLockedException.h Index: src/exceptions/OFMutexStillLockedException.h ================================================================== --- src/exceptions/OFMutexStillLockedException.h +++ src/exceptions/OFMutexStillLockedException.h @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2008, 2009, 2010, 2011, 2012 - * 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, retain, 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 - */ -+ (instancetype)exceptionWithClass: (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 DELETED src/exceptions/OFMutexStillLockedException.m Index: src/exceptions/OFMutexStillLockedException.m ================================================================== --- src/exceptions/OFMutexStillLockedException.m +++ src/exceptions/OFMutexStillLockedException.m @@ -1,74 +0,0 @@ -/* - * Copyright (c) 2008, 2009, 2010, 2011, 2012 - * 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 "OFMutex.h" - -#import "OFNotImplementedException.h" - -@implementation OFMutexStillLockedException -+ (instancetype)exceptionWithClass: (Class)class_ - mutex: (OFMutex*)mutex -{ - return [[[self alloc] initWithClass: class_ - mutex: mutex] autorelease]; -} - -- initWithClass: (Class)class_ -{ - Class c = [self class]; - [self release]; - @throw [OFNotImplementedException exceptionWithClass: c - selector: _cmd]; -} - -- initWithClass: (Class)class_ - mutex: (OFMutex*)mutex_ -{ - self = [super initWithClass: class_]; - - mutex = [mutex_ retain]; - - 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 -{ - OF_GETTER(mutex, NO) -} -@end DELETED src/exceptions/OFMutexUnlockFailedException.h Index: src/exceptions/OFMutexUnlockFailedException.h ================================================================== --- src/exceptions/OFMutexUnlockFailedException.h +++ src/exceptions/OFMutexUnlockFailedException.h @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2008, 2009, 2010, 2011, 2012 - * 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 unlocking a mutex failed. - */ -@interface OFMutexUnlockFailedException: OFException -{ - OFMutex *mutex; -} - -#ifdef OF_HAVE_PROPERTIES -@property (readonly, retain, 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 - */ -+ (instancetype)exceptionWithClass: (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 DELETED src/exceptions/OFMutexUnlockFailedException.m Index: src/exceptions/OFMutexUnlockFailedException.m ================================================================== --- src/exceptions/OFMutexUnlockFailedException.m +++ src/exceptions/OFMutexUnlockFailedException.m @@ -1,73 +0,0 @@ -/* - * Copyright (c) 2008, 2009, 2010, 2011, 2012 - * 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 "OFMutexUnlockFailedException.h" -#import "OFString.h" -#import "OFMutex.h" - -#import "OFNotImplementedException.h" - -@implementation OFMutexUnlockFailedException -+ (instancetype)exceptionWithClass: (Class)class_ - mutex: (OFMutex*)mutex -{ - return [[[self alloc] initWithClass: class_ - mutex: mutex] autorelease]; -} - -- initWithClass: (Class)class_ -{ - Class c = [self class]; - [self release]; - @throw [OFNotImplementedException exceptionWithClass: c - selector: _cmd]; -} - -- initWithClass: (Class)class_ - mutex: (OFMutex*)mutex_ -{ - self = [super initWithClass: class_]; - - mutex = [mutex_ retain]; - - return self; -} - -- (void)dealloc -{ - [mutex release]; - - [super dealloc]; -} - -- (OFString*)description -{ - if (description != nil) - return description; - - description = [[OFString alloc] initWithFormat: - @"A mutex of class %@ could not be unlocked!", inClass]; - - return description; -} - -- (OFMutex*)mutex -{ - OF_GETTER(mutex, NO) -} -@end ADDED src/exceptions/OFStillLockedException.h Index: src/exceptions/OFStillLockedException.h ================================================================== --- src/exceptions/OFStillLockedException.h +++ src/exceptions/OFStillLockedException.h @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011, 2012 + * 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" +#import "OFLocking.h" + +/** + * \brief An exception indicating that a lock is still locked. + */ +@interface OFStillLockedException: OFException +{ + id lock; +} + +#ifdef OF_HAVE_PROPERTIES +@property (readonly, retain, nonatomic) id lock; +#endif + +/** + * \param class_ The class of the object which caused the exception + * \param lock The lock which is still locked + * \return A new still locked exception + */ ++ (instancetype)exceptionWithClass: (Class)class_ + lock: (id )lock; + +/** + * Initializes an already allocated still locked exception. + * + * \param class_ The class of the object which caused the exception + * \param lock The lock which is still locked + * \return An initialized still locked exception + */ +- initWithClass: (Class)class_ + lock: (id )lock; + +/** + * \return The lock which is still locked + */ +- (id )lock; +@end ADDED src/exceptions/OFStillLockedException.m Index: src/exceptions/OFStillLockedException.m ================================================================== --- src/exceptions/OFStillLockedException.m +++ src/exceptions/OFStillLockedException.m @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011, 2012 + * 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 "OFStillLockedException.h" +#import "OFString.h" + +#import "OFNotImplementedException.h" + +#import "macros.h" + +@implementation OFStillLockedException ++ (instancetype)exceptionWithClass: (Class)class_ + lock: (id )lock +{ + return [[[self alloc] initWithClass: class_ + lock: lock] autorelease]; +} + +- initWithClass: (Class)class_ + lock: (id )lock_ +{ + self = [super initWithClass: class_]; + + lock = [lock_ retain]; + + return self; +} + +- (void)dealloc +{ + [lock release]; + + [super dealloc]; +} + +- (OFString*)description +{ + if (description != nil) + return description; + + description = [[OFString alloc] initWithFormat: + @"Deallocation of a lock of type %@ was tried in class %@, even " + @"though it was still locked!", [(id)lock className], inClass]; + + return description; +} + +- (id )lock +{ + OF_GETTER(lock, NO) +} +@end ADDED src/exceptions/OFUnlockFailedException.h Index: src/exceptions/OFUnlockFailedException.h ================================================================== --- src/exceptions/OFUnlockFailedException.h +++ src/exceptions/OFUnlockFailedException.h @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011, 2012 + * 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" +#import "OFLocking.h" + +/** + * \brief An exception indicating that unlocking a lock failed. + */ +@interface OFUnlockFailedException: OFException +{ + id lock; +} + +#ifdef OF_HAVE_PROPERTIES +@property (readonly, retain, nonatomic) id lock; +#endif + +/** + * \param class_ The class of the object which caused the exception + * \param lock The lock which could not be unlocked + * \return A new unlock failed exception + */ ++ (instancetype)exceptionWithClass: (Class)class_ + lock: (id )lock; + +/** + * Initializes an already allocated unlock failed exception. + * + * \param class_ The class of the object which caused the exception + * \param lock The lock which could not be unlocked + * \return An initialized unlock failed exception + */ +- initWithClass: (Class)class_ + lock: (id )lock; + +/** + * \return The lock which could not be unlocked + */ +- (id )lock; +@end ADDED src/exceptions/OFUnlockFailedException.m Index: src/exceptions/OFUnlockFailedException.m ================================================================== --- src/exceptions/OFUnlockFailedException.m +++ src/exceptions/OFUnlockFailedException.m @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011, 2012 + * 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 "OFUnlockFailedException.h" +#import "OFString.h" + +#import "OFNotImplementedException.h" + +#import "macros.h" + +@implementation OFUnlockFailedException ++ (instancetype)exceptionWithClass: (Class)class_ + lock: (id )lock +{ + return [[[self alloc] initWithClass: class_ + lock: lock] autorelease]; +} + +- initWithClass: (Class)class_ + lock: (id )lock_ +{ + self = [super initWithClass: class_]; + + lock = [lock_ retain]; + + return self; +} + +- (void)dealloc +{ + [lock release]; + + [super dealloc]; +} + +- (OFString*)description +{ + if (description != nil) + return description; + + description = [[OFString alloc] initWithFormat: + @"A lock of class %@ could not be unlocked in class %@!", + [(id)lock className], inClass]; + + return description; +} + +- (id )lock +{ + OF_GETTER(lock, NO) +} +@end