Index: src/OFLocking.h ================================================================== --- src/OFLocking.h +++ src/OFLocking.h @@ -18,10 +18,14 @@ /*! * @brief A protocol for locks. */ @protocol OFLocking +#ifdef OF_HAVE_PROPERTIES +@property (copy) OFString *name; +#endif + /*! * @brief Locks the lock. */ - (void)lock; @@ -34,6 +38,20 @@ /*! * @brief Unlocks the lock. */ - (void)unlock; + +/*! + * @brief Sets a name for the lock. + * + * @param name The name for the lock + */ +- (void)setName: (OFString*)name; + +/*! + * @brief Returns the name for the lock. + * + * @return The name for the lock + */ +- (OFString*)name; @end Index: src/OFMutex.h ================================================================== --- src/OFMutex.h +++ src/OFMutex.h @@ -24,14 +24,15 @@ */ @interface OFMutex: OFObject { of_mutex_t mutex; BOOL initialized; + OFString *name; } /*! * @brief Creates a new mutex. * * @return A new autoreleased mutex. */ + (instancetype)mutex; @end Index: src/OFMutex.m ================================================================== --- src/OFMutex.m +++ src/OFMutex.m @@ -15,15 +15,18 @@ */ #include "config.h" #import "OFMutex.h" +#import "OFString.h" #import "OFInitializationFailedException.h" #import "OFLockFailedException.h" #import "OFStillLockedException.h" #import "OFUnlockFailedException.h" + +#import "macros.h" @implementation OFMutex + (instancetype)mutex { return [[[self alloc] init] autorelease]; @@ -60,17 +63,37 @@ { if (!of_mutex_unlock(&mutex)) @throw [OFUnlockFailedException exceptionWithClass: [self class] lock: self]; } + +- (void)setName: (OFString*)name_ +{ + OF_SETTER(name, name_, YES, YES) +} + +- (OFString*)name +{ + OF_GETTER(name, YES) +} + +- (OFString*)description +{ + if (name == nil) + return [super description]; + + return [OFString stringWithFormat: @"<%@: %@>", [self className], name]; +} - (void)dealloc { if (initialized) if (!of_mutex_free(&mutex)) @throw [OFStillLockedException exceptionWithClass: [self class] lock: self]; + + [name release]; [super dealloc]; } @end Index: src/OFRecursiveMutex.h ================================================================== --- src/OFRecursiveMutex.h +++ src/OFRecursiveMutex.h @@ -25,14 +25,15 @@ */ @interface OFRecursiveMutex: OFObject { of_rmutex_t rmutex; BOOL initialized; + OFString *name; } /*! * @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 @@ -15,15 +15,18 @@ */ #include "config.h" #import "OFRecursiveMutex.h" +#import "OFString.h" #import "OFInitializationFailedException.h" #import "OFLockFailedException.h" #import "OFStillLockedException.h" #import "OFUnlockFailedException.h" + +#import "macros.h" @implementation OFRecursiveMutex + (instancetype)mutex { return [[[self alloc] init] autorelease]; @@ -60,17 +63,37 @@ { if (!of_rmutex_unlock(&rmutex)) @throw [OFUnlockFailedException exceptionWithClass: [self class] lock: self]; } + +- (void)setName: (OFString*)name_ +{ + OF_SETTER(name, name_, YES, YES) +} + +- (OFString*)name +{ + OF_GETTER(name, YES) +} + +- (OFString*)description +{ + if (name == nil) + return [super description]; + + return [OFString stringWithFormat: @"<%@: %@>", [self className], name]; +} - (void)dealloc { if (initialized) if (!of_rmutex_free(&rmutex)) @throw [OFStillLockedException exceptionWithClass: [self class] lock: self]; + + [name release]; [super dealloc]; } @end