diff options
author | Jonathan Dierksen <jedierksen@gmail.com> | 2018-01-22 13:26:39 -0800 |
---|---|---|
committer | Thomas Van Lenten <thomasvl@google.com> | 2018-01-22 16:26:39 -0500 |
commit | a721bf6d294915b412e4ba6b5d92a9b84c6bfef9 (patch) | |
tree | e2650a8219b383a4e622df32a6294b3418a00594 /objectivec | |
parent | 47b7d2c7cadf74ceec90fc5042232819cd0dd557 (diff) |
Migrate away from deprecated OSAtomic APIs. (#4184)
* Migrate away from deprecated OSAtomic APIs.
Diffstat (limited to 'objectivec')
-rw-r--r-- | objectivec/GPBCodedInputStream_PackagePrivate.h | 2 | ||||
-rw-r--r-- | objectivec/GPBMessage.m | 5 | ||||
-rw-r--r-- | objectivec/GPBMessage_PackagePrivate.h | 4 | ||||
-rw-r--r-- | objectivec/google/protobuf/Struct.pbobjc.m | 5 | ||||
-rw-r--r-- | objectivec/google/protobuf/Type.pbobjc.m | 15 |
5 files changed, 17 insertions, 14 deletions
diff --git a/objectivec/GPBCodedInputStream_PackagePrivate.h b/objectivec/GPBCodedInputStream_PackagePrivate.h index 90bd0c92..43ec6e79 100644 --- a/objectivec/GPBCodedInputStream_PackagePrivate.h +++ b/objectivec/GPBCodedInputStream_PackagePrivate.h @@ -34,8 +34,6 @@ #import "GPBCodedInputStream.h" -#import <libkern/OSAtomic.h> - @class GPBUnknownFieldSet; @class GPBFieldDescriptor; diff --git a/objectivec/GPBMessage.m b/objectivec/GPBMessage.m index cc1a650a..a9f8bfe7 100644 --- a/objectivec/GPBMessage.m +++ b/objectivec/GPBMessage.m @@ -32,6 +32,7 @@ #import <objc/runtime.h> #import <objc/message.h> +#import <stdatomic.h> #import "GPBArray_PackagePrivate.h" #import "GPBCodedInputStream_PackagePrivate.h" @@ -742,14 +743,14 @@ void GPBClearMessageAutocreator(GPBMessage *self) { void GPBPrepareReadOnlySemaphore(GPBMessage *self) { #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdirect-ivar-access" -#pragma clang diagnostic ignored "-Wdeprecated-declarations" // Create the semaphore on demand (rather than init) as developers might not cause them // to be needed, and the heap usage can add up. The atomic swap is used to avoid needing // another lock around creating it. if (self->readOnlySemaphore_ == nil) { dispatch_semaphore_t worker = dispatch_semaphore_create(1); - if (!OSAtomicCompareAndSwapPtrBarrier(NULL, worker, (void * volatile *)&(self->readOnlySemaphore_))) { + dispatch_semaphore_t expected = nil; + if (!atomic_compare_exchange_strong(&self->readOnlySemaphore_, &expected, worker)) { dispatch_release(worker); } } diff --git a/objectivec/GPBMessage_PackagePrivate.h b/objectivec/GPBMessage_PackagePrivate.h index 90834d40..c5501c85 100644 --- a/objectivec/GPBMessage_PackagePrivate.h +++ b/objectivec/GPBMessage_PackagePrivate.h @@ -34,7 +34,7 @@ #import "GPBMessage.h" -#import <libkern/OSAtomic.h> +#import <stdatomic.h> #import "GPBBootstrap.h" @@ -70,7 +70,7 @@ typedef struct GPBMessage_Storage *GPBMessage_StoragePtr; // Use of readOnlySemaphore_ must be prefaced by a call to // GPBPrepareReadOnlySemaphore to ensure it has been created. This allows // readOnlySemaphore_ to be only created when actually needed. - dispatch_semaphore_t readOnlySemaphore_; + _Atomic(dispatch_semaphore_t) readOnlySemaphore_; } // Gets an extension value without autocreating the result if not found. (i.e. diff --git a/objectivec/google/protobuf/Struct.pbobjc.m b/objectivec/google/protobuf/Struct.pbobjc.m index f36ec582..dff2f844 100644 --- a/objectivec/google/protobuf/Struct.pbobjc.m +++ b/objectivec/google/protobuf/Struct.pbobjc.m @@ -51,7 +51,7 @@ static GPBFileDescriptor *GPBStructRoot_FileDescriptor(void) { #pragma mark - Enum GPBNullValue GPBEnumDescriptor *GPBNullValue_EnumDescriptor(void) { - static GPBEnumDescriptor *descriptor = NULL; + static _Atomic(GPBEnumDescriptor*) descriptor = NULL; if (!descriptor) { static const char *valueNames = "NullValue\000"; @@ -64,7 +64,8 @@ GPBEnumDescriptor *GPBNullValue_EnumDescriptor(void) { values:values count:(uint32_t)(sizeof(values) / sizeof(int32_t)) enumVerifier:GPBNullValue_IsValidValue]; - if (!OSAtomicCompareAndSwapPtrBarrier(nil, worker, (void * volatile *)&descriptor)) { + GPBEnumDescriptor *expected = nil; + if (!atomic_compare_exchange_strong(&descriptor, &expected, worker)) { [worker release]; } } diff --git a/objectivec/google/protobuf/Type.pbobjc.m b/objectivec/google/protobuf/Type.pbobjc.m index 7a949388..06795308 100644 --- a/objectivec/google/protobuf/Type.pbobjc.m +++ b/objectivec/google/protobuf/Type.pbobjc.m @@ -54,7 +54,7 @@ static GPBFileDescriptor *GPBTypeRoot_FileDescriptor(void) { #pragma mark - Enum GPBSyntax GPBEnumDescriptor *GPBSyntax_EnumDescriptor(void) { - static GPBEnumDescriptor *descriptor = NULL; + static _Atomic(GPBEnumDescriptor*) descriptor = NULL; if (!descriptor) { static const char *valueNames = "SyntaxProto2\000SyntaxProto3\000"; @@ -68,7 +68,8 @@ GPBEnumDescriptor *GPBSyntax_EnumDescriptor(void) { values:values count:(uint32_t)(sizeof(values) / sizeof(int32_t)) enumVerifier:GPBSyntax_IsValidValue]; - if (!OSAtomicCompareAndSwapPtrBarrier(nil, worker, (void * volatile *)&descriptor)) { + GPBEnumDescriptor *expected = nil; + if (!atomic_compare_exchange_strong(&descriptor, &expected, worker)) { [worker release]; } } @@ -368,7 +369,7 @@ void SetGPBField_Cardinality_RawValue(GPBField *message, int32_t value) { #pragma mark - Enum GPBField_Kind GPBEnumDescriptor *GPBField_Kind_EnumDescriptor(void) { - static GPBEnumDescriptor *descriptor = NULL; + static _Atomic(GPBEnumDescriptor*) descriptor = NULL; if (!descriptor) { static const char *valueNames = "TypeUnknown\000TypeDouble\000TypeFloat\000TypeInt" @@ -404,7 +405,8 @@ GPBEnumDescriptor *GPBField_Kind_EnumDescriptor(void) { values:values count:(uint32_t)(sizeof(values) / sizeof(int32_t)) enumVerifier:GPBField_Kind_IsValidValue]; - if (!OSAtomicCompareAndSwapPtrBarrier(nil, worker, (void * volatile *)&descriptor)) { + GPBEnumDescriptor *expected = nil; + if (!atomic_compare_exchange_strong(&descriptor, &expected, worker)) { [worker release]; } } @@ -441,7 +443,7 @@ BOOL GPBField_Kind_IsValidValue(int32_t value__) { #pragma mark - Enum GPBField_Cardinality GPBEnumDescriptor *GPBField_Cardinality_EnumDescriptor(void) { - static GPBEnumDescriptor *descriptor = NULL; + static _Atomic(GPBEnumDescriptor*) descriptor = NULL; if (!descriptor) { static const char *valueNames = "CardinalityUnknown\000CardinalityOptional\000C" @@ -458,7 +460,8 @@ GPBEnumDescriptor *GPBField_Cardinality_EnumDescriptor(void) { values:values count:(uint32_t)(sizeof(values) / sizeof(int32_t)) enumVerifier:GPBField_Cardinality_IsValidValue]; - if (!OSAtomicCompareAndSwapPtrBarrier(nil, worker, (void * volatile *)&descriptor)) { + GPBEnumDescriptor *expected = nil; + if (!atomic_compare_exchange_strong(&descriptor, &expected, worker)) { [worker release]; } } |