99#[ path = "./common_ring_buffer_test.rs" ]
1010mod common_ring_buffer_test;
1111
12+ use super :: RingBufferStats ;
1213#[ cfg( test) ]
1314use super :: test:: thread_synchronizer:: ThreadSynchronizer ;
14- use super :: { RingBufferStats , to_u32} ;
1515use crate :: { AbslCode , Error , Result } ;
1616use bd_client_common:: error:: InvariantError ;
17+ use bd_log_primitives:: LossyIntToU32 ;
1718use parking_lot:: { Condvar , Mutex , MutexGuard } ;
1819use std:: fmt:: Display ;
1920use std:: ptr:: NonNull ;
@@ -229,14 +230,14 @@ impl<ExtraLockedData> LockedData<ExtraLockedData> {
229230 // part of the record. The extra space is always fixed and is the value stored in
230231 // extra_bytes_per_record_.
231232 fn record_size_offset ( & self , start : u32 ) -> u32 {
232- debug_assert ! ( self . extra_bytes_per_record >= to_u32 ( std:: mem:: size_of:: <u32 >( ) ) ) ;
233- start + ( self . extra_bytes_per_record - to_u32 ( std:: mem:: size_of :: < u32 > ( ) ) )
233+ debug_assert ! ( self . extra_bytes_per_record >= std:: mem:: size_of:: <u32 >( ) . to_u32 ( ) ) ;
234+ start + ( self . extra_bytes_per_record - std:: mem:: size_of :: < u32 > ( ) . to_u32 ( ) )
234235 }
235236
236237 // Returns any extra space at the beginning of the reservation. See recordSizeOffset() for more
237238 // information on the record layout.
238239 fn extra_data ( & mut self , start : u32 ) -> & mut [ u8 ] {
239- debug_assert ! ( self . extra_bytes_per_record >= to_u32 ( std:: mem:: size_of:: <u32 >( ) ) ) ;
240+ debug_assert ! ( self . extra_bytes_per_record >= std:: mem:: size_of:: <u32 >( ) . to_u32 ( ) ) ;
240241 let start = start as usize ;
241242 let extra_bytes_per_record = self . extra_bytes_per_record as usize ;
242243 & mut self . memory ( ) [ start .. start + extra_bytes_per_record - std:: mem:: size_of :: < u32 > ( ) ]
@@ -299,7 +300,7 @@ impl<ExtraLockedData> LockedData<ExtraLockedData> {
299300 // space. This can overflow but as long as we are within the memory space crc checks will catch
300301 // further corruption.
301302 let size_index = self . record_size_offset ( next_read_start_to_use) ;
302- if size_index + to_u32 ( std:: mem:: size_of :: < u32 > ( ) ) > to_u32 ( self . memory . 0 . len ( ) ) {
303+ if size_index + std:: mem:: size_of :: < u32 > ( ) . to_u32 ( ) > self . memory . 0 . len ( ) . to_u32 ( ) {
303304 return Err ( Error :: AbslStatus (
304305 AbslCode :: DataLoss ,
305306 "corrupted record size index" . to_string ( ) ,
@@ -318,7 +319,7 @@ impl<ExtraLockedData> LockedData<ExtraLockedData> {
318319 // space crc checks will catch further corruption.
319320 if size == 0
320321 || Self :: overflow_add ( & [ next_read_start_to_use, self . extra_bytes_per_record , size] )
321- . is_none_or ( |next_read_start_index| next_read_start_index > to_u32 ( self . memory . 0 . len ( ) ) )
322+ . is_none_or ( |next_read_start_index| next_read_start_index > self . memory . 0 . len ( ) . to_u32 ( ) )
322323 {
323324 return Err ( Error :: AbslStatus (
324325 AbslCode :: DataLoss ,
@@ -343,7 +344,7 @@ impl<ExtraLockedData> LockedData<ExtraLockedData> {
343344 . last_write_end_before_wrap
344345 . ok_or ( InvariantError :: Invariant ) ?
345346 + 1 ,
346- size : to_u32 ( self . memory . 0 . len ( ) )
347+ size : self . memory . 0 . len ( ) . to_u32 ( )
347348 - ( reservation_data
348349 . last_write_end_before_wrap
349350 . ok_or ( InvariantError :: Invariant ) ?
@@ -469,7 +470,7 @@ impl<ExtraLockedData> LockedData<ExtraLockedData> {
469470 let mut reservation_data = TempReservationData :: default ( ) ;
470471 let next_write_start = * self . next_write_start ( ) ;
471472
472- if next_write_start + write_size <= to_u32 ( self . memory . 0 . len ( ) ) {
473+ if next_write_start + write_size <= self . memory . 0 . len ( ) . to_u32 ( ) {
473474 // It fits in the remainder without wrapping.
474475 reservation_data. range . start = next_write_start;
475476 reservation_data. next_write_start = next_write_start + write_size;
@@ -529,7 +530,7 @@ impl<ExtraLockedData> LockedData<ExtraLockedData> {
529530 } ;
530531
531532 // If size is 0 or > then the ring buffer size we can't do anything.
532- if size == 0 || actual_size > to_u32 ( self . memory . 0 . len ( ) ) {
533+ if size == 0 || actual_size > self . memory . 0 . len ( ) . to_u32 ( ) {
533534 log:: trace!( "({}) invalid reservation size: {}" , self . name, size) ;
534535 // Note that we don't record the bytes lost in this case, since a very large number is likely
535536 // to cause overflow.
@@ -996,7 +997,7 @@ impl<ExtraLockedData> CommonRingBuffer<ExtraLockedData> {
996997 lock_count : AtomicU32 :: default ( ) . into ( ) ,
997998 shutdown_lock : None ,
998999 stats,
999- extra_bytes_per_record : extra_bytes_per_record + to_u32 ( std:: mem:: size_of :: < u32 > ( ) ) ,
1000+ extra_bytes_per_record : extra_bytes_per_record + std:: mem:: size_of :: < u32 > ( ) . to_u32 ( ) ,
10001001 extra_locked_data,
10011002 allow_overwrite,
10021003 on_total_data_loss_cb : Box :: new ( on_total_data_loss_cb) ,
0 commit comments