Free ringbuf buffer by relying on gc, not gc_free()

This commit is contained in:
Dan Halbert 2022-04-04 20:34:49 -04:00
parent faca1ec3bf
commit b29b7bfe32
2 changed files with 2 additions and 6 deletions

View File

@ -28,7 +28,6 @@
#include "ringbuf.h" #include "ringbuf.h"
bool ringbuf_init(ringbuf_t *r, uint8_t *buf, size_t capacity) { bool ringbuf_init(ringbuf_t *r, uint8_t *buf, size_t capacity) {
r->heap = false;
r->buf = buf; r->buf = buf;
r->size = capacity; r->size = capacity;
r->iget = r->iput = 0; r->iget = r->iput = 0;
@ -40,7 +39,6 @@ bool ringbuf_init(ringbuf_t *r, uint8_t *buf, size_t capacity) {
// size of the buffer is one greater than that, due to how the buffer // size of the buffer is one greater than that, due to how the buffer
// handles empty and full statuses. // handles empty and full statuses.
bool ringbuf_alloc(ringbuf_t *r, size_t capacity, bool long_lived) { bool ringbuf_alloc(ringbuf_t *r, size_t capacity, bool long_lived) {
r->heap = true;
r->buf = gc_alloc(capacity + 1, false, long_lived); r->buf = gc_alloc(capacity + 1, false, long_lived);
r->size = capacity + 1; r->size = capacity + 1;
r->iget = r->iput = 0; r->iget = r->iput = 0;
@ -48,9 +46,8 @@ bool ringbuf_alloc(ringbuf_t *r, size_t capacity, bool long_lived) {
} }
void ringbuf_free(ringbuf_t *r) { void ringbuf_free(ringbuf_t *r) {
if (r->heap) { // Free buf by letting gc take care of it. If the VM has finished already,
gc_free(r->buf); // this will be safe.
}
r->buf = (uint8_t *)NULL; r->buf = (uint8_t *)NULL;
r->size = 0; r->size = 0;
ringbuf_clear(r); ringbuf_clear(r);

View File

@ -37,7 +37,6 @@ typedef struct _ringbuf_t {
uint32_t size; uint32_t size;
uint32_t iget; uint32_t iget;
uint32_t iput; uint32_t iput;
bool heap;
} ringbuf_t; } ringbuf_t;
// Note that the capacity of the buffer is N-1! // Note that the capacity of the buffer is N-1!