61 #ifndef included_heap_h 62 #define included_heap_h 82 #define HEAP_ELT_FREE_BIT (1 << 31) 118 #define HEAP_LOG2_SMALL_BINS (5) 119 #define HEAP_SMALL_BINS (1 << HEAP_LOG2_SMALL_BINS) 120 #define HEAP_N_BINS (2 * HEAP_SMALL_BINS) 154 #define HEAP_IS_STATIC (1) 158 #define HEAP_DATA_ALIGN (CLIB_CACHE_LINE_BYTES) 179 new->free_elts =
vec_dup (new->free_elts);
180 new->free_lists =
vec_dup (new->free_lists);
181 for (i = 0; i <
vec_len (new->free_lists); i++)
182 new->free_lists[i] =
vec_dup (new->free_lists[i]);
184 new->small_free_elt_free_index =
vec_dup (new->small_free_elt_free_index);
188 #define heap_dup(v) _heap_dup(v, vec_len (v) * sizeof (v[0])) 191 _heap_dup (
void *v_old,
uword v_bytes)
203 _vec_resize (v_new, _vec_len (v_old), v_bytes,
sizeof (
heap_header_t),
221 _heap_new (
u32 len,
u32 n_elt_bytes)
223 void *
v = _vec_resize (0, len, (
uword) len * n_elt_bytes,
230 #define heap_new(v) (v) = _heap_new (0, sizeof ((v)[0])) 259 if (max_len * elt_bytes <
sizeof (h[0]))
263 memset (h, 0,
sizeof (h[0]));
274 #define heap_foreach(var,len,heap,body) \ 276 if (vec_len (heap) > 0) \ 278 heap_header_t * _h = heap_header (heap); \ 279 heap_elt_t * _e = _h->elts + _h->head; \ 280 heap_elt_t * _end = _h->elts + _h->tail; \ 283 if (! heap_is_free (_e)) \ 285 (var) = (heap) + heap_offset (_e); \ 286 (len) = heap_elt_size ((heap), _e); \ 287 do { body; } while (0); \ 291 _e = heap_next (_e); \ 296 #define heap_elt_at_index(v,index) vec_elt_at_index(v,index) 307 #define heap_elt_with_handle(v,handle) \ 309 heap_elt_t * _e = heap_get_elt ((v), (handle)); \ 310 (v) + heap_offset (_e); \ 327 #define heap_alloc_aligned(v,size,align,handle) \ 330 uword _a = (align); \ 332 (v) = _heap_alloc ((v), _s, _a, sizeof ((v)[0]), &_o, &_h); \ 337 #define heap_alloc(v,size,handle) heap_alloc_aligned((v),(size),0,(handle)) 345 void *_heap_free (
void *
v);
347 #define heap_free(v) (v)=_heap_free(v)
static uword heap_get_max_len(void *v)
static heap_elt_t * heap_get_elt(void *v, uword handle)
#define clib_bitmap_dup(v)
Duplicate a bitmap.
vhost_user_memory_t memory
uword heap_bytes(void *v)
static uword vec_header_bytes(uword header_bytes)
static void heap_set_max_len(void *v, uword max_len)
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
static uword heap_is_free(heap_elt_t *e)
static void * heap_create_from_memory(void *memory, uword max_len, uword elt_bytes)
static heap_elt_t * heap_next(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)
static uword heap_header_bytes()
static void heap_dup_header(heap_header_t *old, heap_header_t *new)
#define clib_memcpy(a, b, c)
static uword heap_offset(heap_elt_t *e)
Bitmaps built as vectors of machine words.
static uword heap_elt_size(void *v, heap_elt_t *e)
static heap_header_t * heap_header(void *v)
static heap_elt_t * heap_prev(heap_elt_t *e)
static void heap_set_format(void *v, format_function_t *format_elt)
template key/value backing page structure
static uword heap_is_free_handle(void *v, uword heap_handle)
#define HEAP_ELT_FREE_BIT
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
static uword heap_elts(void *v)
static void * vec_header(void *v, uword header_bytes)
Find a user vector header.
void heap_dealloc(void *v, uword handle)