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

Function rte_malloc_heap_create

dpdk/lib/eal/common/rte_malloc.c:577–626  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

575}
576
577int
578rte_malloc_heap_create(const char *heap_name)
579{
580 struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
581 struct malloc_heap *heap = NULL;
582 int i, ret;
583
584 if (heap_name == NULL ||
585 strnlen(heap_name, RTE_HEAP_NAME_MAX_LEN) == 0 ||
586 strnlen(heap_name, RTE_HEAP_NAME_MAX_LEN) ==
587 RTE_HEAP_NAME_MAX_LEN) {
588 rte_errno = EINVAL;
589 return -1;
590 }
591 /* check if there is space in the heap list, or if heap with this name
592 * already exists.
593 */
594 rte_mcfg_mem_write_lock();
595
596 for (i = 0; i < RTE_MAX_HEAPS; i++) {
597 struct malloc_heap *tmp = &mcfg->malloc_heaps[i];
598 /* existing heap */
599 if (strncmp(heap_name, tmp->name,
600 RTE_HEAP_NAME_MAX_LEN) == 0) {
601 RTE_LOG(ERR, EAL, "Heap %s already exists\n",
602 heap_name);
603 rte_errno = EEXIST;
604 ret = -1;
605 goto unlock;
606 }
607 /* empty heap */
608 if (strnlen(tmp->name, RTE_HEAP_NAME_MAX_LEN) == 0) {
609 heap = tmp;
610 break;
611 }
612 }
613 if (heap == NULL) {
614 RTE_LOG(ERR, EAL, "Cannot create new heap: no space\n");
615 rte_errno = ENOSPC;
616 ret = -1;
617 goto unlock;
618 }
619
620 /* we're sure that we can create a new heap, so do it */
621 ret = malloc_heap_create(heap, heap_name);
622unlock:
623 rte_mcfg_mem_write_unlock();
624
625 return ret;
626}
627
628int
629rte_malloc_heap_destroy(const char *heap_name)

Callers 5

test_malloc_basicFunction · 0.85
test_reallocFunction · 0.85
setup_extmemFunction · 0.85

Calls 6

strnlenFunction · 0.85
rte_mcfg_mem_write_lockFunction · 0.85
strncmpFunction · 0.85
malloc_heap_createFunction · 0.85

Tested by 5

test_malloc_basicFunction · 0.68
test_reallocFunction · 0.68
setup_extmemFunction · 0.68