Created
September 29, 2012 19:03
-
-
Save yfrancis/3804924 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static NSMutableDictionary* resources_ = nil; | |
@implementation GRResource | |
+ (void)initialize | |
{ | |
static dispatch_once_t once; | |
dispatch_once(&once, ^{ | |
resources_ = [NSMutableDictionary new]; | |
}); | |
} | |
+ (GRResource*)_resourceWithName:(NSString*)resourceName | |
{ | |
@synchronized(resources_) { | |
GRResource* r = [resources_ objectForKey:resourceName]; | |
if (r == nil) { | |
r = [[[GRResource alloc] _initWithName:name] autorelease]; | |
[resources_ setObject:r forKey:resourceName]; | |
} | |
} | |
return r; | |
} | |
- (id)_initWithName:(NSString*)name | |
{ | |
self = [super init]; | |
if (self != nil) | |
self.name = name; | |
return self; | |
} | |
+ (void)acquireResources:(NSArray*)resources | |
{ | |
for (NSString* resourceName in resources) | |
[[GRResource _resourceWithName:resourceName] lock]; | |
} | |
+ (void)relinquishResources:(NSArray*)resources | |
{ | |
for (NSString* resourceName in resources) | |
[[GRResource _resourceWithName:resourceName] unlock]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment