diff options
author | Richard Braun <rbraun@sceen.net> | 2017-07-24 23:30:11 +0200 |
---|---|---|
committer | Richard Braun <rbraun@sceen.net> | 2017-07-24 23:30:11 +0200 |
commit | f504f743a969a82012a8c60283fe130c1dc5d74f (patch) | |
tree | aa7098e89d9e70ef5c0b3d3915f4525d99333f49 /kern/cbuf.h | |
parent | 6e16ff5a6002400489349f55cc7961bccf2fe520 (diff) |
kern/cbuf: update from upstream
Diffstat (limited to 'kern/cbuf.h')
-rw-r--r-- | kern/cbuf.h | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/kern/cbuf.h b/kern/cbuf.h index 4d69334..726435d 100644 --- a/kern/cbuf.h +++ b/kern/cbuf.h @@ -84,12 +84,35 @@ cbuf_range_valid(const struct cbuf *cbuf, size_t start, size_t end) void cbuf_init(struct cbuf *cbuf, char *buf, size_t capacity); /* + * Append a buffer to a circular buffer. + * + * If erasing old data is not allowed, and the circular buffer doesn't have + * enough unused bytes for the new data, ERROR_AGAIN is returned. Otherwise, + * the end index is increased by the new data size, possibly erasing old + * data, in which case, the start index is updated accordingly. + */ +int cbuf_push(struct cbuf *cbuf, const void *buf, size_t size, bool erase); + +/* + * Read bytes from a circular buffer. + * + * If the buffer is empty, ERROR_AGAIN is returned. Otherwise, the oldest + * bytes are stored into the given buffer. On entry, the sizep argument points + * to the size of the given buffer. On exit, that value is updated to the + * number of bytes actually stored. If successful, the start index is increased + * by the amount of bytes read. + */ +int cbuf_pop(struct cbuf *cbuf, void *buf, size_t *sizep); + +/* * Append a byte to a circular buffer. * - * The end index is incremented. If the buffer is full, the oldest byte - * is overwritten and the start index is updated accordingly. + * If erasing old data is not allowed, and the circular buffer is full, + * ERROR_AGAIN is returned. Otherwise, the end index is incremented and, if the + * buffer is full, the oldest byte is overwritten and the start index + * is updated accordingly. */ -void cbuf_push(struct cbuf *cbuf, char byte); +int cbuf_pushb(struct cbuf *cbuf, char byte, bool erase); /* * Read a byte from a circular buffer. @@ -98,7 +121,7 @@ void cbuf_push(struct cbuf *cbuf, char byte); * byte is stored at the bytep address, the start index is incremented, * and 0 is returned. */ -int cbuf_pop(struct cbuf *cbuf, char *bytep); +int cbuf_popb(struct cbuf *cbuf, char *bytep); /* * Write into a circular buffer at a specific location. |