tokio-rs / tokio-uring

An io_uring backed runtime for Rust

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Allow for thread safe `FixedBuf` handles

Nehliin opened this issue · comments

With the introduction of Fixed buffers I was curious if it would be possible to also expose thread safe handles to those buffers? I.e supporting operations on different threads (and runtimes) but still utilizing the same buffer pool. The use case I have in mind for example is having a separate disk-io thread which would be distinct from the thread reading data from a socket. It would be neat if both could share the same buffer pool by propagating the handles from the socket thread to the disk thread and then use write_fixed there.

After discussions on discord it seems like at a minimum register_buffers and unregister_buffers needs to be exposed publicly for it to be possible for end users to create their own buffer registries.

I realize now that another problem is that all the io objects like TcpStream etc only accepts the FixedBuf handle making it impossible to use a custom registry that would with thread safe handles.

The reference counting mechanics would need to be redone with something like Arc<Mutex<FixedBuffers>>, which would cause unnecessary overhead in the single threaded case.

I think it should be possible to have thread-safe fixed buffer collections alongside the current ones. For operations, it should be possible to generalize with a marker trait.

Yes! I do not want us to replace the existing ones. Just make the operations more flexible