1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-10-18 23:23:56 +00:00

Merge pull request #119 from TomHarte/C11

Ejects the deprecated OSAtomicTestAnd[Re]Set test-and-[re]set in favour of C11's atomic_flag.
This commit is contained in:
Thomas Harte 2017-04-15 21:45:48 -04:00 committed by GitHub
commit 26cb903b08

View File

@ -8,10 +8,12 @@
#import "CSBestEffortUpdater.h" #import "CSBestEffortUpdater.h"
#include <stdatomic.h>
@implementation CSBestEffortUpdater @implementation CSBestEffortUpdater
{ {
// these are inherently handled only by thread-safe constructions // these are inherently handled only by thread-safe constructions
uint32_t _updateIsOngoing; atomic_flag _updateIsOngoing;
dispatch_queue_t _serialDispatchQueue; dispatch_queue_t _serialDispatchQueue;
// these are permitted for modification on _serialDispatchQueue only // these are permitted for modification on _serialDispatchQueue only
@ -25,16 +27,18 @@
if(self = [super init]) if(self = [super init])
{ {
_serialDispatchQueue = dispatch_queue_create("Best Effort Updater", DISPATCH_QUEUE_SERIAL); _serialDispatchQueue = dispatch_queue_create("Best Effort Updater", DISPATCH_QUEUE_SERIAL);
// This is a workaround for assigning the correct initial value within Objective-C's form.
atomic_flag initialFlagValue = ATOMIC_FLAG_INIT;
_updateIsOngoing = initialFlagValue;
} }
return self; return self;
} }
- (void)update - (void)update
{ {
const uint32_t processingMask = 0x01;
// Always post an -openGLView:didUpdateToTime: if a previous one isn't still ongoing. This is the hook upon which the substantial processing occurs. // Always post an -openGLView:didUpdateToTime: if a previous one isn't still ongoing. This is the hook upon which the substantial processing occurs.
if(!OSAtomicTestAndSet(processingMask, &_updateIsOngoing)) if(!atomic_flag_test_and_set(&_updateIsOngoing))
{ {
dispatch_async(_serialDispatchQueue, ^{ dispatch_async(_serialDispatchQueue, ^{
NSTimeInterval timeInterval = [NSDate timeIntervalSinceReferenceDate]; NSTimeInterval timeInterval = [NSDate timeIntervalSinceReferenceDate];
@ -52,7 +56,7 @@
} }
_previousTimeInterval = timeInterval; _previousTimeInterval = timeInterval;
_hasSkipped = NO; _hasSkipped = NO;
OSAtomicTestAndClear(processingMask, &_updateIsOngoing); atomic_flag_clear(&_updateIsOngoing);
}); });
} }
else else