Merge pull request #1286 from hathach/fix-fifo-mutex-when-full

fix locked mutex when fifo is full
This commit is contained in:
Ha Thach 2022-01-19 10:45:33 +07:00 committed by GitHub
commit 0b6b4f2441
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 8 deletions

View File

@ -741,21 +741,28 @@ bool tu_fifo_write(tu_fifo_t* f, const void * data)
{
_ff_lock(f->mutex_wr);
uint16_t w = f->wr_idx;
bool ret;
uint16_t const w = f->wr_idx;
if ( _tu_fifo_full(f, w, f->rd_idx) && !f->overwritable ) return false;
if ( _tu_fifo_full(f, w, f->rd_idx) && !f->overwritable )
{
ret = false;
}else
{
uint16_t wRel = get_relative_pointer(f, w);
uint16_t wRel = get_relative_pointer(f, w);
// Write data
_ff_push(f, data, wRel);
// Write data
_ff_push(f, data, wRel);
// Advance pointer
f->wr_idx = advance_pointer(f, w, 1);
// Advance pointer
f->wr_idx = advance_pointer(f, w, 1);
ret = true;
}
_ff_unlock(f->mutex_wr);
return true;
return ret;
}
/******************************************************************************/