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

Modified Paths:
--------------
    trunk/bibdesk/BDSKFileMatcher.h
    trunk/bibdesk/BDSKFileMatcher.m
    trunk/bibdesk/BDSKMetadataCacheOperation.m
    trunk/bibdesk/BDSKOrphanedFilesFinder.h
    trunk/bibdesk/BDSKOrphanedFilesFinder.m

Modified: trunk/bibdesk/BDSKFileMatcher.h
===================================================================
--- trunk/bibdesk/BDSKFileMatcher.h     2022-09-07 16:21:36 UTC (rev 27867)
+++ trunk/bibdesk/BDSKFileMatcher.h     2022-09-07 16:37:21 UTC (rev 27868)
@@ -38,6 +38,7 @@
 
 #import <Cocoa/Cocoa.h>
 #import <Quartz/Quartz.h>
+#import <stdatomic.h>
 
 @class BDSKOutlineView;
 
@@ -52,7 +53,7 @@
     NSMutableArray *matches;
     dispatch_group_t group;
     struct __matchFlags {
-        int32_t shouldAbort;
+        _Atomic(BOOL) shouldAbort;
     } _matchFlags;
     
     BOOL documentWasRemoved;

Modified: trunk/bibdesk/BDSKFileMatcher.m
===================================================================
--- trunk/bibdesk/BDSKFileMatcher.m     2022-09-07 16:21:36 UTC (rev 27867)
+++ trunk/bibdesk/BDSKFileMatcher.m     2022-09-07 16:37:21 UTC (rev 27868)
@@ -44,7 +44,6 @@
 #import "BibDocument_Actions.h"
 #import "NSImage_BDSKExtensions.h"
 #import "BibAuthor.h"
-#import <libkern/OSAtomic.h>
 #import "BDSKFileMatchConfigController.h"
 #import "BDSKOutlineView.h"
 #import "NSGeometry_BDSKExtensions.h"
@@ -106,7 +105,7 @@
     self = [super initWithWindowNibName:[self windowNibName]];
     if (self) {
         matches = [[NSMutableArray alloc] init];
-        _matchFlags.shouldAbort = 0;
+        _matchFlags.shouldAbort = NO;
     }
     return self;
 }
@@ -168,7 +167,7 @@
 
     // wait for the current aborted block is finished
     if (group) {
-        OSAtomicCompareAndSwap32Barrier(0, 1, &_matchFlags.shouldAbort);
+        atomic_store(&_matchFlags.shouldAbort, YES);
         dispatch_group_wait(group, DISPATCH_TIME_FOREVER); 
     } else {
         group = dispatch_group_create();
@@ -177,7 +176,7 @@
     [matches removeAllObjects];
     [outlineView reloadData];
     
-    OSAtomicCompareAndSwap32Barrier(1, 0, &_matchFlags.shouldAbort);
+    atomic_store(&_matchFlags.shouldAbort, NO);
     
     // get the root nodes array on the main thread, since it uses BibItem 
methods
     NSArray *treeNodes = [self copyTreeNodesWithPublications:pubs];
@@ -202,7 +201,8 @@
 
 - (IBAction)abort:(id)sender;
 {
-    if (false == OSAtomicCompareAndSwap32Barrier(0, 1, 
&_matchFlags.shouldAbort))
+    BOOL expected = NO;
+    if (NO == atomic_compare_exchange_strong(&_matchFlags.shouldAbort, 
&expected, YES))
         NSBeep();
     [abortButton setEnabled:NO];
     [progressIndicator stopAnimation:nil];
@@ -473,7 +473,7 @@
     
     for (BDSKTreeNode *node in pubNodes) {
     
-        if (_matchFlags.shouldAbort) break;
+        if (atomic_load(&_matchFlags.shouldAbort)) break;
         
         NSAutoreleasePool *pool = [NSAutoreleasePool new];
         
@@ -543,7 +543,7 @@
         [pool drain];
     }
     
-    if (0 == _matchFlags.shouldAbort) {
+    if (NO == atomic_load(&_matchFlags.shouldAbort)) {
         dispatch_async(dispatch_get_main_queue(), ^{
             [progressIndicator setDoubleValue:(1.0)];
             [statusField setStringValue:NSLocalizedString(@"Search complete!", 
@"")];
@@ -587,7 +587,7 @@
     BOOL shouldLog = [[NSUserDefaults standardUserDefaults] 
boolForKey:BDSKShouldLogFilesAddedToMatchingSearchIndexKey];
     
     for (NSURL *url in fileURLs) {
-        if (_matchFlags.shouldAbort) break;
+        if (atomic_load(&_matchFlags.shouldAbort)) break;
         
         SKDocumentRef doc = SKDocumentCreateWithURL((CFURLRef)url);
         
@@ -605,7 +605,7 @@
         });
     }
     
-    if (0 == _matchFlags.shouldAbort) {
+    if (NO == atomic_load(&_matchFlags.shouldAbort)) {
         dispatch_async(dispatch_get_main_queue(), ^{
             [progressIndicator setDoubleValue:(1.0)];
             [statusField setStringValue:NSLocalizedString(@"Indexing 
complete!", @"")];

Modified: trunk/bibdesk/BDSKMetadataCacheOperation.m
===================================================================
--- trunk/bibdesk/BDSKMetadataCacheOperation.m  2022-09-07 16:21:36 UTC (rev 
27867)
+++ trunk/bibdesk/BDSKMetadataCacheOperation.m  2022-09-07 16:37:21 UTC (rev 
27868)
@@ -41,7 +41,6 @@
 #import "NSError_BDSKExtensions.h"
 #import "NSURL_BDSKExtensions.h"
 #import "BibItem.h"
-#import <libkern/OSAtomic.h>
 
 #define BDSKUseXMLSpotlightCacheKey @"BDSKUseXMLSpotlightCache"
 

Modified: trunk/bibdesk/BDSKOrphanedFilesFinder.h
===================================================================
--- trunk/bibdesk/BDSKOrphanedFilesFinder.h     2022-09-07 16:21:36 UTC (rev 
27867)
+++ trunk/bibdesk/BDSKOrphanedFilesFinder.h     2022-09-07 16:37:21 UTC (rev 
27868)
@@ -39,6 +39,7 @@
 #import <Cocoa/Cocoa.h>
 #import <Quartz/Quartz.h>
 #import "BDSKTableView.h"
+#import <stdatomic.h>
 
 @class BDSKTableView;
 
@@ -57,8 +58,8 @@
     NSArray *draggedFiles;
     NSMutableArray *foundFiles;
     dispatch_queue_t queue;
-    int32_t keepEnumerating;
-    int32_t allFilesEnumerated;
+    _Atomic(BOOL) keepEnumerating;
+    _Atomic(BOOL) allFilesEnumerated;
 }
 
 + (id)sharedFinder;

Modified: trunk/bibdesk/BDSKOrphanedFilesFinder.m
===================================================================
--- trunk/bibdesk/BDSKOrphanedFilesFinder.m     2022-09-07 16:21:36 UTC (rev 
27867)
+++ trunk/bibdesk/BDSKOrphanedFilesFinder.m     2022-09-07 16:37:21 UTC (rev 
27868)
@@ -54,7 +54,6 @@
 #import "BDSKTableView.h"
 #import "NSMenu_BDSKExtensions.h"
 #import "NSPasteboard_BDSKExtensions.h"
-#import <libkern/OSAtomic.h>
 #import "NSEvent_BDSKExtensions.h"
 #import "NSView_BDSKExtensions.h"
 #import "BDSKFileImageTransformer.h"
@@ -485,12 +484,12 @@
 {
     // set the stop flag so enumeration ceases
     // CMH: is this necessary, shouldn't we already be done as we're on the 
same thread?
-    OSAtomicCompareAndSwap32Barrier(1, 0, &keepEnumerating);
+    atomic_store(&keepEnumerating, NO);
     
     [self clearFoundFiles];
     
-    OSAtomicCompareAndSwap32Barrier(0, 1, &keepEnumerating);
-    OSAtomicCompareAndSwap32Barrier(1, 0, &allFilesEnumerated);
+    atomic_store(&keepEnumerating, YES);
+    atomic_store(&allFilesEnumerated, NO);
     
     // increase file limit for enumerating a home directory 
http://developer.apple.com/qa/qa2001/qa1292.html
     struct rlimit limit;
@@ -507,8 +506,7 @@
     NSDirectoryEnumerator *dirEnum = [fm enumeratorAtURL:theURL 
includingPropertiesForKeys:[NSArray arrayWithObjects:NSURLIsDirectoryKey, 
NSURLIsPackageKey, nil] options:NSDirectoryEnumerationSkipsHiddenFiles 
errorHandler:nil];
     
     for (NSURL *aURL in dirEnum) {
-        OSMemoryBarrier();
-        if (0 == keepEnumerating)
+        if (NO == atomic_load(&keepEnumerating))
             break;
         
         if ([foundFiles count] >= 16)
@@ -528,9 +526,8 @@
     [self flushFoundFiles];
     
     // keepEnumerating is 0 when enumeration was stopped
-    OSMemoryBarrier();
-    if (keepEnumerating == 1)
-        OSAtomicCompareAndSwap32Barrier(0, 1, &allFilesEnumerated);
+    if (atomic_load(&keepEnumerating) == YES)
+        atomic_store(&allFilesEnumerated, YES);
     
     // notify the delegate that we're done
     dispatch_async(dispatch_get_main_queue(), ^{
@@ -563,8 +560,8 @@
     [foundFiles removeAllObjects];
 }
 
-- (BOOL)allFilesEnumerated { OSMemoryBarrier(); return (BOOL)(1 == 
allFilesEnumerated); }
+- (BOOL)allFilesEnumerated { return YES == atomic_load(&allFilesEnumerated); }
 
-- (void)stopEnumerating { OSAtomicCompareAndSwap32Barrier(1, 0, 
&keepEnumerating); }
+- (void)stopEnumerating { atomic_store(&keepEnumerating, NO); }
 
 @end

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