summaryrefslogtreecommitdiffstats
path: root/src/ring.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2012-01-31 21:12:48 +0000
committerDavid Robillard <d@drobilla.net>2012-01-31 21:12:48 +0000
commit86826ae6733119d462be9f3642161db895756643 (patch)
tree27edf411aeecde4d96c01f1305e8764da963d84b /src/ring.c
parent790aa117d1bd1c012c6982d1c6bd0832eb9d6118 (diff)
downloadzix-86826ae6733119d462be9f3642161db895756643.tar.gz
zix-86826ae6733119d462be9f3642161db895756643.tar.bz2
zix-86826ae6733119d462be9f3642161db895756643.zip
Full test coverage for ZixRing.
Update waf. git-svn-id: http://svn.drobilla.net/zix/trunk@50 df6676b4-ccc9-40e5-b5d6-7c4628a128e3
Diffstat (limited to 'src/ring.c')
-rw-r--r--src/ring.c15
1 files changed, 5 insertions, 10 deletions
diff --git a/src/ring.c b/src/ring.c
index 5edc200..fd5133a 100644
--- a/src/ring.c
+++ b/src/ring.c
@@ -14,7 +14,6 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#include <assert.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
@@ -70,8 +69,6 @@ zix_ring_new(uint32_t size)
ring->size = next_power_of_two(size);
ring->size_mask = ring->size - 1;
ring->buf = malloc(ring->size);
- assert(zix_ring_read_space(ring) == 0);
- assert(zix_ring_write_space(ring) == ring->size - 1);
return ring;
}
@@ -103,7 +100,7 @@ zix_ring_reset(ZixRing* ring)
static inline uint32_t
read_space_internal(const ZixRing* ring, uint32_t r, uint32_t w)
{
- if (w > r) {
+ if (r < w) {
return w - r;
} else {
return (w - r + ring->size) & ring->size_mask;
@@ -119,12 +116,12 @@ zix_ring_read_space(const ZixRing* ring)
static inline uint32_t
write_space_internal(const ZixRing* ring, uint32_t r, uint32_t w)
{
- if (w > r) {
+ if (r == w) {
+ return ring->size - 1;
+ } else if (r < w) {
return ((r - w + ring->size) & ring->size_mask) - 1;
- } else if (w < r) {
- return (r - w) - 1;
} else {
- return ring->size - 1;
+ return (r - w) - 1;
}
}
@@ -212,8 +209,6 @@ zix_ring_write(ZixRing* ring, const void* src, uint32_t size)
ring->write_head = (w + size) & ring->size_mask;
} else {
const uint32_t this_size = ring->size - w;
- assert(this_size < size);
- assert(w + this_size <= ring->size);
memcpy(&ring->buf[w], src, this_size);
memcpy(&ring->buf[0], (char*)src + this_size, size - this_size);
ZIX_WRITE_BARRIER();