@@ -62,8 +62,6 @@ pub(crate) struct Owner<E, const NUM_BLOCKS: usize, const ENTRIES_PER_BLOCK: usi
6262 pcache : CachePadded < * const Block < E , { ENTRIES_PER_BLOCK } > > ,
6363 /// Consumer cache (single consumer) - points to block in self.queue.
6464 ccache : CachePadded < * const Block < E , { ENTRIES_PER_BLOCK } > > ,
65- /// Stealer position cache - Allows the owner to quickly check if there are any stealers
66- spos : CachePadded < Arc < AtomicUsize > > ,
6765 /// `Arc` to the actual queue to ensure the queue lives at least as long as the Owner.
6866 #[ allow( dead_code) ]
6967 queue : Pin < Arc < BwsQueue < E , NUM_BLOCKS , ENTRIES_PER_BLOCK > > > ,
@@ -373,37 +371,15 @@ impl<E, const NUM_BLOCKS: usize, const ENTRIES_PER_BLOCK: usize>
373371 true
374372 }
375373
376- // /// Advance consumer to the next block, unless the producer has not reached the block yet.
377- // fn try_advance_consumer_block(
378- // &mut self,
379- // next_block: &Block<E, ENTRIES_PER_BLOCK>,
380- // curr_consumed: IndexAndVersion<ENTRIES_PER_BLOCK>,
381- // ) -> Result<(), ()> {
382- // if self.can_advance_consumer_block(next_block, curr_consumed) {
383- // *self.ccache = next_block;
384- // Ok(())
385- // } else {
386- // Err(())
387- // }
388- // }
389-
390- /// Todo: Ideally we would not have this function.
391- pub ( crate ) fn has_stealers ( & self ) -> bool {
392- let curr_spos = self . spos . load ( Relaxed ) ;
393- // spos increments beyond NUM_BLOCKS to prevent ABA problems.
394- let start_block_idx = curr_spos % NUM_BLOCKS ;
395- for i in 0 ..NUM_BLOCKS {
396- let block_idx = ( start_block_idx + i) % NUM_BLOCKS ;
397- let blk: & Block < E , ENTRIES_PER_BLOCK > = & self . queue . blocks [ block_idx] ;
398- let stolen = blk. stolen . load ( Relaxed ) ;
399- let reserved = blk. reserved . load ( Relaxed ) ;
400- if reserved != stolen {
401- return true ;
402- } else if !reserved. index ( ) . is_full ( ) {
403- return false ;
404- }
405- }
406- false
374+ /// Check if there are any entries in the next block that are currently being stolen.
375+ pub ( crate ) fn next_block_has_stealers ( & self ) -> bool {
376+ // SAFETY: `pcache` always points to a valid `Block` in the queue. We never create a mutable reference
377+ // to a Block, so it is safe to construct a shared reference here.
378+ let blk = unsafe { & * * self . pcache } ;
379+ let reserved = blk. reserved . load ( Relaxed ) ;
380+ let stolen = blk. stolen . load ( Relaxed ) ;
381+ // If reserved and stolen don't match then there is still an active stealer in the block.
382+ stolen != reserved
407383 }
408384
409385 /// Check if there are entries that can be stolen from the queue.
@@ -450,18 +426,6 @@ impl<E, const NUM_BLOCKS: usize, const ENTRIES_PER_BLOCK: usize>
450426 free_slots
451427 }
452428
453- /// Returns `true` if enqueuing one block of entries would succeed.
454- pub ( crate ) fn can_enqueue_block ( & self ) -> bool {
455- // Note: the current implementation of this function is overly conservative but fast.
456- let current_block = unsafe { & * ( * * self . pcache ) . next ( ) } ;
457- let committed = current_block. committed . load ( Relaxed ) ;
458- if committed. index ( ) . is_empty ( ) {
459- true
460- } else {
461- self . is_next_block_writable ( current_block, committed. version ( ) )
462- }
463- }
464-
465429 /// `true` if there is at least one entry that can be dequeued.
466430 ///
467431 /// It is possible that a dequeue can still fail, since the item was stolen after we checked
@@ -740,7 +704,7 @@ impl<E, const NUM_BLOCKS: usize, const ENTRIES_PER_BLOCK: usize>
740704
741705 /// The estimated number of entries currently enqueued.
742706 #[ cfg( feature = "stats" ) ]
743- pub fn estimated_queue_entries ( & self ) -> usize {
707+ pub ( crate ) fn estimated_queue_entries ( & self ) -> usize {
744708 self . queue . estimated_len ( )
745709 }
746710}
@@ -851,7 +815,6 @@ pub(crate) fn new<E, const NUM_BLOCKS: usize, const ENTRIES_PER_BLOCK: usize>()
851815 Owner {
852816 pcache : CachePadded :: new ( first_block) ,
853817 ccache : CachePadded :: new ( first_block) ,
854- spos : CachePadded :: new ( stealer_position. clone ( ) ) ,
855818 queue : q. clone ( ) ,
856819 } ,
857820 Stealer {
0 commit comments