Skip to content

Commit

Permalink
Added synchronization guards for the managed object context
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephen Streza committed Feb 14, 2009
1 parent 0a40844 commit 0e16b7f
Show file tree
Hide file tree
Showing 12 changed files with 3,773 additions and 8,823 deletions.
6 changes: 5 additions & 1 deletion Classes/Plugins/Organization/TCCalendarPlugin/TCCalendar.m
Expand Up @@ -81,7 +81,11 @@ +(TCCalendar *)calendarWithStoreCalendar:(CalCalendar *)calendar{
[sortDescriptor release];

NSError *error = nil;
NSArray *array = [moc executeFetchRequest:request error:&error];
NSArray *array = nil;
@synchronized(moc){
array =[moc executeFetchRequest:request error:&error];
}

if (array == nil || array.count == 0)
{
// NSLog(@"Creating show on %@ thread",([NSThread isMainThread] ? @"main" : @"NOT MAIN"));
Expand Down
Expand Up @@ -86,7 +86,10 @@ +(TCCalendarEvent *)calendarEventWithStoreCalendarEvent:(CalEvent *)calendarEven
[sortDescriptor release];

NSError *error = nil;
NSArray *array = [moc executeFetchRequest:request error:&error];
NSArray *array = nil;
@synchronized(moc){
array =[moc executeFetchRequest:request error:&error];
}
if (array == nil || array.count == 0)
{
// NSLog(@"Creating show on %@ thread",([NSThread isMainThread] ? @"main" : @"NOT MAIN"));
Expand Down
2 changes: 1 addition & 1 deletion Classes/TCCore/Core Types/TCExtendableObject.m
Expand Up @@ -39,7 +39,7 @@ - (void)setValue:(id)value forUndefinedKey:(NSString *)key{
}

- (id)valueForUndefinedKey:(NSString *)key{
NSLog(@"-[TCExtendableObject valueForUndefinedKey: %@],key");
NSLog(@"-[TCExtendableObject valueForUndefinedKey: %@]",key);
return [props valueForKey:key];
}

Expand Down
5 changes: 4 additions & 1 deletion Classes/TCCore/Core Types/TCMovieVideo.m
Expand Up @@ -57,7 +57,10 @@ +(NSArray *)arrayForPredicate:(NSPredicate *)predicate sortDescriptors:(NSArray
[request setSortDescriptors:sortDescriptors];

NSError *error = nil;
NSArray *array = [moc executeFetchRequest:request error:&error];
NSArray *array = nil;
@synchronized(moc){
array = [moc executeFetchRequest:request error:&error];
}
if(error){
*errPtr = error;
return nil;
Expand Down
5 changes: 4 additions & 1 deletion Classes/TCCore/Core Types/TCTVEpisode.m
Expand Up @@ -224,7 +224,10 @@ +(NSArray *)arrayForPredicate:(NSPredicate *)predicate sortDescriptors:(NSArray
[request setSortDescriptors:sortDescriptors];

NSError *error = nil;
NSArray *array = [moc executeFetchRequest:request error:&error];
NSArray *array = nil;
@synchronized(moc){
array = [moc executeFetchRequest:request error:&error];
}
if(error){
*errPtr = error;
return nil;
Expand Down
5 changes: 4 additions & 1 deletion Classes/TCCore/Core Types/TCTVShow.m
Expand Up @@ -136,7 +136,10 @@ +(NSArray *)arrayForPredicate:(NSPredicate *)predicate sortDescriptors:(NSArray
[request setSortDescriptors:sortDescriptors];

NSError *error = nil;
NSArray *array = [moc executeFetchRequest:request error:&error];
NSArray *array = nil;
@synchronized(moc){
array =[moc executeFetchRequest:request error:&error];
}
if(error){
*errPtr = error;
return nil;
Expand Down
5 changes: 4 additions & 1 deletion Classes/TCCore/Core Types/TCVideo.m
Expand Up @@ -44,7 +44,10 @@ +(NSArray *)videosForPredicate:(NSPredicate *)predicate withSortDescriptors:(NSA

[request setSortDescriptors:sortDescriptors];

NSArray *items = [moc executeFetchRequest:request error:nil];
NSArray *items = nil;
@synchronized(moc){
items = [moc executeFetchRequest:request error:nil];
}
return items;
}

Expand Down
10 changes: 8 additions & 2 deletions Classes/TCCore/Core Types/TCVideoFile.m
Expand Up @@ -47,7 +47,10 @@ +(TCVideoFile *)videoFileForPath:(NSString *)path{
[sortDescriptor release];

NSError *error = nil;
NSArray *array = [moc executeFetchRequest:request error:&error];
NSArray *array = nil;
@synchronized(moc){
array =[moc executeFetchRequest:request error:&error];
}
if (array == nil || array.count == 0)
{
TCVideoFile *newVideoFile = [NSEntityDescription insertNewObjectForEntityForName:@"VideoFile"
Expand Down Expand Up @@ -78,7 +81,10 @@ +(NSArray *)allFilesWithoutVideos{
[sortDescriptor release];

NSError *error = nil;
NSArray *array = [moc executeFetchRequest:request error:&error];
NSArray *array = nil;
@synchronized(moc){
array =[moc executeFetchRequest:request error:&error];
}
return array;
}

Expand Down

0 comments on commit 0e16b7f

Please sign in to comment.