Revision: 28555
          http://sourceforge.net/p/bibdesk/svn/28555
Author:   hofman
Date:     2024-01-05 19:43:07 +0000 (Fri, 05 Jan 2024)
Log Message:
-----------
use locks instead of lock queues

Modified Paths:
--------------
    trunk/bibdesk/BDSKFileSearchIndex.h
    trunk/bibdesk/BDSKFileSearchIndex.m
    trunk/bibdesk/BDSKNotesSearchIndex.h
    trunk/bibdesk/BDSKNotesSearchIndex.m

Modified: trunk/bibdesk/BDSKFileSearchIndex.h
===================================================================
--- trunk/bibdesk/BDSKFileSearchIndex.h 2024-01-05 19:26:02 UTC (rev 28554)
+++ trunk/bibdesk/BDSKFileSearchIndex.h 2024-01-05 19:43:07 UTC (rev 28555)
@@ -76,7 +76,6 @@
     BDSKReadWriteLock *rwLock;
     
     dispatch_queue_t queue;
-    dispatch_queue_t lockQueue;
     
     BDSKSearchIndexFlags flags;
     BOOL canceled;

Modified: trunk/bibdesk/BDSKFileSearchIndex.m
===================================================================
--- trunk/bibdesk/BDSKFileSearchIndex.m 2024-01-05 19:26:02 UTC (rev 28554)
+++ trunk/bibdesk/BDSKFileSearchIndex.m 2024-01-05 19:43:07 UTC (rev 28555)
@@ -48,6 +48,8 @@
 
 @interface BDSKFileSearchIndex (Private)
 
+@property double progressValue;
+
 + (NSURL *)indexCacheFolderURL;
 - (void)makeIndexForDocumentAtURL:(NSURL *)documentURL;
 - (void)resetIndexWithItems:(NSArray *)items;
@@ -62,8 +64,8 @@
 
 @implementation BDSKFileSearchIndex
 
-@synthesize index=skIndex, delegate;
-@dynamic status, progressValue;
+@synthesize index=skIndex, delegate, progressValue;
+@dynamic status;
 
 // increment if incompatible changes are introduced
 #define CACHE_VERSION @"2"
@@ -106,7 +108,6 @@
         progressValue = 0.0;
         
         queue = 
dispatch_queue_create("edu.ucsd.cs.mmccrack.bibdesk.queue.BDSKFileSearchIndex", 
NULL);
-        lockQueue = 
dispatch_queue_create("edu.ucsd.cs.mmccrack.bibdesk.lockQueue.BDSKFileSearchIndex",
 NULL);
         
         dispatch_async(queue, ^{
             [self makeIndexForDocumentAtURL:documentURL];
@@ -126,7 +127,6 @@
 - (void)dealloc
 {
     BDSKDISPATCHDESTROY(queue);
-    BDSKDISPATCHDESTROY(lockQueue);
        BDSKDESTROY(URLsForIdentifierURLs);
     [rwLock lockForWriting];
        BDSKDESTROY(identifierURLsForURLs);
@@ -193,15 +193,6 @@
     return set;
 }
 
-- (double)progressValue
-{
-    __block double theValue;
-    dispatch_sync(lockQueue, ^{
-        theValue = progressValue;
-    });
-    return theValue;
-}
-
 #pragma mark Private methods
 
 #pragma mark Caching
@@ -455,9 +446,7 @@
         if ([self shouldKeepRunning] == NO) break;
         [self indexFileURLs:[anObject objectForKey:BDSKBibItemURLsKey] 
forIdentifierURL:[anObject objectForKey:BDSKBibItemIdentifierURLKey]];
         numberIndexed++;
-        dispatch_async(lockQueue, ^{
-            progressValue = (numberIndexed / totalObjectCount) * 100;
-        });
+        [self setProgressValue:(numberIndexed / totalObjectCount) * 100];
         
         [pool release];
         pool = [NSAutoreleasePool new];
@@ -622,9 +611,7 @@
                 [itemsToAdd addObject:@{BDSKBibItemURLsKey:missingURLs}];
             } else {
                 numberIndexed++;
-                dispatch_async(lockQueue, ^{
-                    progressValue = (numberIndexed / totalObjectCount) * 100;
-                });
+                [self setProgressValue:(numberIndexed / totalObjectCount) * 
100];
                 
                 [self didUpdate];
             }

Modified: trunk/bibdesk/BDSKNotesSearchIndex.h
===================================================================
--- trunk/bibdesk/BDSKNotesSearchIndex.h        2024-01-05 19:26:02 UTC (rev 
28554)
+++ trunk/bibdesk/BDSKNotesSearchIndex.h        2024-01-05 19:43:07 UTC (rev 
28555)
@@ -43,6 +43,8 @@
 @protocol BDSKOwner;
 @protocol BDSKNotesSearchIndexDelegate;
 
+@class BDSKReadWriteLock;
+
 @interface BDSKNotesSearchIndex : NSObject {
     SKIndexRef skIndex;
     _Atomic(BOOL) shouldKeepRunning;
@@ -50,7 +52,7 @@
     _Atomic(BOOL) updateScheduled;
     BOOL terminated;
     dispatch_queue_t queue;
-    dispatch_queue_t lockQueue;
+    BDSKReadWriteLock *lock;
     NSFileManager *fileManager;
     __weak id <BDSKNotesSearchIndexDelegate> delegate;
 }

Modified: trunk/bibdesk/BDSKNotesSearchIndex.m
===================================================================
--- trunk/bibdesk/BDSKNotesSearchIndex.m        2024-01-05 19:26:02 UTC (rev 
28554)
+++ trunk/bibdesk/BDSKNotesSearchIndex.m        2024-01-05 19:43:07 UTC (rev 
28555)
@@ -43,6 +43,7 @@
 #import <SkimNotesBase/SkimNotesBase.h>
 #import "BibDocument.h"
 #import "BDSKPublicationsArray.h"
+#import "BDSKReadWriteLock.h"
 
 
 @interface BDSKNotesSearchIndex (BDSKPrivate)
@@ -67,7 +68,7 @@
         terminated = NO;
         
         queue = 
dispatch_queue_create("edu.ucsd.cs.mmccrack.bibdesk.queue.BDSKNotesSearchIndex",
 NULL);
-        lockQueue = 
dispatch_queue_create("edu.ucsd.cs.mmccrack.bibdesk.lockQueue.BDSKNotesSearchIndex",
 NULL);
+        lock = [[BDSKReadWriteLock alloc] init];
         
         fileManager = [[NSFileManager alloc] init];
         
@@ -86,7 +87,7 @@
 {
     delegate = nil;
     BDSKDISPATCHDESTROY(queue);
-    BDSKDISPATCHDESTROY(lockQueue);
+    BDSKDESTROY(lock);
     BDSKCFDESTROY(skIndex);
     BDSKDESTROY(fileManager);
     [super dealloc];
@@ -174,10 +175,10 @@
     
     CFMutableDataRef indexData = CFDataCreateMutable(NULL, 0);
     NSDictionary *options = @{(__bridge id)kSKMaximumTerms:@0};
-    dispatch_sync(lockQueue, ^{
-        BDSKCFDESTROY(skIndex);
-        skIndex = SKIndexCreateWithMutableData(indexData, (__bridge 
CFStringRef)BDSKSkimNotesString, kSKIndexInverted, (__bridge 
CFDictionaryRef)options);
-    });
+    [lock lockForWriting];
+    if (skIndex) CFRelease(skIndex);
+    skIndex = SKIndexCreateWithMutableData(indexData, (__bridge 
CFStringRef)BDSKSkimNotesString, kSKIndexInverted, (__bridge 
CFDictionaryRef)options);
+    [lock unlock];
     CFRelease(indexData);
     
     // this will handle the index flush after adding all the pubs
@@ -199,10 +200,10 @@
     if (terminated)
         return NULL;
     
-    __block SKIndexRef theIndex = NULL;
-    dispatch_sync(lockQueue, ^{
-        if (skIndex) theIndex = (SKIndexRef)CFRetain(skIndex);
-    });
+    SKIndexRef theIndex = NULL;
+    [lock lockForReading];
+    if (skIndex) theIndex = (SKIndexRef)CFRetain(skIndex);
+    [lock unlock];
     if (atomic_load(&needsFlushing)) {
         SKIndexFlush(theIndex);
         atomic_store(&needsFlushing, NO);
@@ -248,10 +249,10 @@
                 }
             }
             
-            __block SKIndexRef theIndex = NULL;
-            dispatch_sync(lockQueue, ^{
-                if (skIndex) theIndex = (SKIndexRef)CFRetain(skIndex);
-            });
+            SKIndexRef theIndex = NULL;
+            [lock lockForReading];
+            if (skIndex) theIndex = (SKIndexRef)CFRetain(skIndex);
+            [lock unlock];
             if (theIndex) {
                 BOOL didUpdate = NO;
                 if ([searchText length]) {

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.



_______________________________________________
Bibdesk-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit

Reply via email to