MCPcopy Create free account
hub / github.com/F-Stack/f-stack / malloc_elem_insert

Function malloc_elem_insert

dpdk/lib/eal/common/malloc_elem.c:143–199  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

141}
142
143void
144malloc_elem_insert(struct malloc_elem *elem)
145{
146 struct malloc_elem *prev_elem, *next_elem;
147 struct malloc_heap *heap = elem->heap;
148
149 /* first and last elements must be both NULL or both non-NULL */
150 if ((heap->first == NULL) != (heap->last == NULL)) {
151 RTE_LOG(ERR, EAL, "Heap is probably corrupt\n");
152 return;
153 }
154
155 if (heap->first == NULL && heap->last == NULL) {
156 /* if empty heap */
157 heap->first = elem;
158 heap->last = elem;
159 prev_elem = NULL;
160 next_elem = NULL;
161 } else if (elem < heap->first) {
162 /* if lower than start */
163 prev_elem = NULL;
164 next_elem = heap->first;
165 heap->first = elem;
166 } else if (elem > heap->last) {
167 /* if higher than end */
168 prev_elem = heap->last;
169 next_elem = NULL;
170 heap->last = elem;
171 } else {
172 /* the new memory is somewhere between start and end */
173 uint64_t dist_from_start, dist_from_end;
174
175 dist_from_end = RTE_PTR_DIFF(heap->last, elem);
176 dist_from_start = RTE_PTR_DIFF(elem, heap->first);
177
178 /* check which is closer, and find closest list entries */
179 if (dist_from_start < dist_from_end) {
180 prev_elem = heap->first;
181 while (prev_elem->next < elem)
182 prev_elem = prev_elem->next;
183 next_elem = prev_elem->next;
184 } else {
185 next_elem = heap->last;
186 while (next_elem->prev > elem)
187 next_elem = next_elem->prev;
188 prev_elem = next_elem->prev;
189 }
190 }
191
192 /* insert new element */
193 elem->prev = prev_elem;
194 elem->next = next_elem;
195 if (prev_elem)
196 prev_elem->next = elem;
197 if (next_elem)
198 next_elem->prev = elem;
199}
200

Callers 1

malloc_heap_add_memoryFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected