Clean up some more warnings via an additional Sendability pass audit (#72)

This commit is contained in:
Philippe Hausler authored and GitHub committed 2022-03-11 12:56:43 -08:00
1 parent 624eea0387
commit 4b11faad62
6 files changed
+20 -20

No files matched your search

@@ -67,17 +67,13 @@ public struct AsyncBufferedByteIterator: AsyncIteratorProtocol, Sendable {
@frozen @usableFromInline
internal struct _AsyncBytesBuffer: @unchecked Sendable {
@usableFromInline
final class Storage {
fileprivate let readFunction: @Sendable (UnsafeMutableRawBufferPointer) async throws -> Int
final class Storage: Sendable {
fileprivate let buffer: UnsafeMutableRawBufferPointer
fileprivate var finished = false
init(
capacity: Int,
readFunction: @Sendable @escaping (UnsafeMutableRawBufferPointer) async throws -> Int
capacity: Int
) {
precondition(capacity > 0)
self.readFunction = readFunction
buffer = UnsafeMutableRawBufferPointer.allocate(
byteCount: capacity,
alignment: MemoryLayout<AnyObject>.alignment
@@ -93,11 +89,15 @@ internal struct _AsyncBytesBuffer: @unchecked Sendable {
@usableFromInline internal var nextPointer: UnsafeRawPointer
@usableFromInline internal var endPointer: UnsafeRawPointer
internal let readFunction: @Sendable (UnsafeMutableRawBufferPointer) async throws -> Int
internal var finished = false
@usableFromInline init(
capacity: Int,
readFunction: @Sendable @escaping (UnsafeMutableRawBufferPointer) async throws -> Int
) {
let s = Storage(capacity: capacity, readFunction: readFunction)
let s = Storage(capacity: capacity)
self.readFunction = readFunction
storage = s
nextPointer = UnsafeRawPointer(s.buffer.baseAddress!)
endPointer = nextPointer
@@ -105,21 +105,21 @@ internal struct _AsyncBytesBuffer: @unchecked Sendable {
@inline(never) @usableFromInline
internal mutating func reloadBufferAndNext() async throws -> UInt8? {
if storage.finished {
if finished {
return nil
}
try Task.checkCancellation()
do {
let readSize: Int = try await storage.readFunction(storage.buffer)
let readSize: Int = try await readFunction(storage.buffer)
if readSize == 0 {
storage.finished = true
finished = true
nextPointer = endPointer
return nil
}
nextPointer = UnsafeRawPointer(storage.buffer.baseAddress!)
endPointer = nextPointer + readSize
} catch {
storage.finished = true
finished = true
nextPointer = endPointer
throw error
}