From c001aa8ef66f2ccd9f64a139044b5287aae30a7a Mon Sep 17 00:00:00 2001 From: Peter Mitsis Date: Thu, 13 Oct 2016 13:53:37 -0400 Subject: [PATCH] unified: Add k_mem_map_num_free_get() Complements existing k_mem_map_num_used_get(). Change-Id: Ie69c0a8e30007e365820448bde48303718369904 Signed-off-by: Peter Mitsis --- doc/kernel_v2/memory/maps.rst | 1 + include/kernel.h | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) 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 */ /*