Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(3_0_X)[TIMOB-10280] cleanup dispatch_async calls to prevent possibility of reordered actions #3749

Merged
merged 1 commit into from
Jan 21, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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