@@ -58,7 +58,6 @@ use crate::loom::cell::UnsafeCell;
5858use crate :: loom:: sync:: atomic:: AtomicU64 ;
5959use crate :: loom:: sync:: atomic:: Ordering ;
6060
61- use crate :: runtime:: context;
6261use crate :: runtime:: scheduler;
6362use crate :: sync:: AtomicWaker ;
6463use crate :: time:: Instant ;
@@ -329,8 +328,6 @@ pub(super) type EntryList = crate::util::linked_list::LinkedList<TimerShared, Ti
329328///
330329/// Note that this structure is located inside the `TimerEntry` structure.
331330pub ( crate ) struct TimerShared {
332- /// The shard id. We should never change it.
333- shard_id : u32 ,
334331 /// A link within the doubly-linked list of timers on a particular level and
335332 /// slot. Valid only if state is equal to Registered.
336333 ///
@@ -371,9 +368,8 @@ generate_addr_of_methods! {
371368}
372369
373370impl TimerShared {
374- pub ( super ) fn new ( shard_id : u32 ) -> Self {
371+ pub ( super ) fn new ( ) -> Self {
375372 Self {
376- shard_id,
377373 cached_when : AtomicU64 :: new ( 0 ) ,
378374 pointers : linked_list:: Pointers :: new ( ) ,
379375 state : StateCell :: default ( ) ,
@@ -442,11 +438,6 @@ impl TimerShared {
442438 pub ( super ) fn might_be_registered ( & self ) -> bool {
443439 self . state . might_be_registered ( )
444440 }
445-
446- /// Gets the shard id.
447- pub ( super ) fn shard_id ( & self ) -> u32 {
448- self . shard_id
449- }
450441}
451442
452443unsafe impl linked_list:: Link for TimerShared {
@@ -494,10 +485,8 @@ impl TimerEntry {
494485 fn inner ( & self ) -> & TimerShared {
495486 let inner = unsafe { & * self . inner . get ( ) } ;
496487 if inner. is_none ( ) {
497- let shard_size = self . driver . driver ( ) . time ( ) . inner . get_shard_size ( ) ;
498- let shard_id = generate_shard_id ( shard_size) ;
499488 unsafe {
500- * self . inner . get ( ) = Some ( TimerShared :: new ( shard_id ) ) ;
489+ * self . inner . get ( ) = Some ( TimerShared :: new ( ) ) ;
501490 }
502491 }
503492 return inner. as_ref ( ) . unwrap ( ) ;
@@ -654,23 +643,3 @@ impl Drop for TimerEntry {
654643 unsafe { Pin :: new_unchecked ( self ) } . as_mut ( ) . cancel ( ) ;
655644 }
656645}
657-
658- // Generates a shard id. If current thread is a worker thread, we use its worker index as a shard id.
659- // Otherwise, we use a random number generator to obtain the shard id.
660- cfg_rt ! {
661- fn generate_shard_id( shard_size: u32 ) -> u32 {
662- let id = context:: with_scheduler( |ctx| match ctx {
663- Some ( scheduler:: Context :: CurrentThread ( _ctx) ) => 0 ,
664- #[ cfg( feature = "rt-multi-thread" ) ]
665- Some ( scheduler:: Context :: MultiThread ( ctx) ) => ctx. get_worker_index( ) as u32 ,
666- None => context:: thread_rng_n( shard_size) ,
667- } ) ;
668- id % shard_size
669- }
670- }
671-
672- cfg_not_rt ! {
673- fn generate_shard_id( shard_size: u32 ) -> u32 {
674- context:: thread_rng_n( shard_size)
675- }
676- }
0 commit comments