File tree 2 files changed +21
-6
lines changed 2 files changed +21
-6
lines changed Original file line number Diff line number Diff line change @@ -168,14 +168,17 @@ impl<T> Block<T> {
168
168
Some ( Read :: Value ( value. assume_init ( ) ) )
169
169
}
170
170
171
- /// Returns true if there is a value in the slot to be consumed
171
+ /// Returns true if *this* block has a value in the given slot.
172
172
///
173
- /// # Safety
174
- ///
175
- /// To maintain safety, the caller must ensure:
176
- ///
177
- /// * No concurrent access to the slot.
173
+ /// Always returns false when given an index from a different block.
178
174
pub ( crate ) fn has_value ( & self , slot_index : usize ) -> bool {
175
+ if slot_index < self . header . start_index {
176
+ return false ;
177
+ }
178
+ if slot_index >= self . header . start_index + super :: BLOCK_CAP {
179
+ return false ;
180
+ }
181
+
179
182
let offset = offset ( slot_index) ;
180
183
let ready_bits = self . header . ready_slots . load ( Acquire ) ;
181
184
is_ready ( ready_bits, offset)
Original file line number Diff line number Diff line change @@ -1421,4 +1421,16 @@ async fn test_rx_unbounded_len_when_close_is_called_after_dropping_sender() {
1421
1421
assert_eq ! ( rx. len( ) , 1 ) ;
1422
1422
}
1423
1423
1424
+ // Regression test for https://github.com/tokio-rs/tokio/issues/6602
1425
+ #[ tokio:: test]
1426
+ async fn test_is_empty_32_msgs ( ) {
1427
+ let ( sender, mut receiver) = mpsc:: channel ( 33 ) ;
1428
+
1429
+ for value in 1 ..257 {
1430
+ sender. send ( value) . await . unwrap ( ) ;
1431
+ receiver. recv ( ) . await . unwrap ( ) ;
1432
+ assert ! ( receiver. is_empty( ) , "{value}. len: {}" , receiver. len( ) ) ;
1433
+ }
1434
+ }
1435
+
1424
1436
fn is_debug < T : fmt:: Debug > ( _: & T ) { }
You can’t perform that action at this time.
0 commit comments