Skip to content

stdlib: generalise TLS to support Windows #11949

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
Sep 18, 2017

Conversation

compnerd
Copy link
Member

Rename the explicit pthread to thread to indicate that this is not
pthread specifically. This allows us to implement the TLS support for
Windows using Fibers.

Replace this paragraph with a description of your changes and rationale. Provide links to external references/discussions if appropriate.

Resolves SR-NNNN.

Rename the explicit `pthread` to `thread` to indicate that this is not
`pthread` specifically.  This allows us to implement the TLS support for
Windows using Fibers.
@compnerd compnerd requested a review from milseman September 15, 2017 17:57
internal let _tlsKey: __swift_thread_key_t = {
let sentinelValue = __swift_thread_key_t.max
var key: __swift_thread_key_t = sentinelValue
let success = _swift_stdlib_thread_key_create(&key, _destroyTLS)
Copy link
Member Author

Choose a reason for hiding this comment

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

Is there a way to change the calling convention for _destroyTLS? On Windows (x86), this should be a __stdcall function.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think the Swift compiler can manipulate Windows calling conventions yet. It should be straightforward to rewrite _destroyTLS in C, or write a C __stdcall function that calls back into Swift.

Copy link
Member Author

Choose a reason for hiding this comment

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

We could introduce a @_callingconv attribute. But, it sounds like it would be easier to move it to swift-shims and rewrite it in C.

Copy link
Member

Choose a reason for hiding this comment

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

A shim that calls back into the stdlib for deinitialization would be my preferred approach. We have non-trivial deinitialization logic that ideally would be kept in Swift. We likewise probably want allocate/deallocate parity, and Swift knows the sizes of the TLS buffer already.

@compnerd
Copy link
Member Author

CC: @gparker42 @rjmccall @hughbe

@compnerd
Copy link
Member Author

@swift-ci please test

Copy link
Member

@milseman milseman left a comment

Choose a reason for hiding this comment

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

LGTM. Thank you for taking steps to generalize this and working on the Windows port!

@compnerd
Copy link
Member Author

Given that we would previously attempt to use pthread on Windows, I think that this is better than the previous state. Ill fix the CC mismatch in a follow up (that is specific to Windows x86).

@compnerd compnerd merged commit b38ed2f into swiftlang:master Sep 18, 2017
@compnerd compnerd deleted the windows-tls branch September 18, 2017 21:21
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