38 #ifndef included_fifo_h 39 #define included_fifo_h 58 #define clib_fifo_len(v) vec_len(v) 59 #define _clib_fifo_len(v) _vec_len(v) 60 #define clib_fifo_end(v) vec_end(v) 71 l = _clib_fifo_len (v);
73 r = r < 0 ? r + l : r;
94 void * _clib_fifo_resize (
void * v,
uword n_elts,
uword elt_bytes);
96 #define clib_fifo_resize(f,n_elts) \ 97 f = _clib_fifo_resize ((f), (n_elts), sizeof ((f)[0])) 100 _clib_fifo_validate (
void * v,
uword n_elts,
uword elt_bytes)
103 v = _clib_fifo_resize (v, n_elts, elt_bytes);
107 #define clib_fifo_validate(f,n_elts) \ 108 f = _clib_fifo_validate ((f), (n_elts), sizeof (f[0])) 112 _clib_fifo_advance_tail (
void * v,
word n_elts,
uword elt_bytes,
121 v = _clib_fifo_resize (v, n_elts, elt_bytes);
125 ASSERT (n_free >= n_elts);
129 l = _clib_fifo_len (v);
151 *tail_return = n_elts > 0 ? i : f->
tail_index;
156 #define clib_fifo_advance_tail(f,n_elts) \ 159 (f) = _clib_fifo_advance_tail ((f), (n_elts), sizeof ((f)[0]), &_i); \ 171 l = _clib_fifo_len (v);
179 n = n >= l ? n - l : n;
187 #define clib_fifo_add1(f,e) \ 190 (f) = _clib_fifo_advance_tail ((f), 1, sizeof ((f)[0]), &_i); \ 195 #define clib_fifo_add2(f,p) \ 198 (f) = _clib_fifo_advance_tail ((f), 1, sizeof ((f)[0]), &_i); \ 203 #define clib_fifo_add(f,e,n) \ 205 uword _i, _l; word _n0, _n1; \ 208 (f) = _clib_fifo_advance_tail ((f), _n0, sizeof ((f)[0]), &_i); \ 209 _l = clib_fifo_len (f); \ 210 _n1 = _i + _n0 - _l; \ 211 _n1 = _n1 < 0 ? 0 : _n1; \ 213 clib_memcpy ((f) + _i, (e), _n0 * sizeof ((f)[0])); \ 215 clib_memcpy ((f) + 0, (e) + _n0, _n1 * sizeof ((f)[0])); \ 219 #define clib_fifo_sub1(f,e) \ 222 ASSERT (clib_fifo_elts (f) >= 1); \ 223 _i = clib_fifo_advance_head ((f), 1); \ 227 #define clib_fifo_sub2(f,p) \ 230 ASSERT (clib_fifo_elts (f) >= 1); \ 231 _i = clib_fifo_advance_head ((f), 1); \ 249 #define clib_fifo_head(v) ((v) + clib_fifo_head_index (v)) 250 #define clib_fifo_tail(v) ((v) + clib_fifo_tail_index (v)) 252 #define clib_fifo_free(f) vec_free_h((f),sizeof(clib_fifo_header_t)) 265 if (result >= _vec_len (v))
266 result -= _vec_len (v);
272 #define clib_fifo_elt_at_index(v,i) ((v) + clib_fifo_elt_index (v, (i))) 274 #define clib_fifo_foreach(v,f,body) \ 278 _i = clib_fifo_head_index (f); \ 279 _l = clib_fifo_len (f); \ 280 _n = clib_fifo_elts (f); \ 284 do { body; } while (0); \ 287 _i = _i >= _l ? 0 : _i; \ sll srl srl sll sra u16x4 i
always_inline uword clib_fifo_free_elts(void *v)
always_inline uword clib_fifo_tail_index(void *v)
always_inline uword clib_fifo_elts(void *v)
always_inline void clib_fifo_reset(void *v)
always_inline clib_fifo_header_t * clib_fifo_header(void *f)
always_inline uword clib_fifo_head_index(void *v)
always_inline uword clib_fifo_elt_index(void *v, uword i)
always_inline uword clib_fifo_advance_head(void *v, uword n_elts)
always_inline 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".