Revision: 27869
          http://sourceforge.net/p/bibdesk/svn/27869
Author:   hofman
Date:     2022-09-07 16:50:08 +0000 (Wed, 07 Sep 2022)
Log Message:
-----------
use stdatomic instead of osatomic for some more classes

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

Modified: trunk/bibdesk/BDSKDocumentSearch.h
===================================================================
--- trunk/bibdesk/BDSKDocumentSearch.h  2022-09-07 16:37:21 UTC (rev 27868)
+++ trunk/bibdesk/BDSKDocumentSearch.h  2022-09-07 16:50:08 UTC (rev 27869)
@@ -37,6 +37,7 @@
  */
 
 #import <Cocoa/Cocoa.h>
+#import <stdatomic.h>
 
 @protocol BDSKDocumentSearchDelegate;
 
@@ -44,7 +45,7 @@
     @private;
     SKSearchRef search;
     id<BDSKDocumentSearchDelegate> delegate;
-    volatile int32_t isSearching;
+    _Atomic(BOOL) isSearching;
     BOOL shouldStop;
     NSString *currentSearchString; 
     dispatch_queue_t queue;

Modified: trunk/bibdesk/BDSKDocumentSearch.m
===================================================================
--- trunk/bibdesk/BDSKDocumentSearch.m  2022-09-07 16:37:21 UTC (rev 27868)
+++ trunk/bibdesk/BDSKDocumentSearch.m  2022-09-07 16:50:08 UTC (rev 27869)
@@ -39,7 +39,6 @@
 #import "BDSKDocumentSearch.h"
 #import "BibDocument.h"
 #import "BibItem.h"
-#import <libkern/OSAtomic.h>
 
 #define IDENTIFIERS_KEY @"identifiers"
 #define SCORES_KEY @"scores"
@@ -53,7 +52,7 @@
     if (self) {
         delegate = aDelegate;
         search = NULL;
-        isSearching = 0;
+        isSearching = NO;
         shouldStop = NO;
         currentSearchString = nil;
         previouslySelectedPublications = nil;
@@ -81,7 +80,7 @@
 {
     if (NULL != search) {
         // set first in case this is called while we're working
-        OSAtomicCompareAndSwap32Barrier(1, 0, &isSearching);
+        atomic_store(&isSearching, NO);
         SKSearchCancel(search);
         CFRelease(search);
         search = NULL;
@@ -106,8 +105,7 @@
 
 - (BOOL)isSearching;
 {
-    OSMemoryBarrier();
-    return 1 == isSearching;
+    return atomic_load(&isSearching);
 }
 
 #define SEARCH_BUFFER_MAX 1024
@@ -125,7 +123,7 @@
 
 - (void)backgroundSearchForString:(NSString *)searchString 
index:(SKIndexRef)skIndex
 {
-    OSAtomicCompareAndSwap32Barrier(0, 1, &isSearching);
+    atomic_store(&isSearching, YES);
     dispatch_sync(dispatch_get_main_queue(), ^{
         [delegate searchDidStart:self];
     });

Modified: trunk/bibdesk/BDSKFileSearchIndex.h
===================================================================
--- trunk/bibdesk/BDSKFileSearchIndex.h 2022-09-07 16:37:21 UTC (rev 27868)
+++ trunk/bibdesk/BDSKFileSearchIndex.h 2022-09-07 16:50:08 UTC (rev 27869)
@@ -37,6 +37,7 @@
  */
 
 #import <Cocoa/Cocoa.h>
+#import <stdatomic.h>
 
 @class BDSKFileSearchIndex, BDSKManyToManyDictionary, BDSKReadWriteLock, 
BibDocument;
 @protocol BDSKOwner;
@@ -59,9 +60,9 @@
 
 typedef struct _BDSKSearchIndexFlags
 {
-    volatile int32_t shouldKeepRunning;
-    volatile int32_t updateScheduled;
-    volatile int32_t status;
+    _Atomic(BOOL) shouldKeepRunning;
+    _Atomic(BOOL) updateScheduled;
+    _Atomic(BDSKSearchIndexStatus) status;
 } BDSKSearchIndexFlags;
 
 @interface BDSKFileSearchIndex : NSObject {

Modified: trunk/bibdesk/BDSKFileSearchIndex.m
===================================================================
--- trunk/bibdesk/BDSKFileSearchIndex.m 2022-09-07 16:37:21 UTC (rev 27868)
+++ trunk/bibdesk/BDSKFileSearchIndex.m 2022-09-07 16:50:08 UTC (rev 27869)
@@ -39,7 +39,6 @@
 #import "BDSKFileSearchIndex.h"
 #import "BDSKOwnerProtocol.h"
 #import "BibItem.h"
-#import <libkern/OSAtomic.h>
 #import "NSFileManager_BDSKExtensions.h"
 #import "NSData_BDSKExtensions.h"
 #import "NSArray_BDSKExtensions.h"
@@ -93,8 +92,8 @@
         delegate = nil;
         lastUpdateTime = CFAbsoluteTimeGetCurrent();
         
-        flags.shouldKeepRunning = 1;
-        flags.updateScheduled = 0;
+        flags.shouldKeepRunning = YES;
+        flags.updateScheduled = NO;
         flags.status = BDSKSearchIndexStatusStarting;
         
         canceled = NO;
@@ -140,8 +139,7 @@
 }
 
 - (BOOL)shouldKeepRunning {
-    OSMemoryBarrier();
-    return flags.shouldKeepRunning == 1;
+    return atomic_load(&flags.shouldKeepRunning);
 }
 
 - (void)resetWithPublications:(NSArray *)pubs {
@@ -151,13 +149,13 @@
     NSArray *items = [pubs valueForKey:@"searchIndexInfo"];
     
     // clear the queue
-    OSAtomicCompareAndSwap32Barrier(1, 0, &flags.shouldKeepRunning);
+    atomic_store(&flags.shouldKeepRunning, NO);
     dispatch_sync(queue, ^{});
     
     if (canceled)
         return;
     
-    OSAtomicCompareAndSwap32Barrier(0, 1, &flags.shouldKeepRunning);
+    atomic_store(&flags.shouldKeepRunning, YES);
     
     progressValue = 0.0;
     
@@ -174,7 +172,7 @@
     canceled = YES;
     
     [[NSNotificationCenter defaultCenter] removeObserver:self];
-    OSAtomicCompareAndSwap32Barrier(1, 0, &flags.shouldKeepRunning);
+    atomic_store(&flags.shouldKeepRunning, NO);
     
     // write index to file as last block on the queue and wait for it to finish
     dispatch_sync(queue, ^{
@@ -184,8 +182,7 @@
 
 - (BDSKSearchIndexStatus)status
 {
-    OSMemoryBarrier();
-    return flags.status;
+    return atomic_load(&flags.status);
 }
 
 - (NSSet *)identifierURLsForURL:(NSURL *)theURL
@@ -311,14 +308,13 @@
 {
     BDSKASSERT([NSThread isMainThread]);
     // Make sure we send frequently enough to update a progress bar, but not 
too frequently to avoid beachball on single-core systems; too many search 
updates slow down indexing due to repeated flushes. 
-    OSMemoryBarrier();
-    if (0 == flags.updateScheduled) {
-        CGFloat updateDelay = flags.status == BDSKSearchIndexStatusRunning ? 
1.0 : 0.1;
+    if (NO == atomic_load(&flags.updateScheduled)) {
+        CGFloat updateDelay = atomic_load(&flags.status) == 
BDSKSearchIndexStatusRunning ? 1.0 : 0.1;
         dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(updateDelay 
* NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
-            OSAtomicCompareAndSwap32Barrier(1, 0, &flags.updateScheduled);
+            atomic_store(&flags.updateScheduled, NO);
             [delegate searchIndexDidUpdate:self];
         });
-        OSAtomicCompareAndSwap32Barrier(0, 1, &flags.updateScheduled);
+        atomic_store(&flags.updateScheduled, YES);
     }
 }
 
@@ -332,7 +328,7 @@
 - (void)didUpdate
 {
     OSMemoryBarrier();
-    if (0 == flags.updateScheduled) {
+    if (NO == atomic_load(&flags.updateScheduled)) {
         dispatch_async(dispatch_get_main_queue(), ^{
             [self searchIndexDidUpdate];
         });
@@ -341,7 +337,7 @@
 
 - (void)updateStatus:(BDSKSearchIndexStatus)status
 {
-    OSAtomicCompareAndSwap32Barrier(flags.status, status, &flags.status);
+    atomic_store(&flags.status, status);
     dispatch_async(dispatch_get_main_queue(), ^{
         [self searchIndexDidUpdateStatus];
     });

Modified: trunk/bibdesk/BDSKNotesSearchIndex.h
===================================================================
--- trunk/bibdesk/BDSKNotesSearchIndex.h        2022-09-07 16:37:21 UTC (rev 
27868)
+++ trunk/bibdesk/BDSKNotesSearchIndex.h        2022-09-07 16:50:08 UTC (rev 
27869)
@@ -37,6 +37,7 @@
  */
 
 #import <Cocoa/Cocoa.h>
+#import <stdatomic.h>
 
 
 @protocol BDSKOwner;
@@ -44,9 +45,9 @@
 
 @interface BDSKNotesSearchIndex : NSObject {
     SKIndexRef skIndex;
-    volatile int32_t shouldKeepRunning;
-    volatile int32_t needsFlushing;
-    volatile int32_t updateScheduled;
+    _Atomic(BOOL) shouldKeepRunning;
+    _Atomic(BOOL) needsFlushing;
+    _Atomic(BOOL) updateScheduled;
     BOOL terminated;
     dispatch_queue_t queue;
     dispatch_queue_t lockQueue;

Modified: trunk/bibdesk/BDSKNotesSearchIndex.m
===================================================================
--- trunk/bibdesk/BDSKNotesSearchIndex.m        2022-09-07 16:37:21 UTC (rev 
27868)
+++ trunk/bibdesk/BDSKNotesSearchIndex.m        2022-09-07 16:50:08 UTC (rev 
27869)
@@ -40,7 +40,6 @@
 #import "BibItem.h"
 #import "BDSKStringConstants.h"
 #import "NSURL_BDSKExtensions.h"
-#import <libkern/OSAtomic.h>
 #import <SkimNotesBase/SkimNotesBase.h>
 #import "BibDocument.h"
 #import "BDSKPublicationsArray.h"
@@ -63,8 +62,8 @@
 {
     self = [super init];
     if (self) {
-        shouldKeepRunning = 0;
-        needsFlushing = 0;
+        shouldKeepRunning = NO;
+        needsFlushing = NO;
         terminated = NO;
         
         queue = 
dispatch_queue_create("edu.ucsd.cs.mmccrack.bibdesk.queue.BDSKNotesSearchIndex",
 NULL);
@@ -94,16 +93,15 @@
 }
 
 - (BOOL)shouldKeepRunning{
-    OSMemoryBarrier();
-    return shouldKeepRunning;
+    return atomic_load(&shouldKeepRunning);
 }
 
 - (void)clearQueue
 {
-    OSAtomicCompareAndSwap32Barrier(0, 1, &shouldKeepRunning);
+    atomic_store(&shouldKeepRunning, YES);
     dispatch_sync(queue, ^{});
     if (terminated == NO)
-        OSAtomicCompareAndSwap32Barrier(1, 0, &shouldKeepRunning);
+        atomic_store(&shouldKeepRunning, NO);
 }
 
 - (void)terminate
@@ -118,21 +116,19 @@
 {
     BDSKASSERT([NSThread isMainThread]);
     // Make sure we send frequently enough to update a progress bar, but not 
too frequently to avoid beachball on single-core systems; too many search 
updates slow down indexing due to repeated flushes.
-    OSMemoryBarrier();
-    if (0 == updateScheduled) {
+    if (NO == atomic_load(&updateScheduled)) {
         CGFloat updateDelay = 0.1;
         dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(updateDelay 
* NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
-            OSAtomicCompareAndSwap32Barrier(1, 0, &updateScheduled);
+            atomic_store(&updateScheduled, NO);
             [delegate notesSearchIndexDidUpdate:self];
         });
-        OSAtomicCompareAndSwap32Barrier(0, 1, &updateScheduled);
+        atomic_store(&updateScheduled, YES);
     }
 }
 
 - (void)didUpdate
 {
-    OSMemoryBarrier();
-    if (0 == updateScheduled) {
+    if (NO == atomic_load(&updateScheduled)) {
         dispatch_async(dispatch_get_main_queue(), ^{
             [self searchIndexDidUpdate];
         });
@@ -208,10 +204,9 @@
     dispatch_sync(lockQueue, ^{
         if (skIndex) theIndex = (SKIndexRef)CFRetain(skIndex);
     });
-    OSMemoryBarrier();
-    if (needsFlushing) {
+    if (atomic_load(&needsFlushing)) {
         SKIndexFlush(theIndex);
-        OSAtomicCompareAndSwap32Barrier(1, 0, &needsFlushing);
+        atomic_store(&needsFlushing, NO);
     }
     return (SKIndexRef)[(id)theIndex autorelease];
 }
@@ -269,7 +264,7 @@
                 }
                 CFRelease(theIndex);
                 if (didUpdate) {
-                    OSAtomicCompareAndSwap32Barrier(0, 1, &needsFlushing);
+                    atomic_store(&needsFlushing, YES);
                     [self didUpdate];
                 }
             }

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