Skip to content

Commit 0b6b4f2

Browse files
authored
Merge pull request hathach#1286 from hathach/fix-fifo-mutex-when-full
fix locked mutex when fifo is full
2 parents 983abfd + 161ba73 commit 0b6b4f2

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

src/common/tusb_fifo.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -741,21 +741,28 @@ bool tu_fifo_write(tu_fifo_t* f, const void * data)
741741
{
742742
_ff_lock(f->mutex_wr);
743743

744-
uint16_t w = f->wr_idx;
744+
bool ret;
745+
uint16_t const w = f->wr_idx;
745746

746-
if ( _tu_fifo_full(f, w, f->rd_idx) && !f->overwritable ) return false;
747+
if ( _tu_fifo_full(f, w, f->rd_idx) && !f->overwritable )
748+
{
749+
ret = false;
750+
}else
751+
{
752+
uint16_t wRel = get_relative_pointer(f, w);
747753

748-
uint16_t wRel = get_relative_pointer(f, w);
754+
// Write data
755+
_ff_push(f, data, wRel);
749756

750-
// Write data
751-
_ff_push(f, data, wRel);
757+
// Advance pointer
758+
f->wr_idx = advance_pointer(f, w, 1);
752759

753-
// Advance pointer
754-
f->wr_idx = advance_pointer(f, w, 1);
760+
ret = true;
761+
}
755762

756763
_ff_unlock(f->mutex_wr);
757764

758-
return true;
765+
return ret;
759766
}
760767

761768
/******************************************************************************/

0 commit comments

Comments
 (0)