@@ -319,35 +319,35 @@ static void _ff_pull_n(tu_fifo_t* f, void* app_buf, uint16_t n, uint16_t rel, tu
319319
320320// Advance an absolute index
321321// "absolute" index is only in the range of [0..2*depth)
322- static uint16_t advance_pointer ( tu_fifo_t * f , uint16_t idx , uint16_t offset )
322+ static uint16_t advance_index ( uint16_t depth , uint16_t idx , uint16_t offset )
323323{
324324 // We limit the index space of p such that a correct wrap around happens
325325 // Check for a wrap around or if we are in unused index space - This has to be checked first!!
326326 // We are exploiting the wrap around to the correct index
327- uint16_t next_p = (uint16_t ) (idx + offset );
328- if ( (idx > next_p ) || (next_p >= 2 * f -> depth ) )
327+ uint16_t new_idx = (uint16_t ) (idx + offset );
328+ if ( (idx > new_idx ) || (new_idx >= 2 * depth ) )
329329 {
330- uint16_t const non_used_index_space = (uint16_t ) (UINT16_MAX - (2 * f -> depth - 1 ));
331- next_p = (uint16_t ) (next_p + non_used_index_space );
330+ uint16_t const non_used_index_space = (uint16_t ) (UINT16_MAX - (2 * depth - 1 ));
331+ new_idx = (uint16_t ) (new_idx + non_used_index_space );
332332 }
333333
334- return next_p ;
334+ return new_idx ;
335335}
336336
337- // Backward an absolute pointer
338- static uint16_t backward_pointer ( tu_fifo_t * f , uint16_t p , uint16_t offset )
337+ // Backward an absolute index
338+ static uint16_t backward_index ( uint16_t depth , uint16_t idx , uint16_t offset )
339339{
340340 // We limit the index space of p such that a correct wrap around happens
341341 // Check for a wrap around or if we are in unused index space - This has to be checked first!!
342342 // We are exploiting the wrap around to the correct index
343- uint16_t new_p = (uint16_t ) (p - offset );
344- if ( (p < new_p ) || (new_p >= 2 * f -> depth ) )
343+ uint16_t new_idx = (uint16_t ) (idx - offset );
344+ if ( (idx < new_idx ) || (new_idx >= 2 * depth ) )
345345 {
346- uint16_t const non_used_index_space = (uint16_t ) (UINT16_MAX - (2 * f -> depth - 1 ));
347- new_p = (uint16_t ) (new_p - non_used_index_space );
346+ uint16_t const non_used_index_space = (uint16_t ) (UINT16_MAX - (2 * depth - 1 ));
347+ new_idx = (uint16_t ) (new_idx - non_used_index_space );
348348 }
349349
350- return new_p ;
350+ return new_idx ;
351351}
352352
353353// index to pointer, simply an modulo with minus.
@@ -394,9 +394,9 @@ uint16_t _ff_remaining(uint16_t depth, uint16_t wr_idx, uint16_t rd_idx)
394394// Works on local copies of w
395395// For more details see _tu_fifo_overflow()!
396396TU_ATTR_ALWAYS_INLINE static inline
397- void _tu_fifo_correct_read_pointer (tu_fifo_t * f , uint16_t wAbs )
397+ void _tu_fifo_correct_read_pointer (tu_fifo_t * f , uint16_t wr_idx )
398398{
399- f -> rd_idx = backward_pointer ( f , wAbs , f -> depth );
399+ f -> rd_idx = backward_index ( f -> depth , wr_idx , f -> depth );
400400}
401401
402402// Works on local copies of w and r
@@ -502,7 +502,7 @@ static uint16_t _tu_fifo_write_n(tu_fifo_t* f, const void * data, uint16_t n, tu
502502 // Double overflowed
503503 // Index is bigger than the allowed range [0,2*depth)
504504 // re-position write index to have a full fifo after pushed
505- wr_idx = advance_pointer ( f , rd_idx , f -> depth - n );
505+ wr_idx = advance_index ( f -> depth , rd_idx , f -> depth - n );
506506
507507 // TODO we should also shift out n bytes from read index since we avoid changing rd index !!
508508 // However memmove() is expensive due to actual copying + wrapping consideration.
@@ -528,7 +528,7 @@ static uint16_t _tu_fifo_write_n(tu_fifo_t* f, const void * data, uint16_t n, tu
528528 _ff_push_n (f , buf8 , n , wr_ptr , copy_mode );
529529
530530 // Advance index
531- f -> wr_idx = advance_pointer ( f , wr_idx , n );
531+ f -> wr_idx = advance_index ( f -> depth , wr_idx , n );
532532
533533 TU_LOG (TU_FIFO_DBG , "\tnew_wr = %u\n" , f -> wr_idx );
534534 }
@@ -547,7 +547,7 @@ static uint16_t _tu_fifo_read_n(tu_fifo_t* f, void * buffer, uint16_t n, tu_fifo
547547 n = _tu_fifo_peek_n (f , buffer , n , f -> wr_idx , f -> rd_idx , copy_mode );
548548
549549 // Advance read pointer
550- f -> rd_idx = advance_pointer ( f , f -> rd_idx , n );
550+ f -> rd_idx = advance_index ( f -> depth , f -> rd_idx , n );
551551
552552 _ff_unlock (f -> mutex_rd );
553553 return n ;
@@ -690,7 +690,7 @@ bool tu_fifo_read(tu_fifo_t* f, void * buffer)
690690 bool ret = _tu_fifo_peek (f , buffer , f -> wr_idx , f -> rd_idx );
691691
692692 // Advance pointer
693- f -> rd_idx = advance_pointer ( f , f -> rd_idx , ret );
693+ f -> rd_idx = advance_index ( f -> depth , f -> rd_idx , ret );
694694
695695 _ff_unlock (f -> mutex_rd );
696696 return ret ;
@@ -800,7 +800,7 @@ bool tu_fifo_write(tu_fifo_t* f, const void * data)
800800 _ff_push (f , data , wr_ptr );
801801
802802 // Advance pointer
803- f -> wr_idx = advance_pointer ( f , wr_idx , 1 );
803+ f -> wr_idx = advance_index ( f -> depth , wr_idx , 1 );
804804
805805 ret = true;
806806 }
@@ -911,7 +911,7 @@ bool tu_fifo_set_overwritable(tu_fifo_t *f, bool overwritable)
911911/******************************************************************************/
912912void tu_fifo_advance_write_pointer (tu_fifo_t * f , uint16_t n )
913913{
914- f -> wr_idx = advance_pointer ( f , f -> wr_idx , n );
914+ f -> wr_idx = advance_index ( f -> depth , f -> wr_idx , n );
915915}
916916
917917/******************************************************************************/
@@ -932,7 +932,7 @@ void tu_fifo_advance_write_pointer(tu_fifo_t *f, uint16_t n)
932932/******************************************************************************/
933933void tu_fifo_advance_read_pointer (tu_fifo_t * f , uint16_t n )
934934{
935- f -> rd_idx = advance_pointer ( f , f -> rd_idx , n );
935+ f -> rd_idx = advance_index ( f -> depth , f -> rd_idx , n );
936936}
937937
938938/******************************************************************************/
0 commit comments