Skip to content

Commit

Permalink
Small code updates
Browse files Browse the repository at this point in the history
- add a couple of atomics API updates missed from fc4f4a2
- mark C functions taking no arguments as `(void)`
  • Loading branch information
bangnoise committed Apr 11, 2023
1 parent 8262732 commit 991da55
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 11 deletions.
4 changes: 2 additions & 2 deletions SyphonDispatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ static atomic_uintptr_t mWorkDoneSignal = (uintptr_t)NULL;
#pragma mark Constructor and Destructor

__attribute__((destructor))
static void finalizer()
static void finalizer(void)
{
struct timeval start;
if(gettimeofday(&start, NULL) == 0)
Expand Down Expand Up @@ -181,7 +181,7 @@ static void *_SyphonDispatchChannelLoop(SyphonDispatchChannel *channel)
return NULL;
}

static dispatch_semaphore_t _SyphonDispatchGetWorkSemaphore()
static dispatch_semaphore_t _SyphonDispatchGetWorkSemaphore(void)
{
dispatch_semaphore_t sem = (dispatch_semaphore_t)atomic_load(&mWorkDoneSignal);
if (!sem)
Expand Down
10 changes: 5 additions & 5 deletions SyphonMessageQueue.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
*/

#import "SyphonMessageQueue.h"
#import <libkern/OSAtomic.h>
#import <stdatomic.h>
#import <os/lock.h>

/*
Expand Down Expand Up @@ -72,7 +72,7 @@ @implementation SyphonMessageQueue
os_unfair_lock _lock;
void *_head;
OSQueueHead _pool; // TODO: or maybe manage our own within the lock as we lock anyway
void *_info;
atomic_uintptr_t _info;
}

- (id)init
Expand Down Expand Up @@ -186,15 +186,15 @@ - (BOOL)copyAndDequeue:(NSData **)content type:(uint32_t *)type

- (void *)userInfo
{
return _info;
return (void *)atomic_load(&_info);
}

- (void)setUserInfo:(void *)info
{
bool result;
do {
void *old = _info;
result = OSAtomicCompareAndSwapPtrBarrier(old, info, &_info);
uintptr_t old = _info;
result = atomic_compare_exchange_strong(&_info, &old, (uintptr_t)info);
} while (!result);
}
@end
4 changes: 3 additions & 1 deletion SyphonPrivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@

#ifdef __OBJC__

#import <stdatomic.h> // For SyphonSafeBool

#define kSyphonIdentifier @"info.v002.Syphon"

// NSNotification names for Syphon's distributed notifications
Expand Down Expand Up @@ -60,7 +62,7 @@ extern NSString * const SyphonServerOptionStencilBufferResolution;

NSString *SyphonCreateUUIDString(void) NS_RETURNS_RETAINED;

typedef volatile int32_t SyphonSafeBool;
typedef atomic_int_fast32_t SyphonSafeBool;

BOOL SyphonSafeBoolGet(SyphonSafeBool *b);
void SyphonSafeBoolSet(SyphonSafeBool *b, BOOL value);
Expand Down
3 changes: 1 addition & 2 deletions SyphonPrivate.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
*/

#import "SyphonPrivate.h"
#import <libkern/OSAtomic.h> // For SyphonSafeBool

NSString * const SyphonServerDescriptionDictionaryVersionKey = @"SyphonServerDescriptionDictionaryVersionKey";
NSString * const SyphonServerDescriptionUUIDKey = @"SyphonServerDescriptionUUIDKey";
Expand Down Expand Up @@ -67,6 +66,6 @@ void SyphonSafeBoolSet(SyphonSafeBool *b, BOOL value)
int32_t new = value ? 1 : 0;
do {
int32_t old = *b;
result = OSAtomicCompareAndSwap32(old, new, b);
result = atomic_compare_exchange_strong(b, &old, new);
} while (!result);
}
2 changes: 1 addition & 1 deletion SyphonServerBase.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ + (void)retireRemainingServers;
@end

__attribute__((destructor))
static void finalizer()
static void finalizer(void)
{
[SyphonServerBase retireRemainingServers];
}
Expand Down

0 comments on commit 991da55

Please sign in to comment.