Mercurial > hg > th-libs
comparison th_datastruct.c @ 730:1a3ea8f7bb35
Use specified deallocator for ringbuffers when rotating.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 07 Dec 2022 00:06:45 +0200 |
parents | 29e44a58bc73 |
children | 98d12f33da7b |
comparison
equal
deleted
inserted
replaced
729:ef1521b179b1 | 730:1a3ea8f7bb35 |
---|---|
342 | 342 |
343 void th_ringbuf_free(th_ringbuf_t *buf) | 343 void th_ringbuf_free(th_ringbuf_t *buf) |
344 { | 344 { |
345 for (size_t i = 0; i < buf->size; i++) | 345 for (size_t i = 0; i < buf->size; i++) |
346 { | 346 { |
347 if (buf->data[i] != NULL) | 347 buf->deallocator(buf->data[i]); |
348 buf->deallocator(buf->data[i]); | |
349 } | 348 } |
350 | 349 |
351 th_free(buf->data); | 350 th_free(buf->data); |
352 | 351 |
353 if (buf->allocated) | 352 if (buf->allocated) |
358 void th_ringbuf_add(th_ringbuf_t *buf, void *ptr) | 357 void th_ringbuf_add(th_ringbuf_t *buf, void *ptr) |
359 { | 358 { |
360 if (buf->n < buf->size) | 359 if (buf->n < buf->size) |
361 buf->n++; | 360 buf->n++; |
362 | 361 |
363 th_free(buf->data[0]); | 362 buf->deallocator(buf->data[0]); |
364 memmove(&(buf->data[0]), &(buf->data[1]), (buf->size - 1) * sizeof(void *)); | 363 memmove(&(buf->data[0]), &(buf->data[1]), (buf->size - 1) * sizeof(void *)); |
365 buf->data[buf->size - 1] = ptr; | 364 buf->data[buf->size - 1] = ptr; |
366 } | 365 } |
367 | 366 |
368 | 367 |