@@ -188,25 +188,26 @@ impl Handle {
188188 . register ( & mut source, TOKEN_WAKEUP , Interest :: READABLE . to_mio ( ) )
189189 }
190190
191- pub ( crate ) fn get_uring ( & self ) -> & Mutex < UringContext > {
192- & self . uring_context
191+ pub ( crate ) fn get_uring ( & self , shard_id : usize ) -> & Mutex < UringContext > {
192+ let shard_id = shard_id % self . uring_context . len ( ) ;
193+ & self . uring_context [ shard_id]
193194 }
194195
195- fn set_uring_state ( & self , state : State ) {
196- self . uring_state . store ( state. as_usize ( ) , Ordering :: Release ) ;
196+ fn set_uring_state ( & self , shard_id : usize , state : State ) {
197+ self . uring_state [ shard_id ] . store ( state. as_usize ( ) , Ordering :: Release ) ;
197198 }
198199
199200 /// Check if the io_uring context is initialized. If not, it will try to initialize it.
200- pub ( crate ) fn check_and_init ( & self ) -> io:: Result < bool > {
201- match State :: from_usize ( self . uring_state . load ( Ordering :: Acquire ) ) {
202- State :: Uninitialized => match self . try_init ( ) {
201+ pub ( crate ) fn check_and_init ( & self , shard_id : usize ) -> io:: Result < bool > {
202+ match State :: from_usize ( self . uring_state [ shard_id ] . load ( Ordering :: Acquire ) ) {
203+ State :: Uninitialized => match self . try_init ( shard_id ) {
203204 Ok ( ( ) ) => {
204- self . set_uring_state ( State :: Initialized ) ;
205+ self . set_uring_state ( shard_id , State :: Initialized ) ;
205206 Ok ( true )
206207 }
207208 // If the system doesn't support io_uring, we set the state to Unsupported.
208209 Err ( e) if e. raw_os_error ( ) == Some ( libc:: ENOSYS ) => {
209- self . set_uring_state ( State :: Unsupported ) ;
210+ self . set_uring_state ( shard_id , State :: Unsupported ) ;
210211 Ok ( false )
211212 }
212213 // For other system errors, we just return it.
@@ -218,8 +219,8 @@ impl Handle {
218219 }
219220
220221 /// Initialize the io_uring context if it hasn't been initialized yet.
221- fn try_init ( & self ) -> io:: Result < ( ) > {
222- let mut guard = self . get_uring ( ) . lock ( ) ;
222+ fn try_init ( & self , shard_id : usize ) -> io:: Result < ( ) > {
223+ let mut guard = self . get_uring ( shard_id ) . lock ( ) ;
223224 if guard. try_init ( ) ? {
224225 self . add_uring_source ( guard. ring ( ) . as_raw_fd ( ) ) ?;
225226 }
@@ -237,15 +238,20 @@ impl Handle {
237238 ///
238239 /// Callers must ensure that parameters of the entry (such as buffer) are valid and will
239240 /// be valid for the entire duration of the operation, otherwise it may cause memory problems.
240- pub ( crate ) unsafe fn register_op ( & self , entry : Entry , waker : Waker ) -> io:: Result < usize > {
241+ pub ( crate ) unsafe fn register_op (
242+ & self ,
243+ shard_id : usize ,
244+ entry : Entry ,
245+ waker : Waker ,
246+ ) -> io:: Result < usize > {
241247 // Note: Maybe this check can be removed if upstream callers consistently use `check_and_init`.
242- if !self . check_and_init ( ) ? {
248+ if !self . check_and_init ( shard_id ) ? {
243249 return Err ( io:: Error :: from_raw_os_error ( libc:: ENOSYS ) ) ;
244250 }
245251
246252 // Uring is initialized.
247253
248- let mut guard = self . get_uring ( ) . lock ( ) ;
254+ let mut guard = self . get_uring ( shard_id ) . lock ( ) ;
249255 let ctx = & mut * guard;
250256 let index = ctx. ops . insert ( Lifecycle :: Waiting ( waker) ) ;
251257 let entry = entry. user_data ( index as u64 ) ;
@@ -273,8 +279,8 @@ impl Handle {
273279
274280 // TODO: Remove this annotation when operations are actually supported
275281 #[ allow( unused_variables, unreachable_code) ]
276- pub ( crate ) fn cancel_op < T : Cancellable > ( & self , index : usize , data : Option < T > ) {
277- let mut guard = self . get_uring ( ) . lock ( ) ;
282+ pub ( crate ) fn cancel_op < T : Cancellable > ( & self , shard_id : usize , index : usize , data : Option < T > ) {
283+ let mut guard = self . get_uring ( shard_id ) . lock ( ) ;
278284 let ctx = & mut * guard;
279285 let ops = & mut ctx. ops ;
280286 let Some ( lifecycle) = ops. get_mut ( index) else {
0 commit comments