27RCSID(
"$Id: acef49804e222a1e58c7d3539820dbd24a33bb8f $")
29#include <freeradius-devel/util/fring.h>
64 if (fring->
lock) pthread_mutex_destroy(&fring->
mutex);
84 if (size == 0 || size > 0x80000000U)
return NULL;
89 for (pow = 0x00000001;
96 if (!fring)
return NULL;
99 fring->
data = talloc_zero_array(fring,
void *, size);
108 pthread_mutex_init(&fring->
mutex, NULL);
125 if (fring->
lock) pthread_mutex_lock(&fring->
mutex);
127 if (fring->
data[fring->
in]) {
133 fring->
in = (fring->
in + 1) & fring->
size;
136 if (fring->
in == fring->
out) fring->
out = (fring->
out + 1) & fring->
size;
138 if (fring->
lock) pthread_mutex_unlock(&fring->
mutex);
140 return freed ? 1 : 0;
153 if (fring->
lock) pthread_mutex_lock(&fring->
mutex);
155 if (fring->
data[fring->
in]) {
156 if (fring->
lock) pthread_mutex_unlock(&fring->
mutex);
162 fring->
in = (fring->
in + 1) & fring->
size;
165 if (fring->
in == fring->
out) fring->
out = (fring->
out + 1) & fring->
size;
167 if (fring->
lock) pthread_mutex_unlock(&fring->
mutex);
183 if (fring->
lock) pthread_mutex_lock(&fring->
mutex);
189 fring->
data[fring->
out] = NULL;
193 if (fring->
lock) pthread_mutex_unlock(&fring->
mutex);
void const * end
End of allocated memory.
bool lock
Perform thread synchronisation.
void ** data
Ring buffer data.
int fr_fring_overwrite(fr_fring_t *fring, void *in)
Insert a new item into the circular buffer, freeing the tail if we hit it.
void * fr_fring_next(fr_fring_t *fring)
Remove an item from the buffer.
pthread_mutex_t mutex
Thread synchronisation mutex.
int fr_fring_insert(fr_fring_t *fring, void *in)
Insert a new item into the circular buffer if the buffer is not full.
fr_fring_t * fr_fring_alloc(TALLOC_CTX *ctx, uint32_t size, bool lock)
Initialise a ring buffer with fixed element size.
static int _fring_free(fr_fring_t *fring)
Destroy mutex associated with ring buffer.
Standard thread safe circular buffer.
static size_t char ** out