Commit c2a582b
committed
feat: replace q.q_ring with thread-local variable and introduce 3 APIs
Replace individual q.q_ring usage with a unified thread-local QUEUE_RING
using OnceCell for lazy initialization. This change provides cleaner API
access through helper macros and improves thread safety.
Key changes:
- Add thread-local QUEUE_RING with OnceCell<RefCell<IoUring>>
- Create with_queue_ring() and with_queue_ring_mut() for easier external access
- Replace all q.q_ring.borrow() and q.q_ring.borrow_mut() calls (20+ instances)
- Update both src/io.rs and src/uring_async.rs
- Add proper type annotations for compile-time safety
- Initialize thread-local ring when queue is created
Benefits:
- Cleaner, more ergonomic API through helper macros
- Thread-local access avoids cross-thread synchronization
- Lazy initialization reduces memory overhead
- Type-safe access with explicit annotations
Three new APIs are added:
- with_queue_ring()
- with_queue_ring_mut()
- init_task_ring()
The 1st two are for manipulating the queue's ring, and the 3rd one can
be used for customerizing the task ring.
Per-task io_uring is the most common usage, so take this way for
libublk.
- helps to use task ring to handle multiple queues from different
devices
- helps to support async/.await control command because control ring
actually depends on io ring if the two are in same task context
- with control command async/.await ready, it will be pretty
easier/simpler to run arbitrary queues & tasks & devices combination,
one typical example is to create many devices in single process, and
let one thread to handle queues with same index from different
devices.
Signed-off-by: Ming Lei <tom.leiming@gmail.com>1 parent 79200ea commit c2a582b
3 files changed
+416
-150
lines changed
0 commit comments