Changeset 4875

Show
Ignore:
Timestamp:
08/22/07 21:41:01 (1 year ago)
Author:
morris
Message:

Fix thread sync when loading data instead of images

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • Footagehead/trunk/FHBrowserController.m

    r4871 r4875  
    10051005                path = [openPanel filename]; 
    10061006                 
    1007                 [_imageLoader stopLoadingImagesAndThumbnails]; 
     1007                [_imageLoader pauseLoadingImagesAndThumbnails]; 
    10081008                [_imageLoader startLoadingData]; 
    10091009 
     
    10301030        [_saveProgressPanel close]; 
    10311031         
    1032         NSLog(@"returnCode = %d", returnCode); 
    1033          
    1034         if(returnCode != NSAlertDefaultReturn) { 
    1035                 [_imageLoader stopLoadingData]; 
    1036         } 
    1037  
    1038         [_imageLoader startLoadingImages]; 
     1032        if(returnCode != NSAlertDefaultReturn) 
     1033                [_imageLoader pauseLoadingData]; 
     1034 
     1035        [_imageLoader startLoadingImageAtIndex:[self selectedIndex]]; 
    10391036        [_imageLoader startLoadingThumbnails]; 
    10401037} 
  • Footagehead/trunk/FHImageLoader.h

    r4868 r4875  
    4040        NSUInteger                              _dataCounter; 
    4141         
    42         BOOL                                    _imageStop; 
    43         BOOL                                    _thumbnailStop; 
    44         BOOL                                    _dataStop; 
     42        BOOL                                    _imagePause, _imageStop; 
     43        BOOL                                    _thumbnailPause, _thumbnailStop; 
     44        BOOL                                    _dataPause, _dataStop; 
    4545         
    4646        NSLock                                  *_asynchronousLock; 
     
    7979- (void)startLoadingImages; 
    8080- (void)startLoadingThumbnails; 
     81- (void)pauseLoadingImagesAndThumbnails; 
    8182- (void)stopLoadingImagesAndThumbnails; 
    8283- (void)startLoadingData; 
     84- (void)pauseLoadingData; 
    8385- (void)stopLoadingData; 
    8486 
  • Footagehead/trunk/FHImageLoader.m

    r4871 r4875  
    238238 
    239239- (void)imageThread:(id)object { 
    240         NSAutoreleasePool               *pool
     240        NSAutoreleasePool               *pool, *loopPool
    241241        NSArray                                 *files; 
    242242        FHFile                                  *file; 
    243243        NSUInteger                              i, count, index; 
    244244        NSUInteger                              counter, lastCounter = 0; 
    245         BOOL                                    stop; 
     245        BOOL                                    pause, stop; 
    246246         
    247247        [NSThread setThreadPriority:0.5]; 
     
    250250 
    251251        while(YES) { 
    252                 if(!pool) 
    253                         pool = [[NSAutoreleasePool alloc] init]; 
     252                loopPool = [[NSAutoreleasePool alloc] init]; 
    254253 
    255254                [_imageLock lockWhenCondition:1]; 
     
    299298                                if(counter != _imageCounter) 
    300299                                        i = count; 
     300                                pause = _imagePause; 
     301                                _imagePause = NO; 
    301302                                stop = _imageStop; 
    302303                                [_imageLock unlockWithCondition:counter == _imageCounter ? 0 : 1]; 
    303304                                 
    304                                 if(stop) 
     305                                if(pause || stop) 
    305306                                        break; 
    306307                        } 
     
    309310                } 
    310311 
    311                 [pool release]; 
    312                 pool = NULL; 
     312                [loopPool release]; 
     313                loopPool = NULL; 
    313314                 
    314315                if(stop) 
     
    328329        WIURL                           *url; 
    329330        NSUInteger                      i, count, counter, images; 
    330         BOOL                            stop; 
     331        BOOL                            pause, stop; 
    331332         
    332333        [NSThread setThreadPriority:0.25]; 
     
    364365                                if(counter != _thumbnailCounter) 
    365366                                        i = count; 
     367                                pause = _thumbnailPause; 
    366368                                stop = _thumbnailStop; 
    367369                                [_thumbnailLock unlockWithCondition:counter == _thumbnailCounter ? 0 : 1]; 
    368370                                 
    369                                 if(stop) 
     371                                if(pause || stop) 
    370372                                        break; 
    371373                        } 
     
    385387 
    386388- (void)dataThread:(id)sender { 
    387         NSAutoreleasePool               *pool
     389        NSAutoreleasePool               *pool, *loopPool
    388390        NSArray                                 *files; 
    389391        FHFile                                  *file; 
    390392        NSUInteger                              i, count; 
    391393        NSUInteger                              counter, lastCounter = 0; 
    392         BOOL                                    stop; 
     394        BOOL                                    pause, stop; 
    393395         
    394396        [NSThread setThreadPriority:0.5]; 
     
    397399 
    398400        while(YES) { 
    399                 if(!pool) 
    400                         pool = [[NSAutoreleasePool alloc] init]; 
     401                loopPool = [[NSAutoreleasePool alloc] init]; 
    401402 
    402403                [_dataLock lockWhenCondition:1]; 
     
    421422                                if(counter != _dataCounter) 
    422423                                        i = count; 
     424                                pause = _dataPause; 
     425                                _dataPause = NO; 
    423426                                stop = _dataStop; 
    424427                                [_dataLock unlockWithCondition:counter == _dataCounter ? 0 : 1]; 
    425428                                 
    426                                 if(stop) 
     429                                if(pause || stop) 
    427430                                        break; 
    428431                        } 
     
    430433                        lastCounter = counter; 
    431434 
    432                         [_notificationCenter mainThreadPostNotificationName:FHImageLoaderDidLoadAllFiles]; 
     435                        if(!pause && !stop) 
     436                                [_notificationCenter mainThreadPostNotificationName:FHImageLoaderDidLoadAllFiles]; 
    433437                } 
    434438 
    435                 [pool release]; 
    436                 pool = NULL; 
     439                [loopPool release]; 
     440                loopPool = NULL; 
    437441                 
    438442                if(stop) 
     
    501505 
    502506 
     507- (void)pauseLoadingImagesAndThumbnails { 
     508        [_imageLock lock]; 
     509        _imagePause = YES; 
     510        [_imageLock unlockWithCondition:0]; 
     511 
     512        [_thumbnailLock lock]; 
     513        _thumbnailPause = YES; 
     514        [_thumbnailLock unlockWithCondition:0]; 
     515} 
     516 
     517 
     518 
    503519- (void)stopLoadingImagesAndThumbnails { 
    504520        [_imageLock lock]; 
    505521        _imageStop = YES; 
    506         [_imageLock unlockWithCondition:1]; 
     522        [_imageLock unlockWithCondition:0]; 
    507523 
    508524        [_thumbnailLock lock]; 
    509525        _thumbnailStop = YES; 
    510         [_thumbnailLock unlockWithCondition:1]; 
     526        [_thumbnailLock unlockWithCondition:0]; 
    511527} 
    512528 
     
    521537 
    522538 
     539- (void)pauseLoadingData { 
     540        [_dataLock lock]; 
     541        _dataPause = YES; 
     542        [_dataLock unlockWithCondition:0]; 
     543} 
     544 
     545 
     546 
    523547- (void)stopLoadingData { 
    524548        [_dataLock lock]; 
    525549        _dataStop = YES; 
    526         [_dataLock unlockWithCondition:1]; 
     550        [_dataLock unlockWithCondition:0]; 
    527551} 
    528552