Mercurial > hg > th-libs
changeset 28:c47dcb8a4ffe
Change how ringbuffer actually works to be more sensible.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 11 Jun 2011 05:01:38 +0300 |
parents | 4232dc54b818 |
children | 04cfdefc3253 |
files | th_util.c |
diffstat | 1 files changed, 5 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/th_util.c Sat Jun 11 05:01:14 2011 +0300 +++ b/th_util.c Sat Jun 11 05:01:38 2011 +0300 @@ -435,12 +435,10 @@ void th_ringbuf_add(qringbuf_t *buf, void *ptr) { - if (buf->n < buf->size) { - buf->data[buf->n] = ptr; + if (buf->n < buf->size) buf->n++; - } else { - th_free(buf->data[0]); - memmove(&(buf->data[0]), &(buf->data[1]), buf->size - 1); - buf->data[buf->size - 1] = ptr; - } + + th_free(buf->data[0]); + memmove(&(buf->data[0]), &(buf->data[1]), (buf->size - 1) * sizeof(void *)); + buf->data[buf->size - 1] = ptr; }