diff --git a/doc/kernel_v2/memory/maps.rst b/doc/kernel_v2/memory/maps.rst index 27d53671c60..0226d622e3d 100644 --- a/doc/kernel_v2/memory/maps.rst +++ b/doc/kernel_v2/memory/maps.rst @@ -142,3 +142,4 @@ The following memory map APIs are provided by :file:`kernel.h`: * :cpp:func:`k_mem_map_alloc()` * :cpp:func:`k_mem_map_free()` * :cpp:func:`k_mem_map_num_used_get()` +* :cpp:func:`k_mem_map_num_free_get()` diff --git a/include/kernel.h b/include/kernel.h index fd22d90b22d..bf311361d7a 100644 --- a/include/kernel.h +++ b/include/kernel.h @@ -1225,6 +1225,22 @@ static inline int k_mem_map_num_used_get(struct k_mem_map *map) return map->num_used; } +/** + * @brief Get the number of unused memory blocks + * + * This routine gets the current number of unused memory blocks in the + * specified pool. It should be used for stats purposes only as that value + * may potentially be out-of-date by the time it is used. + * + * @param map Memory map to query + * + * @return Number of unused memory blocks + */ +static inline int k_mem_map_num_free_get(struct k_mem_map *map) +{ + return map->num_blocks - map->num_used; +} + /* memory pools */ /*