fix locked mutex when fifo is full

This commit is contained in:
hathach 2022-01-19 10:17:39 +07:00
parent 84f2ca77f7
commit 161ba73c8b
No known key found for this signature in database
GPG Key ID: 2FA891220FBFD581
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;
}
/******************************************************************************/