@@ -62,8 +62,6 @@ pub(crate) struct Owner<E, const NUM_BLOCKS: usize, const ENTRIES_PER_BLOCK: usi
62
62
pcache : CachePadded < * const Block < E , { ENTRIES_PER_BLOCK } > > ,
63
63
/// Consumer cache (single consumer) - points to block in self.queue.
64
64
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 > > ,
67
65
/// `Arc` to the actual queue to ensure the queue lives at least as long as the Owner.
68
66
#[ allow( dead_code) ]
69
67
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>
373
371
true
374
372
}
375
373
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
407
383
}
408
384
409
385
/// 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>
450
426
free_slots
451
427
}
452
428
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
-
465
429
/// `true` if there is at least one entry that can be dequeued.
466
430
///
467
431
/// 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>
740
704
741
705
/// The estimated number of entries currently enqueued.
742
706
#[ cfg( feature = "stats" ) ]
743
- pub fn estimated_queue_entries ( & self ) -> usize {
707
+ pub ( crate ) fn estimated_queue_entries ( & self ) -> usize {
744
708
self . queue . estimated_len ( )
745
709
}
746
710
}
@@ -851,7 +815,6 @@ pub(crate) fn new<E, const NUM_BLOCKS: usize, const ENTRIES_PER_BLOCK: usize>()
851
815
Owner {
852
816
pcache : CachePadded :: new ( first_block) ,
853
817
ccache : CachePadded :: new ( first_block) ,
854
- spos : CachePadded :: new ( stealer_position. clone ( ) ) ,
855
818
queue : q. clone ( ) ,
856
819
} ,
857
820
Stealer {
0 commit comments