diff options
author | Josh Haberman <jhaberman@gmail.com> | 2016-03-29 16:24:35 -0700 |
---|---|---|
committer | Josh Haberman <jhaberman@gmail.com> | 2016-03-29 16:24:35 -0700 |
commit | a15b916c419000565384a78224e402ed925e5fc8 (patch) | |
tree | d0bd6aa4648fddbb08d35d8b78dba32958ae7b51 /objectivec/GPBMessage_PackagePrivate.h | |
parent | 67c727cd411a339eb4233c84d9a1afadd8c20566 (diff) | |
parent | 261ee021f640ea6fe67aaf1f53e1518ed154cad0 (diff) | |
download | protobuf-a15b916c419000565384a78224e402ed925e5fc8.tar.gz protobuf-a15b916c419000565384a78224e402ed925e5fc8.tar.bz2 protobuf-a15b916c419000565384a78224e402ed925e5fc8.zip |
Merge branch 'master' into docker
Diffstat (limited to 'objectivec/GPBMessage_PackagePrivate.h')
-rw-r--r-- | objectivec/GPBMessage_PackagePrivate.h | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/objectivec/GPBMessage_PackagePrivate.h b/objectivec/GPBMessage_PackagePrivate.h index b7e24fc9..478db2cf 100644 --- a/objectivec/GPBMessage_PackagePrivate.h +++ b/objectivec/GPBMessage_PackagePrivate.h @@ -67,6 +67,10 @@ typedef struct GPBMessage_Storage *GPBMessage_StoragePtr; // priority inversion: // http://mjtsai.com/blog/2015/12/16/osspinlock-is-unsafe/ // https://lists.swift.org/pipermail/swift-dev/Week-of-Mon-20151214/000372.html + // 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_once_t readOnlySemaphoreCreationOnce_; dispatch_semaphore_t readOnlySemaphore_; } @@ -103,6 +107,14 @@ typedef struct GPBMessage_Storage *GPBMessage_StoragePtr; CF_EXTERN_C_BEGIN + +// Call this before using the readOnlySemaphore_. This ensures it is created only once. +NS_INLINE void GPBPrepareReadOnlySemaphore(GPBMessage *self) { + dispatch_once(&self->readOnlySemaphoreCreationOnce_, ^{ + self->readOnlySemaphore_ = dispatch_semaphore_create(1); + }); +} + // Returns a new instance that was automatically created by |autocreator| for // its field |field|. GPBMessage *GPBCreateMessageWithAutocreator(Class msgClass, |