@@ -19,7 +19,7 @@ import AsyncQueue
1919import Glibc
2020
2121extension SingleshotSubmission {
22- func enqueue( ) {
22+ func enqueue( ring : isolated IORing ) {
2323 guard let group else { return }
2424 Task {
2525 do {
@@ -31,34 +31,30 @@ extension SingleshotSubmission {
3131 }
3232 }
3333
34- func ready( ) async {
35- await group? . readinessChannel. send ( ( ) )
34+ func ready( ) {
35+ Task { await group? . readinessChannel. send ( ( ) ) }
3636 }
3737}
3838
39- actor SubmissionGroup < T: Sendable > {
39+ final class SubmissionGroup < T: Sendable > : Sendable {
4040 private let ring : IORing
41- private let queue = ActorQueue < SubmissionGroup > ( )
42- private var submissions = [ SingleshotSubmission < T > ] ( )
41+ private nonisolated ( unsafe) var submissions = [ SingleshotSubmission < T > ] ( )
4342
4443 fileprivate let readinessChannel = AsyncChannel < ( ) > ( )
4544 fileprivate let resultChannel = AsyncThrowingChannel < T , Error > ( )
4645
47- init ( ring: IORing ) async throws {
46+ init ( ring: isolated IORing) throws {
4847 self . ring = ring
49- queue. adoptExecutionContext ( of: self )
5048 }
5149
5250 ///
5351 /// Asynchronously enqueues an submission. Submission must call `ready()` when
5452 /// its continuation is registered in the SQE `user_data` otherwise the group
5553 /// will never be submitted.
5654 ///
57- func enqueue( submission: SingleshotSubmission < T > ) {
55+ func enqueue( submission: SingleshotSubmission < T > , ring : isolated IORing ) {
5856 submissions. append ( submission)
59- Task ( on: queue) { _ in
60- submission. enqueue ( )
61- }
57+ submission. enqueue ( ring: ring)
6258 }
6359
6460 private func allReady( ) async {
@@ -75,15 +71,13 @@ actor SubmissionGroup<T: Sendable> {
7571 ///
7672 /// Completing the submission group involves the following:
7773 ///
78- /// - Await all submissions to be scheduled on queue
7974 /// - Wait for all submissions to have continuations registered
8075 /// - Submit SQEs to I/O ring
8176 /// - Collect results from results channel
8277 ///
83- func finish( ) async throws -> [ T ] {
84- await Task ( on: queue) { _ in } . value
78+ func finish( ring: isolated IORing) async throws -> [ T ] {
8579 await allReady ( )
86- try await ring. submit ( )
80+ try ring. submit ( )
8781 readinessChannel. finish ( )
8882 return try await allComplete ( )
8983 }
0 commit comments