summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorhathach <[email protected]>2022-01-19 10:17:39 +0700
committerhathach <[email protected]>2022-01-19 10:17:39 +0700
commit161ba73c8b01c6de637309fbfc8c6dcea58c9d06 (patch)
tree2969973246130dc9d76629bbc07072c54817dccd /src
parent84f2ca77f78d8a79d08377ba08ce72ca8e3da239 (diff)
fix locked mutex when fifo is full
Diffstat (limited to 'src')
-rw-r--r--src/common/tusb_fifo.c23
1 files changed, 15 insertions, 8 deletions
diff --git a/src/common/tusb_fifo.c b/src/common/tusb_fifo.c
index 564687e02..0d35405db 100644
--- a/src/common/tusb_fifo.c
+++ b/src/common/tusb_fifo.c
@@ -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;
}
/******************************************************************************/