Revision: 15192
http://bibdesk.svn.sourceforge.net/bibdesk/?rev=15192&view=rev
Author: hofman
Date: 2009-04-25 23:58:43 +0000 (Sat, 25 Apr 2009)
Log Message:
-----------
reorganize file index thread code
Modified Paths:
--------------
trunk/bibdesk/BDSKFileSearchIndex.m
Modified: trunk/bibdesk/BDSKFileSearchIndex.m
===================================================================
--- trunk/bibdesk/BDSKFileSearchIndex.m 2009-04-25 23:37:45 UTC (rev 15191)
+++ trunk/bibdesk/BDSKFileSearchIndex.m 2009-04-25 23:58:43 UTC (rev 15192)
@@ -467,20 +467,6 @@
[noteLock unlockWithCondition:QUEUE_HAS_NOTIFICATIONS];
}
-- (NSDictionary *)newNotification
-{
- NSDictionary *note = nil;
- [noteLock lockWhenCondition:QUEUE_HAS_NOTIFICATIONS];
- NSUInteger count = [notificationQueue count];
- if (count > 0) {
- note = [[notificationQueue objectAtIndex:0] retain];
- [notificationQueue removeObjectAtIndex:0];
- count--;
- }
- [noteLock unlockWithCondition:(count > 0 ? QUEUE_HAS_NOTIFICATIONS :
QUEUE_EMPTY)];
- return note;
-}
-
- (void)processDocAddItem:(NSArray *)searchIndexInfo
{
BDSKASSERT([[NSThread currentThread] isEqual:notificationThread]);
@@ -543,6 +529,35 @@
[self performSelectorOnMainThread:@selector(searchIndexDidUpdate)
withObject:nil waitUntilDone:NO];
}
+- (void)processNextNotification
+{
+ NSDictionary *note = nil;
+
+ [noteLock lockWhenCondition:QUEUE_HAS_NOTIFICATIONS];
+ NSUInteger count = [notificationQueue count];
+ if (count > 0) {
+ note = [[notificationQueue objectAtIndex:0] retain];
+ [notificationQueue removeObjectAtIndex:0];
+ count--;
+ }
+ [noteLock unlockWithCondition:(count > 0 ? QUEUE_HAS_NOTIFICATIONS :
QUEUE_EMPTY)];
+
+ if (note) {
+ NSString *name = [note valueForKey:@"name"];
+ NSArray *searchIndexInfo = [note valueForKey:@"searchIndexInfo"];
+
+ // this is a background thread that can handle these notifications
+ if ([name isEqualToString:BDSKFileSearchIndexInfoChangedNotification])
+ [self processSearchIndexInfoChanged:searchIndexInfo];
+ else if ([name isEqualToString:BDSKDocAddItemNotification])
+ [self processDocAddItem:searchIndexInfo];
+ else if ([name isEqualToString:BDSKDocDelItemNotification])
+ [self processDocDelItem:searchIndexInfo];
+
+ [note release];
+ }
+}
+
#pragma mark Thread initialization
static void addItemFunction(const void *value, void *context) {
@@ -693,35 +708,19 @@
@try{
[self buildIndexWithInfo:info];
}
- @catch(id localException){
- NSLog(@"Ignoring exception %@ raised while rebuilding index",
localException);
+ @catch(id e){
+ NSLog(@"Ignoring exception %@ raised while rebuilding index", e);
}
- // run the current run loop until we get a cancel message, or else the
current thread/run loop will just go away when this function returns
+ // process notifications from the notificationQueue until we should stop
@try{
-
while ([self shouldKeepRunning]) {
// this blocks until a new note is available, or the index finishes
- NSDictionary *note = [self newNotification];
- if (note) {
- NSString *name = [note valueForKey:@"name"];
- NSArray *searchIndexInfo = [note
valueForKey:@"searchIndexInfo"];
-
- // this is a background thread that can handle these
notifications
- if ([name
isEqualToString:BDSKFileSearchIndexInfoChangedNotification])
- [self processSearchIndexInfoChanged:searchIndexInfo];
- else if ([name isEqualToString:BDSKDocAddItemNotification])
- [self processDocAddItem:searchIndexInfo];
- else if ([name isEqualToString:BDSKDocDelItemNotification])
- [self processDocDelItem:searchIndexInfo];
-
- [note release];
- }
+ [self processNextNotification];
}
-
}
- @catch(id localException){
- NSLog(@"Exception %@ raised in search index; exiting thread run
loop.", localException);
+ @catch(id e){
+ NSLog(@"Exception %@ raised in search index; exiting thread run
loop.", e);
// clean these up to make sure we have no chance of saving it to disk
if (index) CFRelease(index);
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensign option that enables unlimited
royalty-free distribution of the report engine for externally facing
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
Bibdesk-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit