mm/circbuf: add circ_peekat to read data with specified postion
Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
This commit is contained in:
parent
a853c70093
commit
6e1244c274
|
@ -198,11 +198,35 @@ size_t circbuf_used(FAR struct circbuf_s *circ);
|
|||
|
||||
size_t circbuf_space(FAR struct circbuf_s *circ);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: circbuf_peekat
|
||||
*
|
||||
* Description:
|
||||
* Get data speicified position from the circular buffer without removing
|
||||
*
|
||||
* Note :
|
||||
* That with only one concurrent reader and one concurrent writer,
|
||||
* you don't need extra locking to use these api.
|
||||
*
|
||||
* Input Parameters:
|
||||
* circ - Address of the circular buffer to be used.
|
||||
* pos - Position to read.
|
||||
* dst - Address where to store the data.
|
||||
* bytes - Number of bytes to get.
|
||||
*
|
||||
* Returned Value:
|
||||
* The bytes of get data is returned if the peek data is successful;
|
||||
* A negated errno value is returned on any failure.
|
||||
****************************************************************************/
|
||||
|
||||
ssize_t circbuf_peekat(FAR struct circbuf_s *circ, size_t pos,
|
||||
FAR void *dst, size_t bytes);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: circbuf_peek
|
||||
*
|
||||
* Description:
|
||||
* Get data form the circular buffer without removing
|
||||
* Get data from the circular buffer without removing
|
||||
*
|
||||
* Note :
|
||||
* That with only one concurrent reader and one concurrent writer,
|
||||
|
@ -225,7 +249,7 @@ ssize_t circbuf_peek(FAR struct circbuf_s *circ,
|
|||
* Name: circbuf_read
|
||||
*
|
||||
* Description:
|
||||
* Get data form the circular buffer.
|
||||
* Get data from the circular buffer.
|
||||
*
|
||||
* Note :
|
||||
* That with only one concurrent reader and one concurrent writer,
|
||||
|
@ -248,7 +272,7 @@ ssize_t circbuf_read(FAR struct circbuf_s *circ,
|
|||
* Name: circbuf_skip
|
||||
*
|
||||
* Description:
|
||||
* Skip data form the circular buffer.
|
||||
* Skip data from the circular buffer.
|
||||
*
|
||||
* Note:
|
||||
* That with only one concurrent reader and one concurrent writer,
|
||||
|
|
|
@ -273,10 +273,10 @@ bool circbuf_is_full(FAR struct circbuf_s *circ)
|
|||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: circbuf_peek
|
||||
* Name: circbuf_peekat
|
||||
*
|
||||
* Description:
|
||||
* Get data form the circular buffer without removing
|
||||
* Get data speicified position from the circular buffer without removing
|
||||
*
|
||||
* Note :
|
||||
* That with only one concurrent reader and one concurrent writer,
|
||||
|
@ -284,6 +284,7 @@ bool circbuf_is_full(FAR struct circbuf_s *circ)
|
|||
*
|
||||
* Input Parameters:
|
||||
* circ - Address of the circular buffer to be used.
|
||||
* pos - Position to read.
|
||||
* dst - Address where to store the data.
|
||||
* bytes - Number of bytes to get.
|
||||
*
|
||||
|
@ -292,8 +293,8 @@ bool circbuf_is_full(FAR struct circbuf_s *circ)
|
|||
* A negated errno value is returned on any failure.
|
||||
****************************************************************************/
|
||||
|
||||
ssize_t circbuf_peek(FAR struct circbuf_s *circ,
|
||||
FAR void *dst, size_t bytes)
|
||||
ssize_t circbuf_peekat(FAR struct circbuf_s *circ, size_t pos,
|
||||
FAR void *dst, size_t bytes)
|
||||
{
|
||||
size_t len;
|
||||
size_t off;
|
||||
|
@ -306,7 +307,7 @@ ssize_t circbuf_peek(FAR struct circbuf_s *circ,
|
|||
}
|
||||
|
||||
len = circbuf_used(circ);
|
||||
off = circ->tail % circ->size;
|
||||
off = pos % circ->size;
|
||||
|
||||
if (bytes > len)
|
||||
{
|
||||
|
@ -325,11 +326,37 @@ ssize_t circbuf_peek(FAR struct circbuf_s *circ,
|
|||
return bytes;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: circbuf_peek
|
||||
*
|
||||
* Description:
|
||||
* Get data from the circular buffer without removing
|
||||
*
|
||||
* Note :
|
||||
* That with only one concurrent reader and one concurrent writer,
|
||||
* you don't need extra locking to use these api.
|
||||
*
|
||||
* Input Parameters:
|
||||
* circ - Address of the circular buffer to be used.
|
||||
* dst - Address where to store the data.
|
||||
* bytes - Number of bytes to get.
|
||||
*
|
||||
* Returned Value:
|
||||
* The bytes of get data is returned if the peek data is successful;
|
||||
* A negated errno value is returned on any failure.
|
||||
****************************************************************************/
|
||||
|
||||
ssize_t circbuf_peek(FAR struct circbuf_s *circ,
|
||||
FAR void *dst, size_t bytes)
|
||||
{
|
||||
return circbuf_peekat(circ, circ->tail, dst, bytes);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: circbuf_read
|
||||
*
|
||||
* Description:
|
||||
* Get data form the circular buffer.
|
||||
* Get data from the circular buffer.
|
||||
*
|
||||
* Note :
|
||||
* That with only one concurrent reader and one concurrent writer,
|
||||
|
@ -346,7 +373,7 @@ ssize_t circbuf_peek(FAR struct circbuf_s *circ,
|
|||
****************************************************************************/
|
||||
|
||||
ssize_t circbuf_read(FAR struct circbuf_s *circ,
|
||||
FAR void *dst, size_t bytes)
|
||||
FAR void *dst, size_t bytes)
|
||||
{
|
||||
DEBUGASSERT(circ);
|
||||
DEBUGASSERT(dst || !bytes);
|
||||
|
@ -361,7 +388,7 @@ ssize_t circbuf_read(FAR struct circbuf_s *circ,
|
|||
* Name: circbuf_skip
|
||||
*
|
||||
* Description:
|
||||
* Skip data form the circular buffer.
|
||||
* Skip data from the circular buffer.
|
||||
*
|
||||
* Note :
|
||||
* That with only one concurrent reader and one concurrent writer,
|
||||
|
@ -415,7 +442,7 @@ ssize_t circbuf_skip(FAR struct circbuf_s *circ, size_t bytes)
|
|||
****************************************************************************/
|
||||
|
||||
ssize_t circbuf_write(FAR struct circbuf_s *circ,
|
||||
FAR const void *src, size_t bytes)
|
||||
FAR const void *src, size_t bytes)
|
||||
{
|
||||
size_t space;
|
||||
size_t off;
|
||||
|
@ -471,7 +498,7 @@ ssize_t circbuf_write(FAR struct circbuf_s *circ,
|
|||
****************************************************************************/
|
||||
|
||||
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 space;
|
||||
|
|
Loading…
Reference in New Issue