tokio-rs / io-uring

The `io_uring` library for Rust
Apache License 2.0
1.16k stars 129 forks source link

unsafe impl `Send+Sync` for `Submitter`, `SubmissionQueue`, `CompletionQueue` #283

Open problame opened 4 months ago

problame commented 4 months ago

The IoUring type already has Send + Sync impls.

In tokio-epoll-uring, we use split() and need the Submitter, SubmissionQueue and CompletionQueue to be Send (not sync, though).

This PR adds those unsafe impls, and adds hopefully not too repetitive commentary on why these impls are safe.


Co-authored-by: Conrad Ludgate conrad@neon.tech Cherry picked from commit https://github.com/neondatabase/fork--tokio-rs--io-uring/commit/bbc5a0c5f6cde9051037ec2fcc648cbadb7a80b4

quininer commented 4 months ago

You seem to have to use unsafe to get &'static mut or use scope thread to make sense. I would recommend submission_shared and completion_shared.

see https://github.com/tokio-rs/io-uring/pull/100/files#diff-3a884378bde161d43e3099c530c5090847e826cb4501d4f7a803144e6bde14d3

problame commented 4 months ago

Sorry, I'm not following. Who's talking about &'static mut ?

I would recommend submission_shared and completion_shared.

The unsafe impls proposed in this PR allow movement of Submitter, SubmissionQueue, and CompletionQueue, to different threads in consuming code, without any unsafe.

I consider that strictly better than the unsafe fn submission_shared() and unsafe fn completion_shared().