Skip to content

[SourceKit] Add Semaphore to SourceKitSupport's concurrency module #3085

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

Merged
merged 1 commit into from
Jun 21, 2016

Conversation

briancroom
Copy link
Contributor

What's in this pull request?

This adds a basic semaphore class to the existing concurrency module in SourceKitSupport, together with an implementation that uses libdispatch. It also migrates several bits of code to use the new class instead of dispatch_semaphore_t directly.

The most immediate motivation for this change was to remove all explicit libdispatch usage from SourceKit's unit tests which was a barrier to getting them to build on Linux.

This is related to #2793

Related bug number: (SR-1676)


Before merging this pull request to apple/swift repository:

  • Test pull request on Swift continuous integration.

Triggering Swift CI

The swift-ci is triggered by writing a comment on this PR addressed to the GitHub user @swift-ci. Different tests will run depending on the specific comment that you use. The currently available comments are:

Smoke Testing

Platform Comment
All supported platforms @swift-ci Please smoke test
All supported platforms @swift-ci Please smoke test and merge
OS X platform @swift-ci Please smoke test OS X platform
Linux platform @swift-ci Please smoke test Linux platform

Validation Testing

Platform Comment
All supported platforms @swift-ci Please test
All supported platforms @swift-ci Please test and merge
OS X platform @swift-ci Please test OS X platform
OS X platform @swift-ci Please benchmark
Linux platform @swift-ci Please test Linux platform

Lint Testing

Language Comment
Python @swift-ci Please Python lint

Note: Only members of the Apple organization can trigger swift-ci.

@gribozavr @modocache @benlangmuir

@briancroom
Copy link
Contributor Author

@swift-ci please test

return Impl::wait(ImplObj, milliseconds);
}

Semaphore(const Semaphore &Other) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having semaphores be copy-constructible sounds like a bad idea to me. We should be passing them by reference. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although I can be convinced otherwise.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I do think that it makes sense to treat a semaphore as an object intended to be shared rather than copied. I think I was following the example of WorkQueue in this case.

I haven't written much C++ recently and am still trying to get a better understanding of which types of constructors are appropriate. What do you think about the move constructor here? Does it make sense as-is?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The move constructor LGTM. The copy constructor you can just define as = delete, and that should make Semaphore a move-only type.

operator=(Semaphore &&Other) is actually OK for a move-only type.

@briancroom briancroom force-pushed the sourcekit-semaphore branch from 13af85d to d578925 Compare June 21, 2016 14:08
@briancroom
Copy link
Contributor Author

Updated according to @gribozavr's suggestion.

@briancroom
Copy link
Contributor Author

@swift-ci please test

}

bool Semaphore::Impl::wait(Ty Obj, long milliseconds) {
dispatch_time_t timeout = dispatch_time(DISPATCH_TIME_NOW, milliseconds * NSEC_PER_MSEC);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

80 columns, please.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, sorry.

@gribozavr
Copy link
Contributor

LGTM modulo comment, but it looks strange that checkCursorAsync was unused. @akyrtzi @benlangmuir ?

@benlangmuir
Copy link
Contributor

LGTM if Dmitri's comment is addressed. checkCursorAsync was never used; thanks for cleaning it up!

Includes a libdispatch-based implementation.
@briancroom briancroom force-pushed the sourcekit-semaphore branch from d578925 to 4795841 Compare June 21, 2016 17:54
@briancroom
Copy link
Contributor Author

Excellent! Thanks for the review, guys.

@briancroom briancroom merged commit 67edb44 into swiftlang:master Jun 21, 2016
@briancroom briancroom deleted the sourcekit-semaphore branch June 21, 2016 17:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants