mirror of
https://github.com/apache/nuttx.git
synced 2026-06-02 01:21:26 +08:00
circbuf: fix circbuf_get_read/writeptr return *size = 0 when circbuf full
In circbuf_get_read/writeptr, when circbuf is full, off == pos, and *size = off - pos = 0. So add circbuf_is_full() condition to return correct *size. Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
This commit is contained in:
@@ -567,20 +567,15 @@ ssize_t circbuf_overwrite(FAR struct circbuf_s *circ,
|
|||||||
FAR void *circbuf_get_writeptr(FAR struct circbuf_s *circ, FAR size_t *size)
|
FAR void *circbuf_get_writeptr(FAR struct circbuf_s *circ, FAR size_t *size)
|
||||||
{
|
{
|
||||||
size_t off;
|
size_t off;
|
||||||
size_t pos;
|
|
||||||
|
|
||||||
DEBUGASSERT(circ);
|
DEBUGASSERT(circ);
|
||||||
|
|
||||||
|
*size = circbuf_space(circ);
|
||||||
off = circ->head % circ->size;
|
off = circ->head % circ->size;
|
||||||
pos = circ->tail % circ->size;
|
if (off + *size > circ->size)
|
||||||
if (off >= pos)
|
|
||||||
{
|
{
|
||||||
*size = circ->size - off;
|
*size = circ->size - off;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
*size = pos - off;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (FAR char *)circ->base + off;
|
return (FAR char *)circ->base + off;
|
||||||
}
|
}
|
||||||
@@ -603,22 +598,17 @@ FAR void *circbuf_get_writeptr(FAR struct circbuf_s *circ, FAR size_t *size)
|
|||||||
FAR void *circbuf_get_readptr(FAR struct circbuf_s *circ, size_t *size)
|
FAR void *circbuf_get_readptr(FAR struct circbuf_s *circ, size_t *size)
|
||||||
{
|
{
|
||||||
size_t off;
|
size_t off;
|
||||||
size_t pos;
|
|
||||||
|
|
||||||
DEBUGASSERT(circ);
|
DEBUGASSERT(circ);
|
||||||
|
|
||||||
off = circ->head % circ->size;
|
*size = circbuf_used(circ);
|
||||||
pos = circ->tail % circ->size;
|
off = circ->tail % circ->size;
|
||||||
if (pos > off)
|
if (off + *size > circ->size)
|
||||||
{
|
{
|
||||||
*size = circ->size - pos;
|
*size = circ->size - off;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
*size = off - pos;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (FAR char *)circ->base + pos;
|
return (FAR char *)circ->base + off;
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
|
|||||||
Reference in New Issue
Block a user