-
Notifications
You must be signed in to change notification settings - Fork 151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace dispatch_semaphore
use with os_unfair_lock
.
#324
Conversation
// the session has been created (or fails to be created) to avoid a hang. | ||
session = _delegateDispatcher.session; | ||
if (!session) { | ||
session = creationBlock(_delegateDispatcher); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try/catch on this to avoid going to a bad state?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or maybe just a try/finally? Or are you comfortable in it should never throw?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was thinking it should be fine, but for safety's sake yeah it should probably have try/finally to ensure the lock is released.
Do we also raise the min versions? |
I thought I saw one build error about availability, but now I don't see it. |
a162c0e
to
8908422
Compare
Xcode 14 thread checker has flagged potential priority inversion issues relating to use of `dispatch_semaphore` when handling session creation and dispatcher resetting. This replaces uses of semaphores with `os_unfair_lock` which is available on iOS 10+ and all other platforms we're concerned with. To avoid the danger of leaking the lock, this also refactors session creation by having `GTMSessionFetcher` instances provide a session creation block to the service, which is only called if the service does not have an active `NSURLSession`.
Ensures that even if `creationBlock` throws, the lock is properly unlocked.
15ebc6d
to
7bcef09
Compare
Xcode 14 thread checker has flagged potential priority inversion issues relating to use of
dispatch_semaphore
when handling session creation and dispatcher resetting. This replaces uses of semaphores withos_unfair_lock
which is available on iOS 10+ and all other platforms we're concerned with.To avoid the danger of leaking the lock, this also refactors session creation by having
GTMSessionFetcher
instances provide a session creation block to the service, which is only called if the service does not have an activeNSURLSession
.