The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
fifo.h
Go to the documentation of this file.
1 #pragma once
2 /*
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation; either version 2 of the License, or
6  * (at your option) any later version.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
16  */
17 
18 /** Non-thread-safe fifo (FIFO) implementation
19  *
20  * @file src/lib/util/fifo.c
21  *
22  * @copyright 2005,2006 The FreeRADIUS server project
23  * @copyright 2005 Alan DeKok (aland@freeradius.org)
24  */
25 RCSIDH(fifo_h, "$Id: b86abc5dfe5f872a6ae1629906a4edb2e467557e $")
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
31 #include <freeradius-devel/build.h>
32 #include <freeradius-devel/missing.h>
33 #include <freeradius-devel/util/talloc.h>
34 
35 typedef struct fr_fifo_s fr_fifo_t;
36 typedef void (*fr_fifo_free_t)(void *);
37 
38 /** Creates a fifo that verifies elements are of a specific talloc type
39  *
40  * @param[in] _ctx to tie fifo lifetime to.
41  * If ctx is freed, fifo will free any nodes, calling the
42  * free function if set.
43  * @param[in] _max_entries Maximum number of entries.
44  * @param[in] _talloc_type of elements.
45  * @param[in] _node_free Optional function used to free data if tree nodes are
46  * deleted or replaced.
47  * @return
48  * - A new fifo on success.
49  * - NULL on failure.
50  */
51 #define fr_fifo_talloc_create(_ctx, _talloc_type, _max_entries, _node_free) \
52  _fr_fifo_create(_ctx, #_talloc_type, _max_entries, _node_free)
53 
54 /** Creates a fifo
55  *
56  * @param[in] _ctx to tie fifo lifetime to.
57  * If ctx is freed, fifo will free any nodes, calling the
58  * free function if set.
59  * @param[in] _max_entries Maximum number of entries.
60  * @param[in] _node_free Optional function used to free data if tree nodes are
61  * deleted or replaced.
62  * @return
63  * - A new fifo on success.
64  * - NULL on failure.
65  */
66 #define fr_fifo_create(_ctx, _max_entries, _node_free) \
67  _fr_fifo_create(_ctx, NULL, _max_entries, _node_free)
68 
69 fr_fifo_t *_fr_fifo_create(TALLOC_CTX *ctx, char const *type, int max_entries, fr_fifo_free_t free_node);
70 int fr_fifo_push(fr_fifo_t *fi, void *data);
71 void *fr_fifo_pop(fr_fifo_t *fi);
72 void *fr_fifo_peek(fr_fifo_t *fi);
73 unsigned int fr_fifo_num_elements(fr_fifo_t *fi);
74 
75 #ifdef __cplusplus
76 }
77 #endif
#define RCSIDH(h, id)
Definition: build.h:482
fr_fifo_free_t free_node
Function to call to free nodes when the fifo is freed.
Definition: fifo.c:34
Definition: fifo.c:30
void * fr_fifo_peek(fr_fifo_t *fi)
Examine the next element that would be popped.
Definition: fifo.c:158
fr_fifo_t * _fr_fifo_create(TALLOC_CTX *ctx, char const *type, int max_entries, fr_fifo_free_t free_node)
Create a fifo queue.
Definition: fifo.c:85
unsigned int fr_fifo_num_elements(fr_fifo_t *fi)
Return the number of elements in the fifo queue.
Definition: fifo.c:170
void * fr_fifo_pop(fr_fifo_t *fi)
Pop data off of the fifo.
Definition: fifo.c:135
int fr_fifo_push(fr_fifo_t *fi, void *data)
Push data onto the fifo.
Definition: fifo.c:111
void(* fr_fifo_free_t)(void *)
Definition: fifo.h:36
fr_aka_sim_id_type_t type
static fr_slen_t data
Definition: value.h:1265