You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2022/01/01 17:25:20 UTC

[incubator-nuttx] branch master updated: net/devif_callback: add support for CONFIG_NET_ALLOC_CONNS

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

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new f345f3d  net/devif_callback: add support for CONFIG_NET_ALLOC_CONNS
f345f3d is described below

commit f345f3dc2e8d1841593995b2e5a069b32d0d06e3
Author: chao.an <an...@xiaomi.com>
AuthorDate: Sat Jan 1 22:05:07 2022 +0800

    net/devif_callback: add support for CONFIG_NET_ALLOC_CONNS
    
    Signed-off-by: chao.an <an...@xiaomi.com>
---
 net/devif/devif_callback.c | 31 +++++++++++++++++++++++++++++--
 net/udp/udp_conn.c         |  1 +
 2 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/net/devif/devif_callback.c b/net/devif/devif_callback.c
index b2bff67..138ba05 100644
--- a/net/devif/devif_callback.c
+++ b/net/devif/devif_callback.c
@@ -31,6 +31,7 @@
 #include <debug.h>
 #include <assert.h>
 
+#include <nuttx/kmalloc.h>
 #include <nuttx/net/netconfig.h>
 #include <nuttx/net/net.h>
 #include <nuttx/net/netdev.h>
@@ -42,7 +43,9 @@
  * Private Data
  ****************************************************************************/
 
+#ifndef CONFIG_NET_ALLOC_CONNS
 static struct devif_callback_s g_cbprealloc[CONFIG_NET_NACTIVESOCKETS];
+#endif
 static FAR struct devif_callback_s *g_cbfreelist = NULL;
 
 /****************************************************************************
@@ -227,6 +230,7 @@ static bool devif_event_trigger(uint16_t events, uint16_t triggers)
 
 void devif_callback_init(void)
 {
+#ifndef CONFIG_NET_ALLOC_CONNS
   int i;
 
   for (i = 0; i < CONFIG_NET_NACTIVESOCKETS; i++)
@@ -234,6 +238,7 @@ void devif_callback_init(void)
       g_cbprealloc[i].nxtconn = g_cbfreelist;
       g_cbfreelist = &g_cbprealloc[i];
     }
+#endif
 }
 
 /****************************************************************************
@@ -258,11 +263,33 @@ FAR struct devif_callback_s *
                        FAR struct devif_callback_s **list_tail)
 {
   FAR struct devif_callback_s *ret;
+#ifdef CONFIG_NET_ALLOC_CONNS
+  int i;
+#endif
+
+  net_lock();
+
+  /* Allocate the callback entry from heap */
+
+#ifdef CONFIG_NET_ALLOC_CONNS
+  if (g_cbfreelist == NULL)
+    {
+      ret = kmm_zalloc(sizeof(struct devif_callback_s) *
+                       CONFIG_NET_NACTIVESOCKETS);
+      if (ret != NULL)
+        {
+          for (i = 0; i < CONFIG_NET_NACTIVESOCKETS; i++)
+            {
+              ret[i].nxtconn = g_cbfreelist;
+              g_cbfreelist = &ret[i];
+            }
+        }
+    }
+#endif
 
   /* Check the head of the free list */
 
-  net_lock();
-  ret  = g_cbfreelist;
+  ret = g_cbfreelist;
   if (ret)
     {
       /* Remove the next instance from the head of the free list */
diff --git a/net/udp/udp_conn.c b/net/udp/udp_conn.c
index b8a73d8..ea80b00 100644
--- a/net/udp/udp_conn.c
+++ b/net/udp/udp_conn.c
@@ -55,6 +55,7 @@
 #include <arch/irq.h>
 
 #include <nuttx/clock.h>
+#include <nuttx/kmalloc.h>
 #include <nuttx/semaphore.h>
 #include <nuttx/net/netconfig.h>
 #include <nuttx/net/net.h>