38 #ifndef included_fifo_h 39 #define included_fifo_h 61 #define clib_fifo_len(v) vec_len(v) 62 #define _clib_fifo_len(v) _vec_len(v) 63 #define clib_fifo_end(v) vec_end(v) 74 l = _clib_fifo_len (v);
76 r = r < 0 ? r + l : r;
99 void *_clib_fifo_resize (
void *v,
uword n_elts,
uword elt_bytes);
101 #define clib_fifo_resize(f,n_elts) \ 102 f = _clib_fifo_resize ((f), (n_elts), sizeof ((f)[0])) 105 _clib_fifo_validate (
void *v,
uword n_elts,
uword elt_bytes)
108 v = _clib_fifo_resize (v, n_elts, elt_bytes);
112 #define clib_fifo_validate(f,n_elts) \ 113 f = _clib_fifo_validate ((f), (n_elts), sizeof (f[0])) 117 _clib_fifo_advance_tail (
void *v,
word n_elts,
uword elt_bytes,
126 v = _clib_fifo_resize (v, n_elts, elt_bytes);
130 ASSERT (n_free >= n_elts);
134 l = _clib_fifo_len (v);
161 #define clib_fifo_advance_tail(f,n_elts) \ 164 (f) = _clib_fifo_advance_tail ((f), (n_elts), sizeof ((f)[0]), &_i); \ 176 l = _clib_fifo_len (v);
184 n = n >= l ? n - l : n;
192 #define clib_fifo_add1(f,e) \ 195 (f) = _clib_fifo_advance_tail ((f), 1, sizeof ((f)[0]), &_i); \ 200 #define clib_fifo_add2(f,p) \ 203 (f) = _clib_fifo_advance_tail ((f), 1, sizeof ((f)[0]), &_i); \ 208 #define clib_fifo_add(f,e,n) \ 210 uword _i, _l; word _n0, _n1; \ 213 (f) = _clib_fifo_advance_tail ((f), _n0, sizeof ((f)[0]), &_i); \ 214 _l = clib_fifo_len (f); \ 215 _n1 = _i + _n0 - _l; \ 216 _n1 = _n1 < 0 ? 0 : _n1; \ 218 clib_memcpy_fast ((f) + _i, (e), _n0 * sizeof ((f)[0])); \ 220 clib_memcpy_fast ((f) + 0, (e) + _n0, _n1 * sizeof ((f)[0])); \ 224 #define clib_fifo_sub1(f,e) \ 227 ASSERT (clib_fifo_elts (f) >= 1); \ 228 _i = clib_fifo_advance_head ((f), 1); \ 232 #define clib_fifo_sub2(f,p) \ 235 ASSERT (clib_fifo_elts (f) >= 1); \ 236 _i = clib_fifo_advance_head ((f), 1); \ 254 #define clib_fifo_head(v) ((v) + clib_fifo_head_index (v)) 255 #define clib_fifo_tail(v) ((v) + clib_fifo_tail_index (v)) 257 #define clib_fifo_free(f) vec_free_h((f),sizeof(clib_fifo_header_t)) 270 if (result >= _vec_len (v))
271 result -= _vec_len (v);
277 #define clib_fifo_elt_at_index(v,i) ((v) + clib_fifo_elt_index (v, (i))) 279 #define clib_fifo_foreach(v,f,body) \ 283 _i = clib_fifo_head_index (f); \ 284 _l = clib_fifo_len (f); \ 285 _n = clib_fifo_elts (f); \ 289 do { body; } while (0); \ 292 _i = _i >= _l ? 0 : _i; \ static uword clib_fifo_elts(void *v)
static uword clib_fifo_elt_index(void *v, uword i)
static uword clib_fifo_head_index(void *v)
static uword clib_fifo_free_elts(void *v)
static void clib_fifo_reset(void *v)
static uword clib_fifo_tail_index(void *v)
static uword clib_fifo_advance_head(void *v, uword n_elts)
static clib_fifo_header_t * clib_fifo_header(void *f)
static void * vec_header(void *v, uword header_bytes)
Find a user vector header.
CLIB vectors are ubiquitous dynamically resized arrays with by user defined "headers".