aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--objectivec/GPBCodedInputStream_PackagePrivate.h2
-rw-r--r--objectivec/GPBMessage.m5
-rw-r--r--objectivec/GPBMessage_PackagePrivate.h4
-rw-r--r--objectivec/google/protobuf/Struct.pbobjc.m5
-rw-r--r--objectivec/google/protobuf/Type.pbobjc.m15
-rw-r--r--src/google/protobuf/compiler/objectivec/objectivec_enum.cc5
6 files changed, 20 insertions, 16 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];
}
}
diff --git a/src/google/protobuf/compiler/objectivec/objectivec_enum.cc b/src/google/protobuf/compiler/objectivec/objectivec_enum.cc
index 02d60b3e..95e53f19 100644
--- a/src/google/protobuf/compiler/objectivec/objectivec_enum.cc
+++ b/src/google/protobuf/compiler/objectivec/objectivec_enum.cc
@@ -149,7 +149,7 @@ void EnumGenerator::GenerateSource(io::Printer* printer) {
printer->Print(
"GPBEnumDescriptor *$name$_EnumDescriptor(void) {\n"
- " static GPBEnumDescriptor *descriptor = NULL;\n"
+ " static _Atomic(GPBEnumDescriptor*) descriptor = NULL;\n"
" if (!descriptor) {\n",
"name", name_);
@@ -192,7 +192,8 @@ void EnumGenerator::GenerateSource(io::Printer* printer) {
"extraTextFormatInfo", CEscape(text_format_decode_data.Data()));
}
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"
" }\n"
" }\n"