From 81008a16925bea739b22e7695a1d1d3cb0c493bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C5=93ur?= Date: Mon, 29 Jan 2024 05:49:06 +0100 Subject: [PATCH] only use a single concurrent queue for timeMachineExclude instead of one queue per torrent (#6523) * only use a single concurrent queue for timeMachineExclude instead of one queue per torrent * moving to +initialize for now (will become a `static let` in Swift anyway) * DISPATCH_QUEUE_SERIAL because DISPATCH_QUEUE_CONCURRENT is limited to 64 simultaneous torrent dispatch_async * `static` is better than `global`, to make it private to a single compilation unit --- macosx/Controller.mm | 3 +++ macosx/CreatorWindowController.mm | 2 +- macosx/Torrent.mm | 16 ++++++++++++---- macosx/TrackerCell.mm | 11 +++++++---- 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/macosx/Controller.mm b/macosx/Controller.mm index 2c7897082..c0a01a091 100644 --- a/macosx/Controller.mm +++ b/macosx/Controller.mm @@ -345,6 +345,9 @@ static void removeKeRangerRansomware() + (void)initialize { + if (self != [Controller self]) + return; + removeKeRangerRansomware(); //make sure another Transmission.app isn't running already diff --git a/macosx/CreatorWindowController.mm b/macosx/CreatorWindowController.mm index 847562cfe..c5952ee76 100644 --- a/macosx/CreatorWindowController.mm +++ b/macosx/CreatorWindowController.mm @@ -56,7 +56,7 @@ typedef NS_ENUM(NSUInteger, TrackerSegmentTag) { @end -NSMutableSet* creatorWindowControllerSet = nil; +static NSMutableSet* creatorWindowControllerSet; @implementation CreatorWindowController diff --git a/macosx/Torrent.mm b/macosx/Torrent.mm index ea732692b..6f5d83397 100644 --- a/macosx/Torrent.mm +++ b/macosx/Torrent.mm @@ -23,6 +23,8 @@ NSString* const kTorrentDidChangeGroupNotification = @"TorrentDidChangeGroup"; static int const kETAIdleDisplaySec = 2 * 60; +static dispatch_queue_t timeMachineExcludeQueue; + @interface Torrent () @property(nonatomic, readonly) tr_torrent* fHandle; @@ -45,8 +47,6 @@ static int const kETAIdleDisplaySec = 2 * 60; @property(nonatomic) BOOL fResumeOnWake; -@property(nonatomic) dispatch_queue_t timeMachineExcludeQueue; - - (void)renameFinished:(BOOL)success nodes:(NSArray*)nodes completionHandler:(void (^)(BOOL))completionHandler @@ -98,6 +98,15 @@ bool trashDataFile(char const* filename, void* /*user_data*/, tr_error* error) @implementation Torrent ++ (void)initialize +{ + if (self != [Torrent self]) + return; + + // DISPATCH_QUEUE_SERIAL because DISPATCH_QUEUE_CONCURRENT is limited to 64 simultaneous torrent dispatch_async + timeMachineExcludeQueue = dispatch_queue_create("updateTimeMachineExclude", DISPATCH_QUEUE_SERIAL); +} + - (instancetype)initWithPath:(NSString*)path location:(NSString*)location deleteTorrentFile:(BOOL)torrentDelete @@ -1826,7 +1835,6 @@ bool trashDataFile(char const* filename, void* /*user_data*/, tr_error* error) name:@"GroupValueRemoved" object:nil]; - _timeMachineExcludeQueue = dispatch_queue_create("updateTimeMachineExclude", DISPATCH_QUEUE_CONCURRENT); [self update]; [self updateTimeMachineExclude]; @@ -2157,7 +2165,7 @@ bool trashDataFile(char const* filename, void* /*user_data*/, tr_error* error) NSString* path; if ((path = self.dataLocation)) { - dispatch_async(_timeMachineExcludeQueue, ^{ + dispatch_async(timeMachineExcludeQueue, ^{ CFURLRef url = (__bridge CFURLRef)[NSURL fileURLWithPath:path]; CSBackupSetItemExcluded(url, exclude, false); }); diff --git a/macosx/TrackerCell.mm b/macosx/TrackerCell.mm index 8412a010b..55559b598 100644 --- a/macosx/TrackerCell.mm +++ b/macosx/TrackerCell.mm @@ -20,6 +20,10 @@ static CGFloat const kPaddingBetweenLines = 1.0; static CGFloat const kPaddingBetweenLinesOnSameLine = 4.0; static CGFloat const kCountWidth = 60.0; +// make the favicons accessible to all tracker cells +static NSCache* fTrackerIconCache; +static NSMutableSet* fTrackerIconLoading; + @interface TrackerCell () @property(nonatomic, readonly) NSImage* favIcon; @@ -31,12 +35,11 @@ static CGFloat const kCountWidth = 60.0; @implementation TrackerCell -//make the favicons accessible to all tracker cells -NSCache* fTrackerIconCache; -NSMutableSet* fTrackerIconLoading; - + (void)initialize { + if (self != [TrackerCell self]) + return; + fTrackerIconCache = [[NSCache alloc] init]; fTrackerIconLoading = [[NSMutableSet alloc] init]; }