forked from hummingbird-project/hummingbird
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make HBRequest/HBResponse Sendable (hummingbird-project#153)
* Made HBRequest Sendable * Add UnsafeTransfer and use in HBRequest * Make HBResponse Sendable * Added _HBSendableProtocol * format * Make PerformanceTest an executableTarget * Update FlatDictionary.swift * Fix compile error * Make MediaType Sendable
- Loading branch information
1 parent
9c9ad92
commit 4bf0119
Showing
9 changed files
with
180 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the Hummingbird server framework project | ||
// | ||
// Copyright (c) 2022 the Hummingbird authors | ||
// Licensed under Apache License v2.0 | ||
// | ||
// See LICENSE.txt for license information | ||
// See hummingbird/CONTRIBUTORS.txt for the list of Hummingbird authors | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#if compiler(>=5.6) | ||
@preconcurrency public protocol _HBSendableProtocol: Sendable {} | ||
#else | ||
public protocol _HBSendableProtocol {} | ||
#endif |
66 changes: 66 additions & 0 deletions
66
Sources/Hummingbird/AsyncAwaitSupport/UnsafeTransfer.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the Hummingbird server framework project | ||
// | ||
// Copyright (c) 2022 the Hummingbird authors | ||
// Licensed under Apache License v2.0 | ||
// | ||
// See LICENSE.txt for license information | ||
// See hummingbird/CONTRIBUTORS.txt for the list of Hummingbird authors | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the SwiftNIO open source project | ||
// | ||
// Copyright (c) 2021-2022 Apple Inc. and the SwiftNIO project authors | ||
// Licensed under Apache License v2.0 | ||
// | ||
// See LICENSE.txt for license information | ||
// See CONTRIBUTORS.txt for the list of SwiftNIO project authors | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
/// ``HBUnsafeTransfer`` can be used to make non-`Sendable` values `Sendable`. | ||
/// As the name implies, the usage of this is unsafe because it disables the sendable checking of the compiler. | ||
/// It can be used similar to `@unsafe Sendable` but for values instead of types. | ||
@usableFromInline | ||
struct HBUnsafeTransfer<Wrapped> { | ||
@usableFromInline | ||
var wrappedValue: Wrapped | ||
|
||
@inlinable | ||
init(_ wrappedValue: Wrapped) { | ||
self.wrappedValue = wrappedValue | ||
} | ||
} | ||
|
||
#if swift(>=5.5) && canImport(_Concurrency) | ||
extension HBUnsafeTransfer: @unchecked Sendable {} | ||
#endif | ||
|
||
extension HBUnsafeTransfer: Equatable where Wrapped: Equatable {} | ||
extension HBUnsafeTransfer: Hashable where Wrapped: Hashable {} | ||
|
||
/// ``HBUnsafeMutableTransferBox`` can be used to make non-`Sendable` values `Sendable` and mutable. | ||
/// It can be used to capture local mutable values in a `@Sendable` closure and mutate them from within the closure. | ||
/// As the name implies, the usage of this is unsafe because it disables the sendable checking of the compiler and does not add any synchronisation. | ||
@usableFromInline | ||
final class HBUnsafeMutableTransferBox<Wrapped> { | ||
@usableFromInline | ||
var wrappedValue: Wrapped | ||
|
||
@inlinable | ||
init(_ wrappedValue: Wrapped) { | ||
self.wrappedValue = wrappedValue | ||
} | ||
} | ||
|
||
#if swift(>=5.5) && canImport(_Concurrency) | ||
extension HBUnsafeMutableTransferBox: @unchecked Sendable {} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters