Changeset 2875

Show
Ignore:
Timestamp:
05/19/05 20:58:47 (4 years ago)
Author:
morris
Message:

Set thread priorities

Make threads check whether they are still working against the current fileset, and bail out if the user switched directories

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • Footagehead/trunk/FHController.h

    r2874 r2875  
    6363        NSConditionLock                                 *_loadImageLock; 
    6464        NSConditionLock                                 *_loadThumbnailsLock; 
    65         unsigned int                                    _row; 
     65        unsigned int                                    _selectedRow; 
     66        unsigned int                                    _imageCounter; 
     67        unsigned int                                    _thumbnailsCounter; 
    6668         
    6769        BOOL                                                    _openLast; 
  • Footagehead/trunk/FHController.m

    r2874 r2875  
    160160        [self updateTableView]; 
    161161         
    162         // --- detach loader thread 
     162        // --- detach loader threads 
    163163        [NSThread detachNewThreadSelector:@selector(loadImageThread:) toTarget:self withObject:NULL]; 
    164164        [NSThread detachNewThreadSelector:@selector(loadThumbnailsThread:) toTarget:self withObject:NULL]; 
     
    693693        } else { 
    694694                [_loadImageLock lock]; 
    695                 _row = row; 
     695                _selectedRow = row; 
     696                _imageCounter++; 
    696697                [_loadImageLock unlockWithCondition:1]; 
    697698        } 
     
    701702        if([_handler isLocal]) { 
    702703                [_loadThumbnailsLock lock]; 
     704                _thumbnailsCounter++; 
    703705                [_loadThumbnailsLock unlockWithCondition:1]; 
    704706        } 
     
    750752        NSImage                         *image; 
    751753        FHFile                          *file; 
    752         unsigned int            i, count, images, row, lastRow; 
     754        unsigned int            i, count, counter, images, row, lastRow; 
    753755         
    754756        lastRow = 0; 
     
    758760 
    759761                [_loadImageLock lockWhenCondition:1]; 
    760                 row = _row; 
    761                 files = [[_handler files] retain]; 
     762                row = _selectedRow; 
     763                files = [[_handler files] copy]; 
     764                counter = _imageCounter; 
    762765                [_loadImageLock unlockWithCondition:0]; 
    763766                 
     
    783786                                 
    784787                                if([file isDirectory]) 
    785                                         continue
     788                                        goto next
    786789                                 
    787790                                if(++images > 10) 
     
    789792                                 
    790793                                if([file image]) 
    791                                         continue
    792  
     794                                        goto next
     795                                 
    793796                                image = [[NSImage alloc] initWithContentsOfURL:[[file URL] URL]]; 
    794797                                [file setImage:[image smoothedImage]]; 
     
    796799 
    797800                                [self performSelectorOnMainThread:@selector(fileDidLoadImage:) withObject:file waitUntilDone:YES]; 
     801 
     802next: 
     803                                [_loadImageLock lock]; 
     804                                if(counter != _imageCounter) 
     805                                        i = count; 
     806                                [_loadImageLock unlockWithCondition:0]; 
    798807                        } 
    799808                         
     
    813822        NSImage                         *image; 
    814823        FHFile                          *file; 
    815         unsigned int            i, count; 
    816          
     824        unsigned int            i, count, counter; 
     825         
     826        [NSThread setThreadPriority:0.2]; 
     827 
    817828        while(YES) { 
    818829                pool = [[NSAutoreleasePool alloc] init]; 
    819830 
    820831                [_loadThumbnailsLock lockWhenCondition:1]; 
    821                 files = [[_handler files] retain]; 
     832                files = [[_handler files] copy]; 
     833                counter = _thumbnailsCounter; 
    822834                [_loadThumbnailsLock unlockWithCondition:0]; 
    823835                 
     
    828840                         
    829841                        if([file isDirectory]) 
    830                                 continue
     842                                goto next
    831843                         
    832844                        if([file hasThumbnail]) 
    833                                 continue
     845                                goto next
    834846 
    835847                        image = [[NSImage alloc] initWithJPEGFile:[file path] preferredSize:NSMakeSize(128.0, 128.0)]; 
     
    841853                                [self performSelectorOnMainThread:@selector(fileDidLoadThumbnail:) withObject:file waitUntilDone:YES]; 
    842854                        } 
    843                 } 
    844  
     855next: 
     856                        if(i % 5 == 0) { 
     857                                [_loadThumbnailsLock lock]; 
     858                                if(counter != _thumbnailsCounter) 
     859                                        i = count; 
     860                                [_loadThumbnailsLock unlockWithCondition:0]; 
     861                        } 
     862                } 
     863                 
    845864                [files release]; 
    846865                [pool release]; 
     
    11851204         
    11861205        [_loadImageLock lock]; 
    1187         _row = [_tableView selectedRow]; 
     1206        _selectedRow = [_tableView selectedRow]; 
    11881207        [_loadImageLock unlockWithCondition:1]; 
    11891208} 
  • Footagehead/trunk/FHFileCell.m

    r2874 r2875  
    8282 
    8383- (void)drawWithFrame:(NSRect)frame inView:(NSView *)view { 
    84         NSString        *name; 
    85         NSImage         *icon; 
    86         NSRect          rect; 
     84        NSAttributedString      *string; 
     85        NSString                        *name; 
     86        NSImage                         *icon; 
     87        NSRect                          rect; 
    8788         
    8889        name = [(NSDictionary *) [self objectValue] objectForKey:FHFileCellNameKey]; 
     
    9091         
    9192        rect = NSMakeRect(frame.origin.x, frame.origin.y + frame.size.height - 26.0, frame.size.width, 24.0); 
    92         [_nameCell setAttributedStringValue: 
    93                [NSAttributedString attributedStringWithString:name attributes:_attributes]]; 
     93        string = [[NSAttributedString alloc] initWithString:name attributes:_attributes]; 
     94        [_nameCell setAttributedStringValue:string]; 
    9495        [_nameCell setHighlighted:[self isHighlighted]]; 
    9596        [_nameCell drawWithFrame:rect inView:view]; 
     97        [string release]; 
    9698         
    9799        rect = NSMakeRect(frame.origin.x, frame.origin.y + 2.0, frame.size.width, frame.size.height - 28.0); 
  • Footagehead/trunk/FHImageView.m

    r2874 r2875  
    2626 
    2727- (void) setImage:(NSImage *)image { 
     28        BOOL    display; 
     29 
     30        display = (image != NULL || _image != NULL); 
     31         
    2832        [image retain]; 
    2933        [_image release]; 
     
    3135        _image = image; 
    3236        [_image setScalesWhenResized:YES]; 
    33  
    34         [self setNeedsDisplay:YES]; 
     37         
     38        if(display) 
     39                [self setNeedsDisplay:YES]; 
    3540} 
    3641 
  • Footagehead/trunk/Footagehead.xcode/project.pbxproj

    r2874 r2875  
    705705                        ); 
    706706                        buildSettings = { 
    707                                 GCC_GENERATE_DEBUGGING_SYMBOLS = NO; 
    708                                 GCC_MODEL_TUNING = G5; 
    709707                                LIBRARY_STYLE = STATIC; 
    710                                 OTHER_CFLAGS = ""; 
    711                                 OTHER_LDFLAGS = ""; 
    712                                 OTHER_REZFLAGS = ""; 
    713                                 PREBINDING = NO; 
    714708                                PRODUCT_NAME = jpeg; 
    715                                 SECTORDER_FLAGS = ""; 
    716                                 WARNING_CFLAGS = "-Wmost -Wno-four-char-constants -Wno-unknown-pragmas"; 
    717709                        }; 
    718710                        dependencies = ( 
     
    14921484                        buildActionMask = 2147483647; 
    14931485                        files = ( 
    1494                                 8D11072A0486CEB800E47090, 
    14951486                                8D11072B0486CEB800E47090, 
    14961487                                A5E51751057750A70004F5D6, 
    14971488                                A5E5174405774ED40004F5D6, 
    14981489                                77CDAE72083B3515003BE654, 
     1490                                8D11072A0486CEB800E47090, 
    14991491                                A51395F505771ED4007FE220, 
    15001492                                A587DF71055AA3C4005D2097,