1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2025-02-20 21:26:53 +00:00

fix a theoretical concurrency issue when removing previous pieces info

This commit is contained in:
Mitchell Livingston 2012-01-08 19:58:58 +00:00
parent 27595b4888
commit ee8977d5c3

View file

@ -2166,18 +2166,11 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy
//clear display cache for not-shown torrents
if ([fDisplayedTorrents count] > 0)
{
NSMutableIndexSet * unusedIndexesInAll = [NSMutableIndexSet indexSetWithIndexesInRange: NSMakeRange(0, [allTorrents count])];
//for each torrent, removes the previous piece info if it's not in allTorrents, and keeps track of which torrents we already found in allTorrents
void (^removePreviousFinishedPieces)(id, NSUInteger, BOOL *) = ^(id objDisplay, NSUInteger idx, BOOL * stop) {
const NSUInteger index = [allTorrents indexOfObjectAtIndexes: unusedIndexesInAll options: NSEnumerationConcurrent passingTest: ^BOOL(id objAll, NSUInteger idxAll, BOOL * stopAll) {
return objDisplay == objAll;
}];
if (index == NSNotFound)
[(Torrent *)objDisplay setPreviousFinishedPieces: nil];
else
[unusedIndexesInAll removeIndex: index];
void (^removePreviousFinishedPieces)(id, NSUInteger, BOOL *) = ^(id obj, NSUInteger idx, BOOL * stop) {
//we used to keep track of which torrents we already found in allTorrents, but it wasn't safe fo concurrent enumeration
if (![allTorrents containsObject: obj])
[(Torrent *)obj setPreviousFinishedPieces: nil];
};
if ([[fDisplayedTorrents objectAtIndex: 0] isKindOfClass: [TorrentGroup class]])