diff --git a/IntegrationTests/tests_02_syscall_wrappers/defines.sh b/IntegrationTests/tests_02_syscall_wrappers/defines.sh index 15e4c49f2..debbfe9af 100644 --- a/IntegrationTests/tests_02_syscall_wrappers/defines.sh +++ b/IntegrationTests/tests_02_syscall_wrappers/defines.sh @@ -48,6 +48,7 @@ EOF "$here/../../Sources/NIOPosix/BSDSocketAPIPosix.swift" \ "$here/../../Sources/NIOPosix/System.swift" \ "$here/../../Sources/NIOCore/IO.swift" \ + "$here/../../Sources/NIOCore/NIOSendable.swift" \ "$tmpdir/syscallwrapper/Sources/syscallwrapper" cp "$here/../../Sources/NIOPosix/IO.swift" "$tmpdir/syscallwrapper/Sources/syscallwrapper/NIOPosixIO.swift" ln -s "$here/../../Sources/CNIOLinux" "$tmpdir/syscallwrapper/Sources" diff --git a/Sources/NIOCore/AsyncAwaitSupport.swift b/Sources/NIOCore/AsyncAwaitSupport.swift index 36c8dfa3e..348a9745b 100644 --- a/Sources/NIOCore/AsyncAwaitSupport.swift +++ b/Sources/NIOCore/AsyncAwaitSupport.swift @@ -12,12 +12,6 @@ // //===----------------------------------------------------------------------===// -#if swift(>=5.5) && canImport(_Concurrency) -public typealias NIOSendable = Swift.Sendable -#else -public typealias NIOSendable = Any -#endif - #if compiler(>=5.5.2) && canImport(_Concurrency) extension EventLoopFuture { diff --git a/Sources/NIOCore/BSDSocketAPI.swift b/Sources/NIOCore/BSDSocketAPI.swift index 60b3ee695..df33d150f 100644 --- a/Sources/NIOCore/BSDSocketAPI.swift +++ b/Sources/NIOCore/BSDSocketAPI.swift @@ -91,7 +91,7 @@ public enum NIOBSDSocket { extension NIOBSDSocket { /// Specifies the addressing scheme that the socket can use. - public struct AddressFamily: RawRepresentable { + public struct AddressFamily: RawRepresentable, NIOSendable { public typealias RawValue = CInt public var rawValue: RawValue public init(rawValue: RawValue) { @@ -108,7 +108,7 @@ extension NIOBSDSocket.AddressFamily: Hashable { extension NIOBSDSocket { /// Specifies the type of protocol that the socket can use. - public struct ProtocolFamily: RawRepresentable { + public struct ProtocolFamily: RawRepresentable, NIOSendable { public typealias RawValue = CInt public var rawValue: RawValue public init(rawValue: RawValue) { @@ -125,7 +125,7 @@ extension NIOBSDSocket.ProtocolFamily: Hashable { extension NIOBSDSocket { /// Defines socket option levels. - public struct OptionLevel: RawRepresentable { + public struct OptionLevel: RawRepresentable, NIOSendable { public typealias RawValue = CInt public var rawValue: RawValue public init(rawValue: RawValue) { @@ -142,7 +142,7 @@ extension NIOBSDSocket.OptionLevel: Hashable { extension NIOBSDSocket { /// Defines configuration option names. - public struct Option: RawRepresentable { + public struct Option: RawRepresentable, NIOSendable { public typealias RawValue = CInt public var rawValue: RawValue public init(rawValue: RawValue) { diff --git a/Sources/NIOCore/ByteBuffer-core.swift b/Sources/NIOCore/ByteBuffer-core.swift index e42bf3b1a..d118bcc35 100644 --- a/Sources/NIOCore/ByteBuffer-core.swift +++ b/Sources/NIOCore/ByteBuffer-core.swift @@ -230,6 +230,7 @@ public struct ByteBuffer { @usableFromInline var _slice: Slice // MARK: Internal _Storage for CoW + /// Note: This class is **not** thread-safe @usableFromInline final class _Storage { @usableFromInline private(set) var capacity: _Capacity @usableFromInline private(set) var bytes: UnsafeMutableRawPointer diff --git a/Sources/NIOCore/ByteBuffer-int.swift b/Sources/NIOCore/ByteBuffer-int.swift index 2618b6fc8..94fba5622 100644 --- a/Sources/NIOCore/ByteBuffer-int.swift +++ b/Sources/NIOCore/ByteBuffer-int.swift @@ -159,7 +159,7 @@ extension UInt32 { /// Endianness refers to the sequential order in which bytes are arranged into larger numerical values when stored in /// memory or when transmitted over digital links. -public enum Endianness { +public enum Endianness: NIOSendable { /// The endianness of the machine running this program. public static let host: Endianness = hostEndianness0() diff --git a/Sources/NIOCore/CircularBuffer.swift b/Sources/NIOCore/CircularBuffer.swift index 3e00eb965..3f70e4571 100644 --- a/Sources/NIOCore/CircularBuffer.swift +++ b/Sources/NIOCore/CircularBuffer.swift @@ -62,7 +62,7 @@ public struct CircularBuffer: CustomStringConvertible { /// /// - note: Every index is invalidated as soon as you perform a length-changing operating on the `CircularBuffer` /// but remains valid when you replace one item by another using the subscript. - public struct Index: Comparable { + public struct Index: Comparable, NIOSendable { @usableFromInline private(set) var _backingIndex: UInt32 @usableFromInline private(set) var _backingCheck: _UInt24 @usableFromInline private(set) var isIndexGEQHeadIndex: Bool @@ -815,6 +815,8 @@ extension CircularBuffer: Hashable where Element: Hashable { } } +extension CircularBuffer: NIOSendable where Element: NIOSendable {} + extension CircularBuffer: ExpressibleByArrayLiteral { public init(arrayLiteral elements: Element...) { self.init(elements) diff --git a/Sources/NIOCore/MarkedCircularBuffer.swift b/Sources/NIOCore/MarkedCircularBuffer.swift index b1190274e..f2630369c 100644 --- a/Sources/NIOCore/MarkedCircularBuffer.swift +++ b/Sources/NIOCore/MarkedCircularBuffer.swift @@ -190,3 +190,5 @@ extension MarkedCircularBuffer: RandomAccessCollection { } } + +extension MarkedCircularBuffer: NIOSendable where Element: NIOSendable {} diff --git a/Sources/NIOCore/NIOSendable.swift b/Sources/NIOCore/NIOSendable.swift new file mode 100644 index 000000000..535e9f747 --- /dev/null +++ b/Sources/NIOCore/NIOSendable.swift @@ -0,0 +1,19 @@ +//===----------------------------------------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#if swift(>=5.5) && canImport(_Concurrency) +public typealias NIOSendable = Swift.Sendable +#else +public typealias NIOSendable = Any +#endif