Skip to content

Commit

Permalink
Merge pull request #3749 from mstepanov/timob-10280-30x
Browse files Browse the repository at this point in the history
(3_0_X)[TIMOB-10280] cleanup dispatch_async calls to prevent possibility of reordered actions
  • Loading branch information
vishalduggal committed Jan 21, 2013
2 parents e9b9750 + 7c476f0 commit a79ca0f
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 36 deletions.
4 changes: 2 additions & 2 deletions iphone/Classes/LauncherView.m
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,9 @@ - (void)layoutButtons
- (void)recreateButtons
{
if (![NSThread isMainThread]) {
dispatch_async(dispatch_get_main_queue(), ^{
TiThreadPerformOnMainThread( ^{
[self recreateButtons];
});
}, NO);
return;
}

Expand Down
16 changes: 8 additions & 8 deletions iphone/Classes/TiMediaSoundProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ -(void)_destroy
-(void)play:(id)args
{
[self rememberSelf];
dispatch_async(dispatch_get_main_queue(), ^{
TiThreadPerformOnMainThread(^{
// indicate we're going to start playback
if (![[TiMediaAudioSession sharedSession] canPlayback]) {
[self throwException:@"Improper audio session mode for playback"
Expand All @@ -86,12 +86,12 @@ -(void)play:(id)args
}
[[self player] play];
paused = NO;
});
}, NO);
}

-(void)stop:(id)args
{
dispatch_async(dispatch_get_main_queue(), ^{
TiThreadPerformOnMainThread(^{
if (player != nil) {
if ([player isPlaying] || paused) {
[player stop];
Expand All @@ -101,24 +101,24 @@ -(void)stop:(id)args
}
resumeTime = 0;
paused = NO;
});
}, NO);
}

-(void)pause:(id)args
{
dispatch_async(dispatch_get_main_queue(), ^{
TiThreadPerformOnMainThread(^{
if (player != nil) {
if ([player isPlaying]) {
[player pause];
paused = YES;
}
}
});
}, NO);
}

-(void)reset:(id)args
{
dispatch_async(dispatch_get_main_queue(), ^{
TiThreadPerformOnMainThread(^{
if (player != nil) {
if (!([player isPlaying] || paused)) {
[[TiMediaAudioSession sharedSession] startAudioSession];
Expand All @@ -130,7 +130,7 @@ -(void)reset:(id)args
}
resumeTime = 0;
paused = NO;
});
}, NO);
}

-(void)release:(id)args
Expand Down
4 changes: 2 additions & 2 deletions iphone/Classes/TiMediaVideoPlayerProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -343,9 +343,9 @@ -(NSNumber*)movieControlStyle
-(void)setMediaControlStyle:(NSNumber *)value
{
if (movie != nil) {
dispatch_async(dispatch_get_main_queue(), ^{
TiThreadPerformOnMainThread(^{
[movie setControlStyle:[TiUtils intValue:value def:MPMovieControlStyleDefault]];
});
}, NO);
} else {
[loadProperties setValue:value forKey:@"mediaControlStyle"];
}
Expand Down
4 changes: 2 additions & 2 deletions iphone/Classes/TiUIDashboardItemProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,13 @@ -(void)add:(id)child
// because -[TiViewProxy add:] could exit early if it's not on the main thread.
// On the other hand, blocking this to execute on the main thread only doesn't appear to work right.

dispatch_async(dispatch_get_main_queue(), ^{
TiThreadPerformOnMainThread(^{
LauncherItem *item_ = [self ensureItem];
if (item_.view==nil)
{
[item_ setView:[self view]];
}
});
}, NO);
}


Expand Down
22 changes: 6 additions & 16 deletions iphone/Classes/TiUITableView.m
Original file line number Diff line number Diff line change
Expand Up @@ -463,14 +463,9 @@ -(void)reloadDataFromCount:(int)oldCount toCount:(int)newCount animation:(UITabl
// way, meaning that we have to explicitly reload the whole visible table to get
// the "right" behavior.
if (animation == UITableViewRowAnimationNone) {
if (![NSThread isMainThread]) {
dispatch_async(dispatch_get_main_queue(), ^{
[table reloadData];
});
}
else {
[table reloadData];
}
TiThreadPerformOnMainThread(^{
[table reloadData];
}, NO);
return;
}

Expand Down Expand Up @@ -1681,14 +1676,9 @@ -(void)setIndex_:(NSArray*)index_

// Instead of calling back through our mechanism to reload specific sections, because the entire index of the table
// has been regenerated, we can assume it's okay to just reload the whole dataset.
if ([NSThread isMainThread]) {
[[self tableView] reloadData];
}
else {
dispatch_async(dispatch_get_main_queue(), ^{
[[self tableView] reloadData];
});
}
TiThreadPerformOnMainThread(^{
[[self tableView] reloadData];
}, NO);
}

-(void)setFilterCaseInsensitive_:(id)caseBool
Expand Down
4 changes: 2 additions & 2 deletions iphone/Classes/TiUIView.m
Original file line number Diff line number Diff line change
Expand Up @@ -484,9 +484,9 @@ -(CALayer *)backgroundImageLayer
-(void)renderRepeatedBackground:(id)image
{
if (![NSThread isMainThread]) {
dispatch_async(dispatch_get_main_queue(), ^{
TiThreadPerformOnMainThread(^{
[self renderRepeatedBackground:image];
});
}, NO);
return;
}

Expand Down
8 changes: 4 additions & 4 deletions iphone/Classes/TiViewProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -262,18 +262,18 @@ -(void)remove:(id)arg

-(void)show:(id)arg
{
dispatch_async(dispatch_get_main_queue(), ^{
TiThreadPerformOnMainThread(^{
[self setHidden:NO withArgs:arg];
[self replaceValue:NUMBOOL(YES) forKey:@"visible" notification:YES];
});
}, NO);
}

-(void)hide:(id)arg
{
dispatch_async(dispatch_get_main_queue(), ^{
TiThreadPerformOnMainThread(^{
[self setHidden:YES withArgs:arg];
[self replaceValue:NUMBOOL(NO) forKey:@"visible" notification:YES];
});
}, NO);
}

-(void)animate:(id)arg
Expand Down

0 comments on commit a79ca0f

Please sign in to comment.