Skip to content
This repository has been archived by the owner on Feb 19, 2020. It is now read-only.

Replace deprecated api calls #501

Merged
merged 1 commit into from
Jan 8, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions Classes/BITChannel.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#import "BITDevice.h"
#import "BITPersistencePrivate.h"
#import "BITSender.h"
#import <libkern/OSAtomic.h>
#import <stdatomic.h>


static char *const BITDataItemsOperationsQueue = "net.hockeyapp.senderQueue";
Expand All @@ -29,6 +29,8 @@
static NSInteger const BITDebugMaxBatchSize = 5;
static NSInteger const BITDebugBatchInterval = 3;

typedef _Atomic(char*) atomic_charptr;

NS_ASSUME_NONNULL_BEGIN

@interface BITChannel ()
Expand Down Expand Up @@ -137,7 +139,7 @@ - (void)persistDataItemQueue:(char **)eventBuffer {
previousBuffer = *eventBuffer;

// This swaps pointers and makes sure eventBuffer now has the balue of newEmptyString.
if (OSAtomicCompareAndSwapPtr(previousBuffer, newEmptyString, (void*)eventBuffer)) {
if (atomic_compare_exchange_strong((atomic_charptr *)eventBuffer, &previousBuffer, newEmptyString)) {
@synchronized(self) {
self.dataItemCount = 0;
}
Expand Down Expand Up @@ -403,7 +405,7 @@ void bit_appendStringToEventBuffer(NSString *string, char **eventBuffer) {
asprintf(&newBuffer, "%s%.*s\n", previousBuffer, (int)MIN(string.length, (NSUInteger)INT_MAX), string.UTF8String);

// Compare newBuffer and previousBuffer. If they point to the same address, we are safe to use them.
if (OSAtomicCompareAndSwapPtr(previousBuffer, newBuffer, (void*)eventBuffer)) {
if (atomic_compare_exchange_strong((atomic_charptr *)eventBuffer, &previousBuffer, newBuffer)) {

// Free the intermediate pointer.
free(previousBuffer);
Expand All @@ -426,7 +428,7 @@ void bit_resetEventBuffer(char **eventBuffer) {
newEmptyString = strdup("");

// Compare pointers to strings to make sure we are still threadsafe!
if (OSAtomicCompareAndSwapPtr(prevString, newEmptyString, (void*)eventBuffer)) {
if (atomic_compare_exchange_strong((atomic_charptr *)eventBuffer, &prevString, newEmptyString)) {
free(prevString);
return;
}
Expand Down