You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by je...@apache.org on 2024/09/06 12:45:44 UTC

(mynewt-core) 02/02: kernel/os: Fix msys allocation with multiply mpools

This is an automated email from the ASF dual-hosted git repository.

jerzy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git

commit ddae64e9b6ee29ee62d838c19267d4efcdca473d
Author: Jerzy Kasenberg <je...@codecoup.pl>
AuthorDate: Fri Aug 23 11:45:49 2024 +0200

    kernel/os: Fix msys allocation with multiply mpools
    
    When msys was configured with several mpools and one
    of the pools run out of buffers, os_mbuf_get() returned
    NULL even though other mpool did have buffers available.
    
    Now search for suitable buffer checks if suitable pool
    is empty and if not search continues.
---
 kernel/os/src/os_msys.c | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/kernel/os/src/os_msys.c b/kernel/os/src/os_msys.c
index 3b287a31a..fcb56f1a1 100644
--- a/kernel/os/src/os_msys.c
+++ b/kernel/os/src/os_msys.c
@@ -86,30 +86,32 @@ os_msys_reset(void)
     STAILQ_INIT(&g_msys_pool_list);
 }
 
+static struct os_mbuf_pool *os_msys_find_pool(uint16_t dsize);
+
 static struct os_mbuf_pool *
 os_msys_find_biggest_pool(void)
 {
-    /* Mempools are sorted by the blocksize, so just return last one */
-    return STAILQ_LAST(&g_msys_pool_list, os_mbuf_pool, omp_next);
+    return os_msys_find_pool(0xFFFF);
 }
 
 static struct os_mbuf_pool *
 os_msys_find_pool(uint16_t dsize)
 {
     struct os_mbuf_pool *pool;
+    struct os_mbuf_pool *pool_with_free_blocks = NULL;
+    uint16_t pool_free_blocks;
 
-    pool = NULL;
     STAILQ_FOREACH(pool, &g_msys_pool_list, omp_next) {
-        if (dsize <= pool->omp_databuf_len) {
-            break;
+        pool_free_blocks = pool->omp_pool->mp_num_free;
+        if (pool_free_blocks != 0) {
+            pool_with_free_blocks = pool;
+            if (dsize <= pool->omp_databuf_len) {
+                break;
+            }
         }
     }
 
-    if (!pool) {
-        pool = STAILQ_LAST(&g_msys_pool_list, os_mbuf_pool, omp_next);
-    }
-
-    return (pool);
+    return pool_with_free_blocks;
 }