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
258406b8
Commit
258406b8
authored
Mar 29, 2017
by
Thomas Van Lenten
Committed by
GitHub
Mar 29, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2919 from thomasvl/drop_dispatch
Remove the use of dispatch_once that is heap backed.
parents
ba3fa41b
130c1666
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
17 deletions
+20
-17
GPBMessage.m
objectivec/GPBMessage.m
+19
-0
GPBMessage_PackagePrivate.h
objectivec/GPBMessage_PackagePrivate.h
+1
-17
No files found.
objectivec/GPBMessage.m
View file @
258406b8
...
...
@@ -738,6 +738,25 @@ void GPBClearMessageAutocreator(GPBMessage *self) {
self
->
autocreatorExtension_
=
nil
;
}
// Call this before using the readOnlySemaphore_. This ensures it is created only once.
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_release
(
worker
);
}
}
#pragma clang diagnostic pop
}
static
GPBUnknownFieldSet
*
GetOrMakeUnknownFields
(
GPBMessage
*
self
)
{
if
(
!
self
->
unknownFields_
)
{
self
->
unknownFields_
=
[[
GPBUnknownFieldSet
alloc
]
init
];
...
...
objectivec/GPBMessage_PackagePrivate.h
View file @
258406b8
...
...
@@ -70,7 +70,6 @@ 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_once_t
readOnlySemaphoreCreationOnce_
;
dispatch_semaphore_t
readOnlySemaphore_
;
}
...
...
@@ -105,22 +104,7 @@ CF_EXTERN_C_BEGIN
// Call this before using the readOnlySemaphore_. This ensures it is created only once.
NS_INLINE
void
GPBPrepareReadOnlySemaphore
(
GPBMessage
*
self
)
{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdirect-ivar-access"
// Starting on Xcode 8.3, the static analyzer complains that the dispatch_once_t
// variable passed to dispatch_once should not be allocated on the heap or
// stack. Given that the semaphore is also an instance variable of the message,
// both variables are cleared at the same time, so this is safe.
#if !defined(__clang_analyzer__)
dispatch_once
(
&
self
->
readOnlySemaphoreCreationOnce_
,
^
{
self
->
readOnlySemaphore_
=
dispatch_semaphore_create
(
1
);
});
#endif // !defined(__clang_analyzer__)
#pragma clang diagnostic pop
}
void
GPBPrepareReadOnlySemaphore
(
GPBMessage
*
self
);
// Returns a new instance that was automatically created by |autocreator| for
// its field |field|.
...
...
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