Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
protobuf
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
protobuf
Commits
92091363
Commit
92091363
authored
Mar 21, 2016
by
Thomas Van Lenten
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1339 from thomasvl/delay_dispatch_semaphore_creation
Only create the readonlySemaphore on demand.
parents
5e933847
bd41a39f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
3 deletions
+19
-3
GPBMessage.m
objectivec/GPBMessage.m
+6
-3
GPBMessage_PackagePrivate.h
objectivec/GPBMessage_PackagePrivate.h
+12
-0
GPBUtilities.m
objectivec/GPBUtilities.m
+1
-0
No files found.
objectivec/GPBMessage.m
View file @
92091363
...
...
@@ -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
)
{
...
...
objectivec/GPBMessage_PackagePrivate.h
View file @
92091363
...
...
@@ -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
,
...
...
objectivec/GPBUtilities.m
View file @
92091363
...
...
@@ -412,6 +412,7 @@ id GPBGetObjectIvarWithField(GPBMessage *self, GPBFieldDescriptor *field) {
return
field
.
defaultValue
.
valueMessage
;
}
GPBPrepareReadOnlySemaphore
(
self
);
dispatch_semaphore_wait
(
self
->
readOnlySemaphore_
,
DISPATCH_TIME_FOREVER
);
GPBMessage
*
result
=
GPBGetObjectIvarWithFieldNoAutocreate
(
self
,
field
);
if
(
!
result
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment