Skip to content

Commit 779c9ac

Browse files
committed
Fix misuse of _CANCEL_ANY, and add support for non-redicated cancellation
1 parent 2f6c4e0 commit 779c9ac

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

Sources/System/IORequest.swift

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ internal enum IORequestCore {
8484
context: UInt64 = 0
8585
)
8686
case cancel(
87+
flags:UInt32
88+
)
89+
case cancelContext(
8790
flags: UInt32,
8891
targetContext: UInt64
8992
)
@@ -95,6 +98,7 @@ internal enum IORequestCore {
9598
flags: UInt32,
9699
target: IORing.RegisteredFile
97100
)
101+
98102
}
99103

100104
@inline(__always) @inlinable
@@ -341,9 +345,9 @@ extension IORing.Request {
341345
) -> IORing.Request {
342346
switch matchAll {
343347
case .all:
344-
.init(core: .cancel(flags: SWIFT_IORING_ASYNC_CANCEL_ALL | SWIFT_IORING_ASYNC_CANCEL_USERDATA, targetContext: matchingContext))
348+
.init(core: .cancelContext(flags: SWIFT_IORING_ASYNC_CANCEL_ALL | SWIFT_IORING_ASYNC_CANCEL_USERDATA, targetContext: matchingContext))
345349
case .first:
346-
.init(core: .cancel(flags: SWIFT_IORING_ASYNC_CANCEL_ANY | SWIFT_IORING_ASYNC_CANCEL_USERDATA, targetContext: matchingContext))
350+
.init(core: .cancelContext(flags: SWIFT_IORING_ASYNC_CANCEL_USERDATA, targetContext: matchingContext))
347351
}
348352
}
349353

@@ -355,7 +359,7 @@ extension IORing.Request {
355359
case .all:
356360
.init(core: .cancelFD(flags: SWIFT_IORING_ASYNC_CANCEL_ALL | SWIFT_IORING_ASYNC_CANCEL_FD, targetFD: matching))
357361
case .first:
358-
.init(core: .cancelFD(flags: SWIFT_IORING_ASYNC_CANCEL_ANY | SWIFT_IORING_ASYNC_CANCEL_FD, targetFD: matching))
362+
.init(core: .cancelFD(flags: SWIFT_IORING_ASYNC_CANCEL_FD, targetFD: matching))
359363
}
360364
}
361365

@@ -367,7 +371,18 @@ extension IORing.Request {
367371
case .all:
368372
.init(core: .cancelFDSlot(flags: SWIFT_IORING_ASYNC_CANCEL_ALL | SWIFT_IORING_ASYNC_CANCEL_FD_FIXED, target: matching))
369373
case .first:
370-
.init(core: .cancelFDSlot(flags: SWIFT_IORING_ASYNC_CANCEL_ANY | SWIFT_IORING_ASYNC_CANCEL_FD_FIXED, target: matching))
374+
.init(core: .cancelFDSlot(flags: SWIFT_IORING_ASYNC_CANCEL_FD_FIXED, target: matching))
375+
}
376+
}
377+
378+
@inlinable public static func cancel(
379+
_ matchAll: CancellationMatch,
380+
) -> IORing.Request {
381+
switch matchAll {
382+
case .all:
383+
.init(core: .cancel(flags: SWIFT_IORING_ASYNC_CANCEL_ALL))
384+
case .first:
385+
.init(core: .cancel(flags: SWIFT_IORING_ASYNC_CANCEL_ANY))
371386
}
372387
}
373388

@@ -457,7 +472,7 @@ extension IORing.Request {
457472
)
458473
request.path = path
459474
request.rawValue.user_data = context
460-
case .cancel(let flags, let targetContext):
475+
case .cancelContext(let flags, let targetContext):
461476
request.operation = .asyncCancel
462477
request.cancel_flags = flags
463478
request.addr = targetContext
@@ -469,6 +484,9 @@ extension IORing.Request {
469484
request.operation = .asyncCancel
470485
request.cancel_flags = flags
471486
request.rawValue.fd = Int32(target.index)
487+
case .cancel(let flags):
488+
request.operation = .asyncCancel
489+
request.cancel_flags = flags
472490
}
473491

474492
return request

Sources/System/IORing.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,7 @@ public struct IORing: ~Copyable {
378378
submissionRingSize = tmpSQSize
379379
completionRingPtr = tmpCQPtr
380380
completionRingSize = tmpCQSize
381+
381382
_registeredFiles = []
382383
_registeredBuffers = []
383384
submissionRing = SQRing(

0 commit comments

Comments
 (0)