Skip to content

SwiftPrivateThreadExtras: correct misuse of API #32593

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 29, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,18 @@ public func _stdlib_thread_join<Result>(
) -> (CInt, Result?) {
#if os(Windows)
let result = WaitForSingleObject(thread, INFINITE)
if result == WAIT_OBJECT_0 {
var threadResult: DWORD = 0
GetExitCodeThread(thread, &threadResult)
CloseHandle(thread)

return (CInt(result),
UnsafeMutablePointer<DWORD>(&threadResult)
.withMemoryRebound(to: Result.self, capacity: 1){ $0.pointee })
} else {
return (CInt(result), nil)
guard result == WAIT_OBJECT_0 else { return (CInt(result), nil) }

var dwResult: DWORD = 0
GetExitCodeThread(thread, &dwResult)
CloseHandle(thread)

let value: Result = withUnsafePointer(to: &dwResult) {
$0.withMemoryRebound(to: Result.self, capacity: 1) {
$0.pointee
}
}
return (CInt(result), value)
#else
var threadResultRawPtr: UnsafeMutableRawPointer?
let result = pthread_join(thread, &threadResultRawPtr)
Expand Down