Lines Matching full:h

6 #include <zephyr/sys/sys_heap.h>
7 #include <zephyr/sys/util.h>
8 #include <zephyr/kernel.h>
9 #include "heap.h"
23 static bool in_bounds(struct z_heap *h, chunkid_t c) in in_bounds() argument
25 VALIDATE(c >= right_chunk(h, 0)); in in_bounds()
26 VALIDATE(c < h->end_chunk); in in_bounds()
27 VALIDATE(chunk_size(h, c) < h->end_chunk); in in_bounds()
31 static bool valid_chunk(struct z_heap *h, chunkid_t c) in valid_chunk() argument
33 VALIDATE(chunk_size(h, c) > 0); in valid_chunk()
34 VALIDATE((c + chunk_size(h, c)) <= h->end_chunk); in valid_chunk()
35 VALIDATE(in_bounds(h, c)); in valid_chunk()
36 VALIDATE(right_chunk(h, left_chunk(h, c)) == c); in valid_chunk()
37 VALIDATE(left_chunk(h, right_chunk(h, c)) == c); in valid_chunk()
38 if (chunk_used(h, c)) { in valid_chunk()
39 VALIDATE(!solo_free_header(h, c)); in valid_chunk()
41 VALIDATE(chunk_used(h, left_chunk(h, c))); in valid_chunk()
42 VALIDATE(chunk_used(h, right_chunk(h, c))); in valid_chunk()
43 if (!solo_free_header(h, c)) { in valid_chunk()
44 VALIDATE(in_bounds(h, prev_free_chunk(h, c))); in valid_chunk()
45 VALIDATE(in_bounds(h, next_free_chunk(h, c))); in valid_chunk()
55 static inline void check_nexts(struct z_heap *h, int bidx) in check_nexts() argument
57 struct z_heap_bucket *b = &h->buckets[bidx]; in check_nexts()
59 bool emptybit = (h->avail_buckets & BIT(bidx)) == 0; in check_nexts()
67 CHECK(valid_chunk(h, b->next)); in check_nexts()
73 struct z_heap *h = heap->heap; in sys_heap_validate() local
79 for (c = right_chunk(h, 0); c < h->end_chunk; c = right_chunk(h, c)) { in sys_heap_validate()
80 if (!valid_chunk(h, c)) { in sys_heap_validate()
84 if (c != h->end_chunk) { in sys_heap_validate()
98 get_alloc_info(h, &allocated_bytes, &free_bytes); in sys_heap_validate()
110 for (int b = 0; b <= bucket_idx(h, h->end_chunk); b++) { in sys_heap_validate()
111 chunkid_t c0 = h->buckets[b].next; in sys_heap_validate()
114 check_nexts(h, b); in sys_heap_validate()
117 n++, c = next_free_chunk(h, c)) { in sys_heap_validate()
118 if (!valid_chunk(h, c)) { in sys_heap_validate()
121 set_chunk_used(h, c, true); in sys_heap_validate()
124 bool empty = (h->avail_buckets & BIT(b)) == 0; in sys_heap_validate()
131 if (empty && (h->buckets[b].next != 0)) { in sys_heap_validate()
144 for (c = right_chunk(h, 0); c < h->end_chunk; c = right_chunk(h, c)) { in sys_heap_validate()
145 if (!chunk_used(h, c) && !solo_free_header(h, c)) { in sys_heap_validate()
148 if (left_chunk(h, c) != prev_chunk) { in sys_heap_validate()
153 set_chunk_used(h, c, solo_free_header(h, c)); in sys_heap_validate()
155 if (c != h->end_chunk) { in sys_heap_validate()
163 for (int b = 0; b <= bucket_idx(h, h->end_chunk); b++) { in sys_heap_validate()
164 chunkid_t c0 = h->buckets[b].next; in sys_heap_validate()
171 for (c = c0; n == 0 || c != c0; n++, c = next_free_chunk(h, c)) { in sys_heap_validate()
172 if (chunk_used(h, c)) { in sys_heap_validate()
175 set_chunk_used(h, c, true); in sys_heap_validate()
182 for (c = right_chunk(h, 0); c < h->end_chunk; c = right_chunk(h, c)) { in sys_heap_validate()
183 set_chunk_used(h, c, !chunk_used(h, c)); in sys_heap_validate()