The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
fring.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 /** Simple ring buffer with fixed element sizes
19  *
20  * @file src/lib/util/fring.h
21  *
22  * @copyright 2015-2017 Arran Cudbard-Bell (a.cudbardb@freeradius.org)
23  */
24 RCSIDH(fring_h, "$Id: b4e45fe98c43e74a2d38c519242adbcedf4197ed $")
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
30 #include <freeradius-devel/build.h>
31 #include <freeradius-devel/missing.h>
32 #include <freeradius-devel/util/talloc.h>
33 
34 #include <stdbool.h>
35 #include <stdint.h>
36 
37 typedef struct fr_fring_buffer fr_fring_t;
38 
39 fr_fring_t *fr_fring_alloc(TALLOC_CTX *ctx, uint32_t size, bool lock);
40 int fr_fring_overwrite(fr_fring_t *fring, void *obj);
41 int fr_fring_insert(fr_fring_t *fring, void *obj);
42 void *fr_fring_next(fr_fring_t *fring);
43 
44 #ifdef __cplusplus
45 }
46 #endif
#define RCSIDH(h, id)
Definition: build.h:445
uint32_t size
Definition: fring.c:39
bool lock
Perform thread synchronisation.
Definition: fring.c:45
Standard thread safe circular buffer.
Definition: fring.c:36
void * fr_fring_next(fr_fring_t *fring)
Remove an item from the buffer.
Definition: fring.c:177
int fr_fring_insert(fr_fring_t *fring, void *obj)
Insert a new item into the circular buffer if the buffer is not full.
Definition: fring.c:149
fr_fring_t * fr_fring_alloc(TALLOC_CTX *ctx, uint32_t size, bool lock)
Initialise a ring buffer with fixed element size.
Definition: fring.c:78
int fr_fring_overwrite(fr_fring_t *fring, void *obj)
Insert a new item into the circular buffer, freeing the tail if we hit it.
Definition: fring.c:120
unsigned int uint32_t
Definition: merged_model.c:33