aboutsummaryrefslogtreecommitdiff
path: root/objectivec/GPBMessage.m
diff options
context:
space:
mode:
authorThomas Van Lenten <thomasvl@google.com>2016-03-21 11:11:14 -0400
committerThomas Van Lenten <thomasvl@google.com>2016-03-21 11:11:14 -0400
commitbd41a39f693d8307d407e42b634b315e075b6c8f (patch)
tree018b7755a546f18ee54e3fc48d6f8c69fdbcc67d /objectivec/GPBMessage.m
parent5e933847cc9e7826f1a9ee8b3dc1df4960b1ea5d (diff)
downloadprotobuf-bd41a39f693d8307d407e42b634b315e075b6c8f.tar.gz
protobuf-bd41a39f693d8307d407e42b634b315e075b6c8f.tar.bz2
protobuf-bd41a39f693d8307d407e42b634b315e075b6c8f.zip
Only create the readonlySemaphore on demand.
This will lower the amount of dispatch_semaphores created per Message when the full object tree isn't walked in a way that would require them to be created. Uses a dispatch_once_t for one time init of the dispatch_semaphore.
Diffstat (limited to 'objectivec/GPBMessage.m')
-rw-r--r--objectivec/GPBMessage.m9
1 files changed, 6 insertions, 3 deletions
diff --git a/objectivec/GPBMessage.m b/objectivec/GPBMessage.m
index 94d179be..3da85b5b 100644
--- a/objectivec/GPBMessage.m
+++ b/objectivec/GPBMessage.m
@@ -556,6 +556,7 @@ static id GetArrayIvarWithField(GPBMessage *self, GPBFieldDescriptor *field) {
id array = GPBGetObjectIvarWithFieldNoAutocreate(self, field);
if (!array) {
// Check again after getting the lock.
+ GPBPrepareReadOnlySemaphore(self);
dispatch_semaphore_wait(self->readOnlySemaphore_, DISPATCH_TIME_FOREVER);
array = GPBGetObjectIvarWithFieldNoAutocreate(self, field);
if (!array) {
@@ -586,6 +587,7 @@ static id GetMapIvarWithField(GPBMessage *self, GPBFieldDescriptor *field) {
id dict = GPBGetObjectIvarWithFieldNoAutocreate(self, field);
if (!dict) {
// Check again after getting the lock.
+ GPBPrepareReadOnlySemaphore(self);
dispatch_semaphore_wait(self->readOnlySemaphore_, DISPATCH_TIME_FOREVER);
dict = GPBGetObjectIvarWithFieldNoAutocreate(self, field);
if (!dict) {
@@ -791,8 +793,6 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) {
if ((self = [super init])) {
messageStorage_ = (GPBMessage_StoragePtr)(
((uint8_t *)self) + class_getInstanceSize([self class]));
-
- readOnlySemaphore_ = dispatch_semaphore_create(1);
}
return self;
@@ -868,7 +868,9 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) {
- (void)dealloc {
[self internalClear:NO];
NSCAssert(!autocreator_, @"Autocreator was not cleared before dealloc.");
- dispatch_release(readOnlySemaphore_);
+ if (readOnlySemaphore_) {
+ dispatch_release(readOnlySemaphore_);
+ }
[super dealloc];
}
@@ -1706,6 +1708,7 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) {
}
// Check for an autocreated value.
+ GPBPrepareReadOnlySemaphore(self);
dispatch_semaphore_wait(readOnlySemaphore_, DISPATCH_TIME_FOREVER);
value = [autocreatedExtensionMap_ objectForKey:extension];
if (!value) {