Revision: 27870
http://sourceforge.net/p/bibdesk/svn/27870
Author: hofman
Date: 2022-09-07 22:06:46 +0000 (Wed, 07 Sep 2022)
Log Message:
-----------
use stdatomic rather than OSAtomic for BDSKTask
Modified Paths:
--------------
trunk/bibdesk/BDSKTask.h
trunk/bibdesk/BDSKTask.m
Modified: trunk/bibdesk/BDSKTask.h
===================================================================
--- trunk/bibdesk/BDSKTask.h 2022-09-07 16:50:08 UTC (rev 27869)
+++ trunk/bibdesk/BDSKTask.h 2022-09-07 22:06:46 UTC (rev 27870)
@@ -37,6 +37,7 @@
*/
#import <Cocoa/Cocoa.h>
+#import <stdatomic.h>
/** @brief Concrete subclass of NSTask.
@@ -60,10 +61,10 @@
id _standardOutput;
id _standardError;
pid_t _processIdentifier;
- int32_t _terminationStatus;
+ _Atomic(int) _terminationStatus;
NSTaskTerminationReason _terminationReason;
- int32_t _running;
- int32_t _launched;
+ _Atomic(BOOL) _running;
+ _Atomic(BOOL) _launched;
struct BDSKTaskInternal *_internal;
}
Modified: trunk/bibdesk/BDSKTask.m
===================================================================
--- trunk/bibdesk/BDSKTask.m 2022-09-07 16:50:08 UTC (rev 27869)
+++ trunk/bibdesk/BDSKTask.m 2022-09-07 22:06:46 UTC (rev 27870)
@@ -37,7 +37,6 @@
*/
#import "BDSKTask.h"
-#import <libkern/OSAtomic.h>
#import <crt_externs.h>
#import <sys/types.h>
#import <sys/event.h>
@@ -84,8 +83,8 @@
return task;
}
-#define ASSERT_LAUNCH do { if (!_launched) { [NSException
raise:@"BDSKTaskException" format:@"Task has not been launched"]; } } while (0)
-#define ASSERT_NOTLAUNCHED do { if (_launched) { [NSException
raise:@"BDSKTaskException" format:@"Task has already been launched"]; } } while
(0)
+#define ASSERT_LAUNCH do { if (!atomic_load(&_launched)) { [NSException
raise:@"BDSKTaskException" format:@"Task has not been launched"]; } } while (0)
+#define ASSERT_NOTLAUNCHED do { if (atomic_load(&_launched)) { [NSException
raise:@"BDSKTaskException" format:@"Task has already been launched"]; } } while
(0)
- (id)init
{
@@ -371,7 +370,7 @@
// parent: error
int forkError = errno;
NSLog(@"fork() failed in task %@: %s", self, strerror(forkError));
- _terminationStatus = 2;
+ atomic_store(&_terminationStatus, 2);
// clean up what we can
[handlesToClose makeObjectsPerformSelector:@selector(closeFile)];
@@ -383,8 +382,8 @@
// parent process
// CASB probably not necessary anymore...
- OSAtomicCompareAndSwap32Barrier(0, 1, &_running);
- OSAtomicCompareAndSwap32Barrier(0, 1, &_launched);
+ atomic_store(&_running, YES);
+ atomic_store(&_launched, YES);
// NSTask docs say that these descriptors are closed in the parent
task; required to make pipes work properly
[handlesToClose makeObjectsPerformSelector:@selector(closeFile)];
@@ -466,13 +465,13 @@
return _processIdentifier;
}
-- (BOOL)isRunning; { return (0 != _running); }
+- (BOOL)isRunning; { return atomic_load(&_running); }
- (int)terminationStatus;
{
ASSERT_LAUNCH;
if ([self isRunning]) [NSException raise:NSInternalInconsistencyException
format:@"Task is still running"];
- return _terminationStatus;
+ return atomic_load(&_terminationStatus);
}
- (NSTaskTerminationReason)terminationReason;
@@ -657,12 +656,14 @@
// set return value, then set isRunning to false
do {
- swap = OSAtomicCompareAndSwap32Barrier(_terminationStatus, ret,
&_terminationStatus);
+ int expect = _terminationStatus;
+ swap = atomic_compare_exchange_strong(&_terminationStatus, &expect,
ret);
} while (false == swap);
do {
- swap = OSAtomicCompareAndSwap32Barrier(_running, 0, &_running);
- } while (false == swap);
+ BOOL expect = _running;
+ swap = atomic_compare_exchange_strong(&_running, &expect, NO);
+ } while (false == swap);
/*
Transfer ownership through the callout to avoid dealloc. Lock runloop
source access
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