Differences From Artifact [ef20679bce]:
- File
src/OFRecursiveMutex.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: 1585) [annotate] [blame] [check-ins using]
To Artifact [2706783ddc]:
- File src/OFRecursiveMutex.m — part of check-in [7c33158c22] at 2012-10-26 11:23:49 on branch trunk — Add OFLocking protocol. (user: js, size: 1602) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
15 16 17 18 19 20 21 | */ #include "config.h" #import "OFRecursiveMutex.h" #import "OFInitializationFailedException.h" | | | | > > > > > | < | | < | | | | | 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 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 | */ #include "config.h" #import "OFRecursiveMutex.h" #import "OFInitializationFailedException.h" #import "OFLockFailedException.h" #import "OFStillLockedException.h" #import "OFUnlockFailedException.h" @implementation OFRecursiveMutex + (instancetype)mutex { return [[[self alloc] init] autorelease]; } - init { self = [super init]; if (!of_rmutex_new(&rmutex)) { Class c = [self class]; [self release]; @throw [OFInitializationFailedException exceptionWithClass: c]; } initialized = YES; return self; } - (void)lock { if (!of_rmutex_lock(&rmutex)) @throw [OFLockFailedException exceptionWithClass: [self class] lock: self]; } - (BOOL)tryLock { return of_rmutex_trylock(&rmutex); } - (void)unlock { if (!of_rmutex_unlock(&rmutex)) @throw [OFUnlockFailedException exceptionWithClass: [self class] lock: self]; } - (void)dealloc { if (initialized) if (!of_rmutex_free(&rmutex)) @throw [OFStillLockedException exceptionWithClass: [self class] lock: self]; [super dealloc]; } @end |