From 321a750f561d276d0bbe8a4b066ff239a735f7be Mon Sep 17 00:00:00 2001 From: Ismael Gomez Date: Fri, 16 Mar 2018 11:23:10 +0100 Subject: [PATCH] Added features to ringbuffer --- lib/include/srslte/phy/utils/ringbuffer.h | 2 ++ lib/src/phy/utils/ringbuffer.c | 10 +++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/include/srslte/phy/utils/ringbuffer.h b/lib/include/srslte/phy/utils/ringbuffer.h index b8d0cd5c9..a93ebf181 100644 --- a/lib/include/srslte/phy/utils/ringbuffer.h +++ b/lib/include/srslte/phy/utils/ringbuffer.h @@ -28,6 +28,8 @@ SRSLTE_API void srslte_ringbuffer_reset(srslte_ringbuffer_t *q); SRSLTE_API int srslte_ringbuffer_status(srslte_ringbuffer_t *q); +SRSLTE_API int srslte_ringbuffer_space(srslte_ringbuffer_t *q); + SRSLTE_API int srslte_ringbuffer_write(srslte_ringbuffer_t *q, void *ptr, int nof_bytes); diff --git a/lib/src/phy/utils/ringbuffer.c b/lib/src/phy/utils/ringbuffer.c index 8f0c3edf2..02b98a4d8 100644 --- a/lib/src/phy/utils/ringbuffer.c +++ b/lib/src/phy/utils/ringbuffer.c @@ -13,11 +13,10 @@ int srslte_ringbuffer_init(srslte_ringbuffer_t *q, int capacity) } q->active = true; q->capacity = capacity; - srslte_ringbuffer_reset(q); - pthread_mutex_init(&q->mutex, NULL); pthread_cond_init(&q->cvar, NULL); - + srslte_ringbuffer_reset(q); + return 0; } @@ -48,6 +47,11 @@ int srslte_ringbuffer_status(srslte_ringbuffer_t *q) return q->count; } +int srslte_ringbuffer_space(srslte_ringbuffer_t *q) +{ + return q->capacity - q->count; +} + int srslte_ringbuffer_write(srslte_ringbuffer_t *q, void *p, int nof_bytes) { uint8_t *ptr = (uint8_t*) p;