adium/adium

Parents 5f77a1375881
Children 38a86a06aa15
Do the waiting for the semaphore on a serial dispatch queue, which asyncs blocks to the _LOW dispatch queue. This should fix #16412
--- a/Plugins/Twitter Plugin/AITwitterAccount.m Tue Jun 18 14:20:39 2013 +0200
+++ b/Plugins/Twitter Plugin/AITwitterAccount.m Wed Jun 19 17:49:07 2013 +0200
@@ -1033,37 +1033,45 @@
[listContact setValue:[NSNumber numberWithBool:YES] forProperty:TWITTER_PROPERTY_REQUESTED_USER_ICON notify:NotifyNever];
static dispatch_semaphore_t imageDownloadSemaphore;
+ static dispatch_queue_t imageDownloadScheduleQueue;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
imageDownloadSemaphore = dispatch_semaphore_create(16);
+ imageDownloadScheduleQueue = dispatch_queue_create("im.adium.AITwitterAccount.imageDownloadScheduleQueue", NULL);
+ dispatch_set_target_queue(imageDownloadScheduleQueue, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0));
});
- // Grab the user icon and set it as their serverside icon.
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
- NSString *imageURL = [url stringByReplacingOccurrencesOfString:@"_normal." withString:@"_bigger."];
- NSURLRequest *imageRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:imageURL]];
- NSError *error = nil;
+ dispatch_async(imageDownloadScheduleQueue, ^{
dispatch_semaphore_wait(imageDownloadSemaphore, DISPATCH_TIME_FOREVER);
- NSData *data = [NSURLConnection sendSynchronousRequest:imageRequest returningResponse:nil error:&error];
- dispatch_semaphore_signal(imageDownloadSemaphore);
- NSImage *image = [[[NSImage alloc] initWithData:data] autorelease];
-
- if (image) {
- dispatch_async(dispatch_get_main_queue(), ^{
- AILogWithSignature(@"%@ Updated user icon for %@", self, listContact);
- [listContact setServersideIconData:[image TIFFRepresentation]
- notify:NotifyLater];
-
- [listContact setValue:nil forProperty:TWITTER_PROPERTY_REQUESTED_USER_ICON notify:NotifyNever];
- [listContact setValue:url forProperty:TWITTER_PROPERTY_USER_ICON_URL afterDelay:NotifyNever];
- });
- } else {
- dispatch_async(dispatch_get_main_queue(), ^{
- [self requestFailed:AITwitterUserIconPull withError:error userInfo:@{ @"ListContact" : listContact }];
- });
- }
+ // Grab the user icon and set it as their serverside icon.
+ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
+ NSString *imageURL = [url stringByReplacingOccurrencesOfString:@"_normal." withString:@"_bigger."];
+ NSURLRequest *imageRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:imageURL]];
+ NSError *error = nil;
+
+ NSData *data = [NSURLConnection sendSynchronousRequest:imageRequest returningResponse:nil error:&error];
+
+ NSImage *image = [[[NSImage alloc] initWithData:data] autorelease];
+
+ if (image) {
+ dispatch_async(dispatch_get_main_queue(), ^{
+ AILogWithSignature(@"%@ Updated user icon for %@", self, listContact);
+ [listContact setServersideIconData:[image TIFFRepresentation]
+ notify:NotifyLater];
+
+ [listContact setValue:nil forProperty:TWITTER_PROPERTY_REQUESTED_USER_ICON notify:NotifyNever];
+ [listContact setValue:url forProperty:TWITTER_PROPERTY_USER_ICON_URL afterDelay:NotifyNever];
+ });
+ } else {
+ dispatch_async(dispatch_get_main_queue(), ^{
+ [self requestFailed:AITwitterUserIconPull withError:error userInfo:@{ @"ListContact" : listContact }];
+ });
+ }
+
+ dispatch_semaphore_signal(imageDownloadSemaphore);
+ });
});
}
}