| 575 | } |
| 576 | |
| 577 | int |
| 578 | rte_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); |
| 622 | unlock: |
| 623 | rte_mcfg_mem_write_unlock(); |
| 624 | |
| 625 | return ret; |
| 626 | } |
| 627 | |
| 628 | int |
| 629 | rte_malloc_heap_destroy(const char *heap_name) |