Ignore:
Timestamp:
Jan 8, 2012, 7:58:58 PM (10 years ago)
Author:
livings124
Message:

fix a theoretical concurrency issue when removing previous pieces info

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/Controller.m

    r13148 r13149  
    21672167    if ([fDisplayedTorrents count] > 0)
    21682168    {
    2169         NSMutableIndexSet * unusedIndexesInAll = [NSMutableIndexSet indexSetWithIndexesInRange: NSMakeRange(0, [allTorrents count])];
    2170        
    21712169        //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
    2172         void (^removePreviousFinishedPieces)(id, NSUInteger, BOOL *) = ^(id objDisplay, NSUInteger idx, BOOL * stop) {
    2173             const NSUInteger index = [allTorrents indexOfObjectAtIndexes: unusedIndexesInAll options: NSEnumerationConcurrent passingTest: ^BOOL(id objAll, NSUInteger idxAll, BOOL * stopAll) {
    2174                 return objDisplay == objAll;
    2175             }];
    2176            
    2177             if (index == NSNotFound)
    2178                 [(Torrent *)objDisplay setPreviousFinishedPieces: nil];
    2179             else
    2180                 [unusedIndexesInAll removeIndex: index];
     2170        void (^removePreviousFinishedPieces)(id, NSUInteger, BOOL *) = ^(id obj, NSUInteger idx, BOOL * stop) {
     2171            //we used to keep track of which torrents we already found in allTorrents, but it wasn't safe fo concurrent enumeration
     2172            if (![allTorrents containsObject: obj])
     2173                [(Torrent *)obj setPreviousFinishedPieces: nil];
    21812174        };
    21822175       
Note: See TracChangeset for help on using the changeset viewer.