61 #ifndef included_heap_h 62 #define included_heap_h 81 #define HEAP_ELT_FREE_BIT (1 << 31) 90 {
return e + e->
next; }
93 {
return e + e->
prev; }
104 #define HEAP_LOG2_SMALL_BINS (5) 105 #define HEAP_SMALL_BINS (1 << HEAP_LOG2_SMALL_BINS) 106 #define HEAP_N_BINS (2 * HEAP_SMALL_BINS) 139 #define HEAP_IS_STATIC (1) 143 #define HEAP_DATA_ALIGN (CLIB_CACHE_LINE_BYTES) 157 new->free_elts =
vec_dup (new->free_elts);
158 new->free_lists =
vec_dup (new->free_lists);
159 for (i = 0; i <
vec_len (new->free_lists); i++)
160 new->free_lists[i] =
vec_dup (new->free_lists[i]);
162 new->small_free_elt_free_index =
vec_dup (new->small_free_elt_free_index);
166 #define heap_dup(v) _heap_dup(v, vec_len (v) * sizeof (v[0])) 179 v_new = _vec_resize (v_new, _vec_len (v_old), v_bytes,
sizeof (
heap_header_t),
197 void * v = _vec_resize (0, len, len*n_elt_bytes,
204 #define heap_new(v) (v) = _heap_new (0, sizeof ((v)[0])) 230 if (max_len * elt_bytes <
sizeof (h[0]))
234 memset (h, 0,
sizeof (h[0]));
245 #define heap_foreach(var,len,heap,body) \ 247 if (vec_len (heap) > 0) \ 249 heap_header_t * _h = heap_header (heap); \ 250 heap_elt_t * _e = _h->elts + _h->head; \ 251 heap_elt_t * _end = _h->elts + _h->tail; \ 254 if (! heap_is_free (_e)) \ 256 (var) = (heap) + heap_offset (_e); \ 257 (len) = heap_elt_size ((heap), _e); \ 258 do { body; } while (0); \ 262 _e = heap_next (_e); \ 267 #define heap_elt_at_index(v,index) vec_elt_at_index(v,index) 278 #define heap_elt_with_handle(v,handle) \ 280 heap_elt_t * _e = heap_get_elt ((v), (handle)); \ 281 (v) + heap_offset (_e); \ 299 #define heap_alloc_aligned(v,size,align,handle) \ 302 uword _a = (align); \ 304 (v) = _heap_alloc ((v), _s, _a, sizeof ((v)[0]), &_o, &_h); \ 309 #define heap_alloc(v,size,handle) heap_alloc_aligned((v),(size),0,(handle)) 317 void * _heap_free (
void * v);
319 #define heap_free(v) (v)=_heap_free(v) always_inline void heap_set_max_len(void *v, uword max_len)
sll srl srl sll sra u16x4 i
always_inline uword heap_elts(void *v)
always_inline heap_elt_t * heap_get_elt(void *v, uword handle)
always_inline void heap_set_format(void *v, format_function_t *format_elt)
always_inline uword heap_get_max_len(void *v)
always_inline void heap_dup_header(heap_header_t *old, heap_header_t *new)
always_inline heap_elt_t * heap_next(heap_elt_t *e)
#define clib_bitmap_dup(v)
vhost_user_memory_t memory
always_inline uword heap_is_free(heap_elt_t *e)
always_inline heap_header_t * heap_header(void *v)
uword heap_bytes(void *v)
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
always_inline uword heap_offset(heap_elt_t *e)
u8 * format_heap(u8 *s, va_list *va)
void heap_validate(void *v)
#define vec_dup(V)
Return copy of vector (no header, no alignment)
uword heap_len(void *v, word handle)
always_inline uword heap_header_bytes()
#define clib_memcpy(a, b, c)
always_inline heap_elt_t * heap_prev(heap_elt_t *e)
#define HEAP_ELT_FREE_BIT
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
always_inline uword heap_elt_size(void *v, heap_elt_t *e)
always_inline void * vec_header(void *v, uword header_bytes)
Find a user vector header.
always_inline void * heap_create_from_memory(void *memory, uword max_len, uword elt_bytes)
always_inline uword heap_is_free_handle(void *v, uword heap_handle)
void heap_dealloc(void *v, uword handle)
always_inline uword vec_header_bytes(uword header_bytes)