Skip to content

Commit

Permalink
Mutex lock for static variables
Browse files Browse the repository at this point in the history
  • Loading branch information
viktorasl committed Jan 6, 2016
1 parent 631f22d commit bed0efa
Showing 1 changed file with 36 additions and 31 deletions.
67 changes: 36 additions & 31 deletions Realm+JSON/RLMObject+JSON.m
Original file line number Diff line number Diff line change
Expand Up @@ -294,19 +294,20 @@ + (NSDictionary *)mc_inboundMapping {
dispatch_once(&onceToken, ^{
mappingForClassName = [NSMutableDictionary dictionary];
});

NSDictionary *mapping = mappingForClassName[[self className]];
if (!mapping) {
SEL selector = NSSelectorFromString(@"JSONInboundMappingDictionary");
if ([self respondsToSelector:selector]) {
mapping = MCValueFromInvocation(self, selector);
}
else {
mapping = [self mc_defaultInboundMapping];
}
mappingForClassName[[self className]] = mapping;
}
return mapping;
@synchronized(mappingForClassName) {
NSDictionary *mapping = mappingForClassName[[self className]];
if (!mapping) {
SEL selector = NSSelectorFromString(@"JSONInboundMappingDictionary");
if ([self respondsToSelector:selector]) {
mapping = MCValueFromInvocation(self, selector);
}
else {
mapping = [self mc_defaultInboundMapping];
}
mappingForClassName[[self className]] = mapping;
}
return mapping;
}
}

+ (NSDictionary *)mc_outboundMapping {
Expand All @@ -316,18 +317,20 @@ + (NSDictionary *)mc_outboundMapping {
mappingForClassName = [NSMutableDictionary dictionary];
});

NSDictionary *mapping = mappingForClassName[[self className]];
if (!mapping) {
SEL selector = NSSelectorFromString(@"JSONOutboundMappingDictionary");
if ([self respondsToSelector:selector]) {
mapping = MCValueFromInvocation(self, selector);
}
else {
mapping = [self mc_defaultOutboundMapping];
}
mappingForClassName[[self className]] = mapping;
}
return mapping;
@synchronized(mappingForClassName) {
NSDictionary *mapping = mappingForClassName[[self className]];
if (!mapping) {
SEL selector = NSSelectorFromString(@"JSONOutboundMappingDictionary");
if ([self respondsToSelector:selector]) {
mapping = MCValueFromInvocation(self, selector);
}
else {
mapping = [self mc_defaultOutboundMapping];
}
mappingForClassName[[self className]] = mapping;
}
return mapping;
}
}

+ (RLMProperty *)mc_propertyForPropertyKey:(NSString *)key {
Expand All @@ -349,12 +352,14 @@ + (Class)mc_classForPropertyKey:(NSString *)key {
set = [NSCharacterSet characterSetWithCharactersInString:@"\"<"];
});

NSString *string;
NSScanner *scanner = [NSScanner scannerWithString:attributes];
scanner.charactersToBeSkipped = set;
[scanner scanUpToCharactersFromSet:set intoString:NULL];
[scanner scanUpToCharactersFromSet:set intoString:&string];
return NSClassFromString(string);
@synchronized(set) {
NSString *string;
NSScanner *scanner = [NSScanner scannerWithString:attributes];
scanner.charactersToBeSkipped = set;
[scanner scanUpToCharactersFromSet:set intoString:NULL];
[scanner scanUpToCharactersFromSet:set intoString:&string];
return NSClassFromString(string);
}
}
return nil;
}
Expand Down

0 comments on commit bed0efa

Please sign in to comment.