提交 7a81d3d6 编写于 作者: J jp9000

libobs/util: Add circlebuf pop_back/peek_back functions

上级 c2168cf9
......@@ -208,6 +208,29 @@ static inline void circlebuf_peek_front(struct circlebuf *cb, void *data,
}
}
static inline void circlebuf_peek_back(struct circlebuf *cb, void *data,
size_t size)
{
assert(size <= cb->size);
if (data) {
size_t back_size = (cb->end_pos ? cb->end_pos : cb->capacity);
if (back_size < size) {
size_t front_size = size - back_size;
size_t new_end_pos = cb->capacity - front_size;
memcpy((uint8_t*)data + (size - back_size), cb->data,
back_size);
memcpy(data, (uint8_t*)cb->data + new_end_pos,
front_size);
} else {
memcpy(data, (uint8_t*)cb->data + cb->end_pos - size,
size);
}
}
}
static inline void circlebuf_pop_front(struct circlebuf *cb, void *data,
size_t size)
{
......@@ -219,6 +242,18 @@ static inline void circlebuf_pop_front(struct circlebuf *cb, void *data,
cb->start_pos -= cb->capacity;
}
static inline void circlebuf_pop_back(struct circlebuf *cb, void *data,
size_t size)
{
circlebuf_peek_front(cb, data, size);
cb->size -= size;
if (cb->end_pos <= size)
cb->end_pos = cb->capacity - (size - cb->end_pos);
else
cb->end_pos -= size;
}
#ifdef __cplusplus
}
#endif
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册