all repos — mgba @ 10fc916425cbd4650bf8c8a56f8c9428bed052d7

mGBA Game Boy Advance Emulator

Revise circle buffer types
Jeffrey Pfau jeffrey@endrift.com
Sun, 20 Jul 2014 23:56:12 -0700
commit

10fc916425cbd4650bf8c8a56f8c9428bed052d7

parent

eabac4c413c0b83caa4b9a97c6ab6dc3997b4ca0

2 files changed, 16 insertions(+), 11 deletions(-)

jump to
M src/util/circle-buffer.csrc/util/circle-buffer.c

@@ -2,13 +2,13 @@ #include "circle-buffer.h"

#ifndef NDEBUG static int _checkIntegrity(struct CircleBuffer* buffer) { - if ((int8_t*) buffer->writePtr - (int8_t*) buffer->readPtr == buffer->size) { + if ((int8_t*) buffer->writePtr - (int8_t*) buffer->readPtr == (ssize_t) buffer->size) { return 1; } - if (buffer->capacity - buffer->size == ((int8_t*) buffer->writePtr - (int8_t*) buffer->readPtr)) { + if ((ssize_t) (buffer->capacity - buffer->size) == ((int8_t*) buffer->writePtr - (int8_t*) buffer->readPtr)) { return 1; } - if (buffer->capacity - buffer->size == ((int8_t*) buffer->readPtr - (int8_t*) buffer->writePtr)) { + if ((ssize_t) (buffer->capacity - buffer->size) == ((int8_t*) buffer->readPtr - (int8_t*) buffer->writePtr)) { return 1; } return 0;

@@ -26,8 +26,12 @@ free(buffer->data);

buffer->data = 0; } -unsigned CircleBufferSize(const struct CircleBuffer* buffer) { +size_t CircleBufferSize(const struct CircleBuffer* buffer) { return buffer->size; +} + +size_t CircleBufferCapacity(const struct CircleBuffer* buffer) { + return buffer->capacity; } void CircleBufferClear(struct CircleBuffer* buffer) {

@@ -140,7 +144,7 @@ #endif

return 4; } -int CircleBufferRead(struct CircleBuffer* buffer, void* output, size_t length) { +size_t CircleBufferRead(struct CircleBuffer* buffer, void* output, size_t length) { int8_t* data = buffer->readPtr; if (buffer->size == 0) { return 0;

@@ -171,7 +175,7 @@ #endif

return length; } -int CircleBufferDump(const struct CircleBuffer* buffer, void* output, size_t length) { +size_t CircleBufferDump(const struct CircleBuffer* buffer, void* output, size_t length) { int8_t* data = buffer->readPtr; if (buffer->size == 0) { return 0;
M src/util/circle-buffer.hsrc/util/circle-buffer.h

@@ -5,21 +5,22 @@ #include "common.h"

struct CircleBuffer { void* data; - unsigned capacity; - unsigned size; + size_t capacity; + size_t size; void* readPtr; void* writePtr; }; void CircleBufferInit(struct CircleBuffer* buffer, unsigned capacity); void CircleBufferDeinit(struct CircleBuffer* buffer); -unsigned CircleBufferSize(const struct CircleBuffer* buffer); +size_t CircleBufferSize(const struct CircleBuffer* buffer); +size_t CircleBufferCapacity(const struct CircleBuffer* buffer); void CircleBufferClear(struct CircleBuffer* buffer); int CircleBufferWrite8(struct CircleBuffer* buffer, int8_t value); int CircleBufferWrite32(struct CircleBuffer* buffer, int32_t value); int CircleBufferRead8(struct CircleBuffer* buffer, int8_t* value); int CircleBufferRead32(struct CircleBuffer* buffer, int32_t* value); -int CircleBufferRead(struct CircleBuffer* buffer, void* output, size_t length); -int CircleBufferDump(const struct CircleBuffer* buffer, void* output, size_t length); +size_t CircleBufferRead(struct CircleBuffer* buffer, void* output, size_t length); +size_t CircleBufferDump(const struct CircleBuffer* buffer, void* output, size_t length); #endif