24 RCSID(
"$Id: 3c967c14f10148ad89679fcadadb49fb8f212808 $")
28 #include <freeradius-devel/util/fifo.h>
51 for (i = 0 ; i < fi->
num; i++) {
54 element = i + fi->
first;
55 if (element > fi->
max) {
60 fi->
data[element] = NULL;
64 memset(fi, 0,
sizeof(*fi));
89 if ((max < 2) || (max > (1024 * 1024)))
return NULL;
91 fi = talloc_zero_size(ctx, (
sizeof(*fi) + (
sizeof(fi->
data[0])*max)));
113 if (!fi || !
data)
return -1;
115 if (fi->
num >= fi->
max)
return -1;
117 #ifndef TALLOC_GET_TYPE_ABORT_NOOP
118 if (fi->
type) _talloc_get_type_abort(
data, fi->
type, __location__);
139 if (!fi || (fi->
num == 0))
return NULL;
160 if (!fi || (fi->
num == 0))
return NULL;
186 int main(
int argc,
char **argv)
188 int i, j,
array[MAX];
194 for (j = 0; j < 5; j++) {
195 #define SPLIT (MAX/3)
196 #define COUNT ((j * SPLIT) + i)
197 for (i = 0; i < SPLIT; i++) {
198 array[COUNT % MAX] = COUNT;
201 fprintf(stderr,
"%d %d\tfailed pushing %d\n",
207 fprintf(stderr,
"%d %d\tgot size %d expected %d\n",
214 fprintf(stderr,
"HALF %d %d\n",
219 for (i = 0; i < SPLIT; i++) {
224 fprintf(stderr,
"No pop at %d\n", i);
229 fprintf(stderr,
"%d %d\tgot %d expected %d\n",
235 fprintf(stderr,
"%d %d\tgot size %d expected %d\n",
242 fprintf(stderr,
"ZERO %d %d\n",
#define fr_exit(_x)
Exit, producing a log message in debug builds.
int main(int argc, char **argv)
void * fr_fifo_peek(fr_fifo_t *fi)
Examine the next element that would be popped.
char const * type
Type of elements.
unsigned int last
Head and tail indexes for the fifo.
fr_fifo_t * _fr_fifo_create(TALLOC_CTX *ctx, char const *type, int max, fr_fifo_free_t free_node)
Create a fifo queue.
unsigned int num
How many elements exist in the fifo.
unsigned int fr_fifo_num_elements(fr_fifo_t *fi)
Return the number of elements in the fifo queue.
void * fr_fifo_pop(fr_fifo_t *fi)
Pop data off of the fifo.
int fr_fifo_push(fr_fifo_t *fi, void *data)
Push data onto the fifo.
fr_fifo_free_t free_node
Function to call to free nodes when the fifo is freed.
unsigned int max
How many elements were created in the fifo.
static int _fifo_free(fr_fifo_t *fi)
Free a fifo and optionally, any data still enqueued.
#define fr_fifo_create(_ctx, _max_entries, _node_free)
Creates a fifo.
void(* fr_fifo_free_t)(void *)
static size_t array[MY_ARRAY_SIZE]
fr_aka_sim_id_type_t type