Differences From Artifact [3c3018edf4]:
- File
src/OFMutex.m
— part of check-in
[0a55edad35]
at
2012-10-26 11:04:41
on branch trunk
— Split OFThread.m into multiple files.
It was time to finally have one file per class. (user: js, size: 1662) [annotate] [blame] [check-ins using]
To Artifact [e9519677f8]:
- File src/OFMutex.m — part of check-in [7c33158c22] at 2012-10-26 11:23:49 on branch trunk — Add OFLocking protocol. (user: js, size: 1574) [annotate] [blame] [check-ins using]
| ︙ | ︙ | |||
15 16 17 18 19 20 21 | */ #include "config.h" #import "OFMutex.h" #import "OFInitializationFailedException.h" | | | | | 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
*/
#include "config.h"
#import "OFMutex.h"
#import "OFInitializationFailedException.h"
#import "OFLockFailedException.h"
#import "OFStillLockedException.h"
#import "OFUnlockFailedException.h"
@implementation OFMutex
+ (instancetype)mutex
{
return [[[self alloc] init] autorelease];
}
|
| ︙ | ︙ | |||
40 41 42 43 44 45 46 | } initialized = YES; return self; } | < < < < < < | | < | | | | < | 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
}
initialized = YES;
return self;
}
- (void)lock
{
if (!of_mutex_lock(&mutex))
@throw [OFLockFailedException exceptionWithClass: [self class]
lock: self];
}
- (BOOL)tryLock
{
return of_mutex_trylock(&mutex);
}
- (void)unlock
{
if (!of_mutex_unlock(&mutex))
@throw [OFUnlockFailedException exceptionWithClass: [self class]
lock: self];
}
- (void)dealloc
{
if (initialized)
if (!of_mutex_free(&mutex))
@throw [OFStillLockedException
exceptionWithClass: [self class]
lock: self];
[super dealloc];
}
@end
|