diff --git a/Sources/System/IOCompletion.swift b/Sources/System/IOCompletion.swift index 9b41214..ee81797 100644 --- a/Sources/System/IOCompletion.swift +++ b/Sources/System/IOCompletion.swift @@ -1,7 +1,6 @@ @_implementationOnly import CSystem -//TODO: should be ~Copyable, but requires UnsafeContinuation add ~Copyable support -public struct IOCompletion { +public struct IOCompletion: ~Copyable { let rawValue: io_uring_cqe } diff --git a/Sources/System/IORing.swift b/Sources/System/IORing.swift index 4525281..79840c1 100644 --- a/Sources/System/IORing.swift +++ b/Sources/System/IORing.swift @@ -338,7 +338,7 @@ public struct IORing: ~Copyable { minimumCount: UInt32, maximumCount: UInt32, extraArgs: UnsafeMutablePointer? = nil, - consumer: (IOCompletion?, IORingError?, Bool) throws -> Void + consumer: (consuming IOCompletion?, IORingError?, Bool) throws -> Void ) rethrows { var count = 0 while let completion = _tryConsumeCompletion(ring: completionRing) { @@ -407,15 +407,15 @@ public struct IORing: ~Copyable { ) throws -> IOCompletion { var result: IOCompletion? = nil try _blockingConsumeCompletionGuts(minimumCount: 1, maximumCount: 1, extraArgs: extraArgs) { - (completion, error, done) in + (completion: consuming IOCompletion?, error, done) in if let error { throw error } - if let completion { - result = completion + if let completion { + result = consume completion } } - return result.unsafelyUnwrapped + return result.take()! } public func blockingConsumeCompletion( @@ -443,7 +443,7 @@ public struct IORing: ~Copyable { public func blockingConsumeCompletions( minimumCount: UInt32 = 1, timeout: Duration? = nil, - consumer: (IOCompletion?, IORingError?, Bool) throws -> Void + consumer: (consuming IOCompletion?, IORingError?, Bool) throws -> Void ) throws { if let timeout { var ts = __kernel_timespec( @@ -603,7 +603,7 @@ public struct IORing: ~Copyable { public func submitPreparedRequestsAndConsumeCompletions( minimumCount: UInt32 = 1, timeout: Duration? = nil, - consumer: (IOCompletion?, IORingError?, Bool) throws -> Void + consumer: (consuming IOCompletion?, IORingError?, Bool) throws -> Void ) throws { //TODO: optimize this to one uring_enter try submitPreparedRequests()