mm/circbuf: update buffer head according to real length of writing
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
This commit is contained in:
parent
49ce1c5df7
commit
89e8409244
|
@ -501,6 +501,7 @@ ssize_t circbuf_overwrite(FAR struct circbuf_s *circ,
|
||||||
FAR const void *src, size_t bytes)
|
FAR const void *src, size_t bytes)
|
||||||
{
|
{
|
||||||
size_t overwrite = 0;
|
size_t overwrite = 0;
|
||||||
|
size_t skip = 0;
|
||||||
size_t space;
|
size_t space;
|
||||||
size_t off;
|
size_t off;
|
||||||
|
|
||||||
|
@ -514,14 +515,15 @@ ssize_t circbuf_overwrite(FAR struct circbuf_s *circ,
|
||||||
|
|
||||||
if (bytes > circ->size)
|
if (bytes > circ->size)
|
||||||
{
|
{
|
||||||
src = (FAR const void *)((FAR char *)src + bytes - circ->size);
|
skip = bytes - circ->size;
|
||||||
|
src = (FAR const void *)((FAR char *)src + skip);
|
||||||
bytes = circ->size;
|
bytes = circ->size;
|
||||||
}
|
}
|
||||||
|
|
||||||
space = circbuf_space(circ);
|
space = circbuf_space(circ);
|
||||||
if (bytes > space)
|
if (bytes > space)
|
||||||
{
|
{
|
||||||
overwrite = bytes - space;
|
overwrite = bytes - space + skip;
|
||||||
}
|
}
|
||||||
|
|
||||||
off = circ->head % circ->size;
|
off = circ->head % circ->size;
|
||||||
|
@ -533,7 +535,7 @@ ssize_t circbuf_overwrite(FAR struct circbuf_s *circ,
|
||||||
|
|
||||||
memcpy((FAR char *)circ->base + off, src, space);
|
memcpy((FAR char *)circ->base + off, src, space);
|
||||||
memcpy(circ->base, (FAR char *)src + space, bytes - space);
|
memcpy(circ->base, (FAR char *)src + space, bytes - space);
|
||||||
circ->head += bytes;
|
circ->head += bytes + skip;
|
||||||
circ->tail += overwrite;
|
circ->tail += overwrite;
|
||||||
|
|
||||||
return overwrite;
|
return overwrite;
|
||||||
|
|
Loading…
Reference in New Issue