Migrate away from deprecated OSAtomic APIs. (#4184)

* Migrate away from deprecated OSAtomic APIs.
pull/4214/head
Jonathan Dierksen 7 years ago committed by Thomas Van Lenten
parent 47b7d2c7ca
commit a721bf6d29
  1. 2
      objectivec/GPBCodedInputStream_PackagePrivate.h
  2. 5
      objectivec/GPBMessage.m
  3. 4
      objectivec/GPBMessage_PackagePrivate.h
  4. 5
      objectivec/google/protobuf/Struct.pbobjc.m
  5. 15
      objectivec/google/protobuf/Type.pbobjc.m
  6. 5
      src/google/protobuf/compiler/objectivec/objectivec_enum.cc

@ -34,8 +34,6 @@
#import "GPBCodedInputStream.h" #import "GPBCodedInputStream.h"
#import <libkern/OSAtomic.h>
@class GPBUnknownFieldSet; @class GPBUnknownFieldSet;
@class GPBFieldDescriptor; @class GPBFieldDescriptor;

@ -32,6 +32,7 @@
#import <objc/runtime.h> #import <objc/runtime.h>
#import <objc/message.h> #import <objc/message.h>
#import <stdatomic.h>
#import "GPBArray_PackagePrivate.h" #import "GPBArray_PackagePrivate.h"
#import "GPBCodedInputStream_PackagePrivate.h" #import "GPBCodedInputStream_PackagePrivate.h"
@ -742,14 +743,14 @@ void GPBClearMessageAutocreator(GPBMessage *self) {
void GPBPrepareReadOnlySemaphore(GPBMessage *self) { void GPBPrepareReadOnlySemaphore(GPBMessage *self) {
#pragma clang diagnostic push #pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdirect-ivar-access" #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 // 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 // to be needed, and the heap usage can add up. The atomic swap is used to avoid needing
// another lock around creating it. // another lock around creating it.
if (self->readOnlySemaphore_ == nil) { if (self->readOnlySemaphore_ == nil) {
dispatch_semaphore_t worker = dispatch_semaphore_create(1); 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); dispatch_release(worker);
} }
} }

@ -34,7 +34,7 @@
#import "GPBMessage.h" #import "GPBMessage.h"
#import <libkern/OSAtomic.h> #import <stdatomic.h>
#import "GPBBootstrap.h" #import "GPBBootstrap.h"
@ -70,7 +70,7 @@ typedef struct GPBMessage_Storage *GPBMessage_StoragePtr;
// Use of readOnlySemaphore_ must be prefaced by a call to // Use of readOnlySemaphore_ must be prefaced by a call to
// GPBPrepareReadOnlySemaphore to ensure it has been created. This allows // GPBPrepareReadOnlySemaphore to ensure it has been created. This allows
// readOnlySemaphore_ to be only created when actually needed. // 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. // Gets an extension value without autocreating the result if not found. (i.e.

@ -51,7 +51,7 @@ static GPBFileDescriptor *GPBStructRoot_FileDescriptor(void) {
#pragma mark - Enum GPBNullValue #pragma mark - Enum GPBNullValue
GPBEnumDescriptor *GPBNullValue_EnumDescriptor(void) { GPBEnumDescriptor *GPBNullValue_EnumDescriptor(void) {
static GPBEnumDescriptor *descriptor = NULL; static _Atomic(GPBEnumDescriptor*) descriptor = NULL;
if (!descriptor) { if (!descriptor) {
static const char *valueNames = static const char *valueNames =
"NullValue\000"; "NullValue\000";
@ -64,7 +64,8 @@ GPBEnumDescriptor *GPBNullValue_EnumDescriptor(void) {
values:values values:values
count:(uint32_t)(sizeof(values) / sizeof(int32_t)) count:(uint32_t)(sizeof(values) / sizeof(int32_t))
enumVerifier:GPBNullValue_IsValidValue]; enumVerifier:GPBNullValue_IsValidValue];
if (!OSAtomicCompareAndSwapPtrBarrier(nil, worker, (void * volatile *)&descriptor)) { GPBEnumDescriptor *expected = nil;
if (!atomic_compare_exchange_strong(&descriptor, &expected, worker)) {
[worker release]; [worker release];
} }
} }

@ -54,7 +54,7 @@ static GPBFileDescriptor *GPBTypeRoot_FileDescriptor(void) {
#pragma mark - Enum GPBSyntax #pragma mark - Enum GPBSyntax
GPBEnumDescriptor *GPBSyntax_EnumDescriptor(void) { GPBEnumDescriptor *GPBSyntax_EnumDescriptor(void) {
static GPBEnumDescriptor *descriptor = NULL; static _Atomic(GPBEnumDescriptor*) descriptor = NULL;
if (!descriptor) { if (!descriptor) {
static const char *valueNames = static const char *valueNames =
"SyntaxProto2\000SyntaxProto3\000"; "SyntaxProto2\000SyntaxProto3\000";
@ -68,7 +68,8 @@ GPBEnumDescriptor *GPBSyntax_EnumDescriptor(void) {
values:values values:values
count:(uint32_t)(sizeof(values) / sizeof(int32_t)) count:(uint32_t)(sizeof(values) / sizeof(int32_t))
enumVerifier:GPBSyntax_IsValidValue]; enumVerifier:GPBSyntax_IsValidValue];
if (!OSAtomicCompareAndSwapPtrBarrier(nil, worker, (void * volatile *)&descriptor)) { GPBEnumDescriptor *expected = nil;
if (!atomic_compare_exchange_strong(&descriptor, &expected, worker)) {
[worker release]; [worker release];
} }
} }
@ -368,7 +369,7 @@ void SetGPBField_Cardinality_RawValue(GPBField *message, int32_t value) {
#pragma mark - Enum GPBField_Kind #pragma mark - Enum GPBField_Kind
GPBEnumDescriptor *GPBField_Kind_EnumDescriptor(void) { GPBEnumDescriptor *GPBField_Kind_EnumDescriptor(void) {
static GPBEnumDescriptor *descriptor = NULL; static _Atomic(GPBEnumDescriptor*) descriptor = NULL;
if (!descriptor) { if (!descriptor) {
static const char *valueNames = static const char *valueNames =
"TypeUnknown\000TypeDouble\000TypeFloat\000TypeInt" "TypeUnknown\000TypeDouble\000TypeFloat\000TypeInt"
@ -404,7 +405,8 @@ GPBEnumDescriptor *GPBField_Kind_EnumDescriptor(void) {
values:values values:values
count:(uint32_t)(sizeof(values) / sizeof(int32_t)) count:(uint32_t)(sizeof(values) / sizeof(int32_t))
enumVerifier:GPBField_Kind_IsValidValue]; enumVerifier:GPBField_Kind_IsValidValue];
if (!OSAtomicCompareAndSwapPtrBarrier(nil, worker, (void * volatile *)&descriptor)) { GPBEnumDescriptor *expected = nil;
if (!atomic_compare_exchange_strong(&descriptor, &expected, worker)) {
[worker release]; [worker release];
} }
} }
@ -441,7 +443,7 @@ BOOL GPBField_Kind_IsValidValue(int32_t value__) {
#pragma mark - Enum GPBField_Cardinality #pragma mark - Enum GPBField_Cardinality
GPBEnumDescriptor *GPBField_Cardinality_EnumDescriptor(void) { GPBEnumDescriptor *GPBField_Cardinality_EnumDescriptor(void) {
static GPBEnumDescriptor *descriptor = NULL; static _Atomic(GPBEnumDescriptor*) descriptor = NULL;
if (!descriptor) { if (!descriptor) {
static const char *valueNames = static const char *valueNames =
"CardinalityUnknown\000CardinalityOptional\000C" "CardinalityUnknown\000CardinalityOptional\000C"
@ -458,7 +460,8 @@ GPBEnumDescriptor *GPBField_Cardinality_EnumDescriptor(void) {
values:values values:values
count:(uint32_t)(sizeof(values) / sizeof(int32_t)) count:(uint32_t)(sizeof(values) / sizeof(int32_t))
enumVerifier:GPBField_Cardinality_IsValidValue]; enumVerifier:GPBField_Cardinality_IsValidValue];
if (!OSAtomicCompareAndSwapPtrBarrier(nil, worker, (void * volatile *)&descriptor)) { GPBEnumDescriptor *expected = nil;
if (!atomic_compare_exchange_strong(&descriptor, &expected, worker)) {
[worker release]; [worker release];
} }
} }

@ -149,7 +149,7 @@ void EnumGenerator::GenerateSource(io::Printer* printer) {
printer->Print( printer->Print(
"GPBEnumDescriptor *$name$_EnumDescriptor(void) {\n" "GPBEnumDescriptor *$name$_EnumDescriptor(void) {\n"
" static GPBEnumDescriptor *descriptor = NULL;\n" " static _Atomic(GPBEnumDescriptor*) descriptor = NULL;\n"
" if (!descriptor) {\n", " if (!descriptor) {\n",
"name", name_); "name", name_);
@ -192,7 +192,8 @@ void EnumGenerator::GenerateSource(io::Printer* printer) {
"extraTextFormatInfo", CEscape(text_format_decode_data.Data())); "extraTextFormatInfo", CEscape(text_format_decode_data.Data()));
} }
printer->Print( printer->Print(
" if (!OSAtomicCompareAndSwapPtrBarrier(nil, worker, (void * volatile *)&descriptor)) {\n" " GPBEnumDescriptor *expected = nil;\n"
" if (!atomic_compare_exchange_strong(&descriptor, &expected, worker)) {\n"
" [worker release];\n" " [worker release];\n"
" }\n" " }\n"
" }\n" " }\n"

Loading…
Cancel
Save