From: <ho...@us...> - 2007-01-26 10:50:20
|
Revision: 9386 http://svn.sourceforge.net/bibdesk/?rev=9386&view=rev Author: hofman Date: 2007-01-26 02:50:14 -0800 (Fri, 26 Jan 2007) Log Message: ----------- Break off writing metadata when the app terminates. Use OSAtomic function to set flag and volatile aligned ivar for thread safety. Modified Paths: -------------- trunk/bibdesk/BibAppController.m Modified: trunk/bibdesk/BibAppController.m =================================================================== --- trunk/bibdesk/BibAppController.m 2007-01-26 10:36:20 UTC (rev 9385) +++ trunk/bibdesk/BibAppController.m 2007-01-26 10:50:14 UTC (rev 9386) @@ -76,6 +76,7 @@ #import "BDSKDocumentController.h" #import "NSError_BDSKExtensions.h" #import "BDSKSpotlightIconController.h" +#import <libkern/OSAtomic.h> @implementation BibAppController @@ -175,7 +176,7 @@ metadataCacheLock = [[NSLock alloc] init]; metadataMessageQueue = [[OFMessageQueue alloc] init]; [metadataMessageQueue startBackgroundProcessors:1]; - canWriteMetadata = YES; + canWriteMetadata = 1; NSString *formatString = [[OFPreferenceWrapper sharedPreferenceWrapper] objectForKey:BDSKCiteKeyFormatKey]; NSString *error = nil; @@ -348,9 +349,7 @@ } - (void)applicationWillTerminate:(NSNotification *)aNotification{ - [metadataCacheLock lock]; - canWriteMetadata = NO; - [metadataCacheLock unlock]; + OSAtomicCompareAndSwap32Barrier(1, 0, (int32_t *)&canWriteMetadata); NSArray *fileNames = [[[NSDocumentController sharedDocumentController] documents] valueForKeyPath:@"@distinctUnionOfObjects.fileName"]; NSMutableArray *array = [NSMutableArray arrayWithCapacity:[fileNames count]]; @@ -1207,7 +1206,7 @@ // we could unlock after checking the flag, but we don't want multiple threads writing to the cache directory at the same time, in case files have identical items [metadataCacheLock lock]; - if(canWriteMetadata == NO){ + if(canWriteMetadata == 0){ NSLog(@"Application will quit without writing metadata cache."); [metadataCacheLock unlock]; return; @@ -1264,6 +1263,11 @@ while(anItem = [entryEnum nextObject]){ + if(canWriteMetadata == 0){ + NSLog(@"Application will quit without finishing writing metadata cache."); + break; + } + [innerPool release]; innerPool = [NSAutoreleasePool new]; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |