1 /* 2 * Copyright (c) 2023 Codecoup 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #include <stdlib.h> 8 #include <zephyr/kernel.h> 9 k_mem_slab_alloc(struct k_mem_slab * slab,void ** mem,k_timeout_t timeout)10int k_mem_slab_alloc(struct k_mem_slab *slab, void **mem, k_timeout_t timeout) 11 { 12 if (slab->info.num_used >= slab->info.num_blocks) { 13 *mem = NULL; 14 return -ENOMEM; 15 } 16 17 *mem = malloc(slab->info.block_size); 18 zassert_not_null(*mem); 19 20 slab->info.num_used++; 21 return 0; 22 } 23 k_mem_slab_free(struct k_mem_slab * slab,void * mem)24void k_mem_slab_free(struct k_mem_slab *slab, void *mem) 25 { 26 free(mem); 27 slab->info.num_used--; 28 } 29