[v3,01/16] malloc: rework heap destroy
Checks
Commit Message
The destroy helper has been reworked to zero all the heap object but
leave the lock untouched. The heap lock is then released through the
standard API.
Signed-off-by: David Marchand <david.marchand@redhat.com>
---
Changes since v2:
- shrinked the change to the required part,
---
lib/eal/common/malloc_heap.c | 6 ++++--
lib/eal/common/rte_malloc.c | 5 +----
2 files changed, 5 insertions(+), 6 deletions(-)
@@ -1385,8 +1385,10 @@ malloc_heap_destroy(struct malloc_heap *heap)
if (heap->total_size != 0)
RTE_LOG(ERR, EAL, "Total size not zero, heap is likely corrupt\n");
- /* after this, the lock will be dropped */
- memset(heap, 0, sizeof(*heap));
+ /* Reset all of the heap but the (hold) lock so caller can release it. */
+ RTE_BUILD_BUG_ON(offsetof(struct malloc_heap, lock) != 0);
+ memset(RTE_PTR_ADD(heap, sizeof(heap->lock)), 0,
+ sizeof(*heap) - sizeof(heap->lock));
return 0;
}
@@ -657,10 +657,7 @@ rte_malloc_heap_destroy(const char *heap_name)
/* sanity checks done, now we can destroy the heap */
rte_spinlock_lock(&heap->lock);
ret = malloc_heap_destroy(heap);
-
- /* if we failed, lock is still active */
- if (ret < 0)
- rte_spinlock_unlock(&heap->lock);
+ rte_spinlock_unlock(&heap->lock);
unlock:
rte_mcfg_mem_write_unlock();