This is an automated email from the ASF dual-hosted git repository.
GUIDINGLI pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new ae571a4ff8c net: replace NET_BUFPOOL with MEMPOOL_DEFINE
ae571a4ff8c is described below
commit ae571a4ff8c1efdb65dd615525c5e9e9a96c1913
Author: zhanghongyu <[email protected]>
AuthorDate: Wed Nov 18 13:45:13 2026 +0800
net: replace NET_BUFPOOL with MEMPOOL_DEFINE
The ICMP, ICMPv6, PKT, NetLink and UDP connection pools, the UDP write
buffer pool, the forward structure pool, the RAM route pools and the
devif callback pool all used net_bufpool, and several of them borrowed
the net_bufpool lock to protect both the pool and a separate list (the
per-protocol active connection list, or the RAM routing table).
Switch every pool to the common MEMPOOL_DEFINE, whose allocate/release
are internally locked, and give each list that relied on the pool lock
its own rmutex (connection lists and route tables). The pool allocate/
free macros map directly to mempool_allocate()/mempool_release(). No
functional change for callers.
Signed-off-by: zhanghongyu <[email protected]>
---
net/devif/devif_callback.c | 16 +++++++---------
net/icmp/icmp_conn.c | 42 +++++++++++++++++++++++++-----------------
net/icmpv6/icmpv6_conn.c | 28 ++++++++++++++++++----------
net/netforward/netfwd_alloc.c | 13 +++++++------
net/netlink/netlink_conn.c | 25 ++++++++++++++++---------
net/pkt/pkt_conn.c | 29 ++++++++++++++++++-----------
net/route/net_alloc_ramroute.c | 34 ++++++++++++++++++++++------------
net/udp/udp_conn.c | 27 ++++++++++++++++-----------
net/udp/udp_wrbuffer.c | 15 ++++++++-------
9 files changed, 137 insertions(+), 92 deletions(-)
diff --git a/net/devif/devif_callback.c b/net/devif/devif_callback.c
index 1495cd9967e..78b130717b4 100644
--- a/net/devif/devif_callback.c
+++ b/net/devif/devif_callback.c
@@ -38,6 +38,7 @@
#include <nuttx/net/net.h>
#include <nuttx/net/netdev.h>
#include <nuttx/net/netstats.h>
+#include <nuttx/mm/mempool.h>
#include "netdev/netdev.h"
#include "utils/utils.h"
@@ -64,9 +65,9 @@ struct net_stats_s g_netstats;
* Private Data
****************************************************************************/
-NET_BUFPOOL_DECLARE(g_cbprealloc, sizeof(struct devif_callback_s),
- CONFIG_NET_PREALLOC_DEVIF_CALLBACKS,
- CONFIG_NET_ALLOC_DEVIF_CALLBACKS, 0);
+MEMPOOL_DEFINE(g_cbprealloc, sizeof(struct devif_callback_s),
+ CONFIG_NET_PREALLOC_DEVIF_CALLBACKS, 0,
+ CONFIG_NET_ALLOC_DEVIF_CALLBACKS);
/****************************************************************************
* Private Functions
@@ -96,16 +97,13 @@ static void devif_callback_free(FAR struct net_driver_s
*dev,
#ifdef CONFIG_DEBUG_FEATURES
/* Check for double freed callbacks */
- NET_BUFPOOL_LOCK(g_cbprealloc);
- curr = (FAR struct devif_callback_s *)g_cbprealloc.freebuffers.head;
+ curr = (FAR struct devif_callback_s *)g_cbprealloc.queue.head;
while (curr != NULL)
{
DEBUGASSERT(cb != curr);
curr = curr->nxtconn;
}
-
- NET_BUFPOOL_UNLOCK(g_cbprealloc);
#endif
/* Remove the callback structure from the data notification list if
@@ -199,7 +197,7 @@ static void devif_callback_free(FAR struct net_driver_s
*dev,
/* Free the callback structure */
- NET_BUFPOOL_FREE(g_cbprealloc, cb);
+ mempool_release(&g_cbprealloc, cb);
}
}
@@ -307,7 +305,7 @@ devif_callback_alloc(FAR struct net_driver_s *dev,
/* Get a callback structure */
- ret = NET_BUFPOOL_TRYALLOC(g_cbprealloc);
+ ret = mempool_allocate(&g_cbprealloc, 0);
if (ret)
{
/* Add the newly allocated instance to the head of the device event
diff --git a/net/icmp/icmp_conn.c b/net/icmp/icmp_conn.c
index 16cbc6cf7e1..849e73264c6 100644
--- a/net/icmp/icmp_conn.c
+++ b/net/icmp/icmp_conn.c
@@ -39,6 +39,8 @@
#include <nuttx/net/net.h>
#include <nuttx/net/netdev.h>
+#include <nuttx/mm/mempool.h>
+
#include "devif/devif.h"
#include "icmp/icmp.h"
#include "utils/utils.h"
@@ -59,9 +61,15 @@
/* The array containing all IPPROTO_ICMP socket connections */
-NET_BUFPOOL_DECLARE(g_icmp_connections, sizeof(struct icmp_conn_s),
- CONFIG_NET_ICMP_PREALLOC_CONNS,
- CONFIG_NET_ICMP_ALLOC_CONNS, CONFIG_NET_ICMP_MAX_CONNS);
+MEMPOOL_DEFINE(g_icmp_connections, sizeof(struct icmp_conn_s),
+ CONFIG_NET_ICMP_PREALLOC_CONNS, CONFIG_NET_ICMP_MAX_CONNS,
+ CONFIG_NET_ICMP_ALLOC_CONNS);
+
+/* The list of all allocated IPPROTO_ICMP socket connections is protected by
+ * this rmutex.
+ */
+
+static rmutex_t g_icmp_connections_lock = NXRMUTEX_INITIALIZER;
/* A list of all allocated IPPROTO_ICMP socket connections */
@@ -85,11 +93,11 @@ FAR struct icmp_conn_s *icmp_alloc(void)
{
FAR struct icmp_conn_s *conn = NULL;
- /* The free list is protected by a mutex. */
+ /* The connection list is protected by a mutex. */
- NET_BUFPOOL_LOCK(g_icmp_connections);
+ icmp_conn_list_lock();
- conn = NET_BUFPOOL_TRYALLOC(g_icmp_connections);
+ conn = mempool_allocate(&g_icmp_connections, 0);
if (conn != NULL)
{
/* Use conn_init to initialize the connection structure */
@@ -101,7 +109,7 @@ FAR struct icmp_conn_s *icmp_alloc(void)
dq_addlast(&conn->sconn.s_node, &g_active_icmp_connections);
}
- NET_BUFPOOL_UNLOCK(g_icmp_connections);
+ icmp_conn_list_unlock();
return conn;
}
@@ -117,13 +125,13 @@ FAR struct icmp_conn_s *icmp_alloc(void)
void icmp_free(FAR struct icmp_conn_s *conn)
{
- /* The free list is protected by a mutex. */
+ /* The connection list is protected by a mutex. */
DEBUGASSERT(conn->crefs == 0);
/* Take the mutex (perhaps waiting) */
- NET_BUFPOOL_LOCK(g_icmp_connections);
+ icmp_conn_list_lock();
/* free any read-ahead data */
@@ -139,9 +147,9 @@ void icmp_free(FAR struct icmp_conn_s *conn)
/* Free the connection. */
- NET_BUFPOOL_FREE(g_icmp_connections, conn);
+ mempool_release(&g_icmp_connections, conn);
- NET_BUFPOOL_UNLOCK(g_icmp_connections);
+ icmp_conn_list_unlock();
}
/****************************************************************************
@@ -218,12 +226,12 @@ FAR struct icmp_conn_s *icmp_nextconn(FAR struct
icmp_conn_s *conn)
void icmp_conn_list_lock(void)
{
- NET_BUFPOOL_LOCK(g_icmp_connections);
+ nxrmutex_lock(&g_icmp_connections_lock);
}
void icmp_conn_list_unlock(void)
{
- NET_BUFPOOL_UNLOCK(g_icmp_connections);
+ nxrmutex_unlock(&g_icmp_connections_lock);
}
/****************************************************************************
@@ -243,7 +251,7 @@ FAR struct icmp_conn_s *icmp_findconn(FAR struct
net_driver_s *dev,
{
FAR struct icmp_conn_s *conn;
- NET_BUFPOOL_LOCK(g_icmp_connections);
+ icmp_conn_list_lock();
for (conn = icmp_nextconn(NULL); conn != NULL; conn = icmp_nextconn(conn))
{
if (conn->id == id && conn->dev == dev)
@@ -252,7 +260,7 @@ FAR struct icmp_conn_s *icmp_findconn(FAR struct
net_driver_s *dev,
}
}
- NET_BUFPOOL_UNLOCK(g_icmp_connections);
+ icmp_conn_list_unlock();
return conn;
}
@@ -274,7 +282,7 @@ int icmp_foreach(icmp_callback_t callback, FAR void *arg)
FAR struct icmp_conn_s *conn;
int ret = 0;
- NET_BUFPOOL_LOCK(g_icmp_connections);
+ icmp_conn_list_lock();
if (callback != NULL)
{
for (conn = icmp_nextconn(NULL); conn != NULL;
@@ -288,7 +296,7 @@ int icmp_foreach(icmp_callback_t callback, FAR void *arg)
}
}
- NET_BUFPOOL_UNLOCK(g_icmp_connections);
+ icmp_conn_list_unlock();
return ret;
}
#endif /* CONFIG_NET_ICMP */
diff --git a/net/icmpv6/icmpv6_conn.c b/net/icmpv6/icmpv6_conn.c
index edff7012e99..1ec1ee5d484 100644
--- a/net/icmpv6/icmpv6_conn.c
+++ b/net/icmpv6/icmpv6_conn.c
@@ -39,6 +39,8 @@
#include <nuttx/net/net.h>
#include <nuttx/net/netdev.h>
+#include <nuttx/mm/mempool.h>
+
#include "devif/devif.h"
#include "icmpv6/icmpv6.h"
#include "utils/utils.h"
@@ -59,10 +61,16 @@
/* The array containing all IPPROTO_ICMP socket connections */
-NET_BUFPOOL_DECLARE(g_icmpv6_connections, sizeof(struct icmpv6_conn_s),
- CONFIG_NET_ICMPv6_PREALLOC_CONNS,
- CONFIG_NET_ICMPv6_ALLOC_CONNS,
- CONFIG_NET_ICMPv6_MAX_CONNS);
+MEMPOOL_DEFINE(g_icmpv6_connections, sizeof(struct icmpv6_conn_s),
+ CONFIG_NET_ICMPv6_PREALLOC_CONNS,
+ CONFIG_NET_ICMPv6_MAX_CONNS,
+ CONFIG_NET_ICMPv6_ALLOC_CONNS);
+
+/* The list of all allocated IPPROTO_ICMP6 socket connections is protected
+ * by this rmutex.
+ */
+
+static rmutex_t g_icmpv6_connections_lock = NXRMUTEX_INITIALIZER;
/* A list of all allocated IPPROTO_ICMP socket connections */
@@ -88,9 +96,9 @@ FAR struct icmpv6_conn_s *icmpv6_alloc(void)
/* The free list is protected by a mutex. */
- NET_BUFPOOL_LOCK(g_icmpv6_connections);
+ nxrmutex_lock(&g_icmpv6_connections_lock);
- conn = NET_BUFPOOL_TRYALLOC(g_icmpv6_connections);
+ conn = mempool_allocate(&g_icmpv6_connections, 0);
if (conn != NULL)
{
/* Use conn_init to initialize the connection structure */
@@ -102,7 +110,7 @@ FAR struct icmpv6_conn_s *icmpv6_alloc(void)
dq_addlast(&conn->sconn.s_node, &g_active_icmpv6_connections);
}
- NET_BUFPOOL_UNLOCK(g_icmpv6_connections);
+ nxrmutex_unlock(&g_icmpv6_connections_lock);
return conn;
}
@@ -124,7 +132,7 @@ void icmpv6_free(FAR struct icmpv6_conn_s *conn)
/* Take the mutex (perhaps waiting) */
- NET_BUFPOOL_LOCK(g_icmpv6_connections);
+ nxrmutex_lock(&g_icmpv6_connections_lock);
/* Remove the connection from the active list */
@@ -136,9 +144,9 @@ void icmpv6_free(FAR struct icmpv6_conn_s *conn)
/* Free the connection. */
- NET_BUFPOOL_FREE(g_icmpv6_connections, conn);
+ mempool_release(&g_icmpv6_connections, conn);
- NET_BUFPOOL_UNLOCK(g_icmpv6_connections);
+ nxrmutex_unlock(&g_icmpv6_connections_lock);
}
/****************************************************************************
diff --git a/net/netforward/netfwd_alloc.c b/net/netforward/netfwd_alloc.c
index b5d448a2ef6..8bb29a87f80 100644
--- a/net/netforward/netfwd_alloc.c
+++ b/net/netforward/netfwd_alloc.c
@@ -35,6 +35,7 @@
#include <nuttx/net/udp.h>
#include <nuttx/net/icmp.h>
#include <nuttx/net/icmpv6.h>
+#include <nuttx/mm/mempool.h>
#include "netforward/netforward.h"
#include "utils/utils.h"
@@ -72,10 +73,10 @@ static_assert(MAX_HDRLEN <= CONFIG_IOB_BUFSIZE, "IOB buffer
size too small");
/* This is the state of the global forwarding structures */
-NET_BUFPOOL_DECLARE(g_fwdpool, sizeof(struct forward_s),
- CONFIG_NET_FORWARD_NSTRUCT,
- CONFIG_NET_FORWARD_ALLOC_STRUCT,
- CONFIG_IOB_NBUFFERS - CONFIG_IOB_THROTTLE);
+MEMPOOL_DEFINE(g_fwdpool, sizeof(struct forward_s),
+ CONFIG_NET_FORWARD_NSTRUCT,
+ CONFIG_IOB_NBUFFERS - CONFIG_IOB_THROTTLE,
+ CONFIG_NET_FORWARD_ALLOC_STRUCT);
/****************************************************************************
* Public Functions
@@ -96,7 +97,7 @@ NET_BUFPOOL_DECLARE(g_fwdpool, sizeof(struct forward_s),
FAR struct forward_s *netfwd_alloc(void)
{
- return NET_BUFPOOL_TRYALLOC(g_fwdpool);
+ return mempool_allocate(&g_fwdpool, 0);
}
/****************************************************************************
@@ -113,5 +114,5 @@ FAR struct forward_s *netfwd_alloc(void)
void netfwd_free(FAR struct forward_s *fwd)
{
- NET_BUFPOOL_FREE(g_fwdpool, fwd);
+ mempool_release(&g_fwdpool, fwd);
}
diff --git a/net/netlink/netlink_conn.c b/net/netlink/netlink_conn.c
index 7599df1c71e..0d61a40bbea 100644
--- a/net/netlink/netlink_conn.c
+++ b/net/netlink/netlink_conn.c
@@ -42,6 +42,7 @@
#include <nuttx/net/net.h>
#include <nuttx/net/netlink.h>
#include <nuttx/tls.h>
+#include <nuttx/mm/mempool.h>
#include "utils/utils.h"
#include "netlink/netlink.h"
@@ -62,9 +63,15 @@
/* The array containing all NetLink connections. */
-NET_BUFPOOL_DECLARE(g_netlink_connections, sizeof(struct netlink_conn_s),
- CONFIG_NETLINK_PREALLOC_CONNS,
- CONFIG_NETLINK_ALLOC_CONNS, CONFIG_NETLINK_MAX_CONNS);
+MEMPOOL_DEFINE(g_netlink_connections, sizeof(struct netlink_conn_s),
+ CONFIG_NETLINK_PREALLOC_CONNS, CONFIG_NETLINK_MAX_CONNS,
+ CONFIG_NETLINK_ALLOC_CONNS);
+
+/* The list of all allocated NetLink connections is protected by this
+ * rmutex.
+ */
+
+static rmutex_t g_netlink_connections_lock = NXRMUTEX_INITIALIZER;
/* A list of all allocated NetLink connections */
@@ -157,9 +164,9 @@ FAR struct netlink_conn_s *netlink_alloc(void)
/* The free list is protected by a mutex. */
- NET_BUFPOOL_LOCK(g_netlink_connections);
+ nxrmutex_lock(&g_netlink_connections_lock);
- conn = NET_BUFPOOL_TRYALLOC(g_netlink_connections);
+ conn = mempool_allocate(&g_netlink_connections, 0);
if (conn != NULL)
{
/* Use conn_init to initialize the connection structure */
@@ -171,7 +178,7 @@ FAR struct netlink_conn_s *netlink_alloc(void)
dq_addlast(&conn->sconn.s_node, &g_active_netlink_connections);
}
- NET_BUFPOOL_UNLOCK(g_netlink_connections);
+ nxrmutex_unlock(&g_netlink_connections_lock);
return conn;
}
@@ -192,7 +199,7 @@ void netlink_free(FAR struct netlink_conn_s *conn)
DEBUGASSERT(conn->crefs == 0);
- NET_BUFPOOL_LOCK(g_netlink_connections);
+ nxrmutex_lock(&g_netlink_connections_lock);
/* Remove the connection from the active list */
@@ -207,9 +214,9 @@ void netlink_free(FAR struct netlink_conn_s *conn)
/* Free the connection */
- NET_BUFPOOL_FREE(g_netlink_connections, conn);
+ mempool_release(&g_netlink_connections, conn);
- NET_BUFPOOL_UNLOCK(g_netlink_connections);
+ nxrmutex_unlock(&g_netlink_connections_lock);
}
/****************************************************************************
diff --git a/net/pkt/pkt_conn.c b/net/pkt/pkt_conn.c
index 16bd18ecf58..46b83af3707 100644
--- a/net/pkt/pkt_conn.c
+++ b/net/pkt/pkt_conn.c
@@ -42,6 +42,7 @@
#include <nuttx/net/net.h>
#include <nuttx/net/netdev.h>
#include <nuttx/net/ethernet.h>
+#include <nuttx/mm/mempool.h>
#include "devif/devif.h"
#include "netdev/netdev.h"
@@ -67,9 +68,15 @@
/* The array containing all packet socket connections */
-NET_BUFPOOL_DECLARE(g_pkt_connections, sizeof(struct pkt_conn_s),
- CONFIG_NET_PKT_PREALLOC_CONNS,
- CONFIG_NET_PKT_ALLOC_CONNS, CONFIG_NET_PKT_MAX_CONNS);
+MEMPOOL_DEFINE(g_pkt_connections, sizeof(struct pkt_conn_s),
+ CONFIG_NET_PKT_PREALLOC_CONNS, CONFIG_NET_PKT_MAX_CONNS,
+ CONFIG_NET_PKT_ALLOC_CONNS);
+
+/* The list of all allocated packet socket connections is protected by this
+ * rmutex.
+ */
+
+static rmutex_t g_pkt_connections_lock = NXRMUTEX_INITIALIZER;
/* A list of all allocated packet socket connections */
@@ -94,9 +101,9 @@ FAR struct pkt_conn_s *pkt_alloc(void)
/* The free list is protected by a mutex. */
- NET_BUFPOOL_LOCK(g_pkt_connections);
+ pkt_conn_list_lock();
- conn = NET_BUFPOOL_TRYALLOC(g_pkt_connections);
+ conn = mempool_allocate(&g_pkt_connections, 0);
if (conn)
{
/* Use conn_init to initialize the connection structure */
@@ -108,7 +115,7 @@ FAR struct pkt_conn_s *pkt_alloc(void)
dq_addlast(&conn->sconn.s_node, &g_active_pkt_connections);
}
- NET_BUFPOOL_UNLOCK(g_pkt_connections);
+ pkt_conn_list_unlock();
return conn;
}
@@ -127,7 +134,7 @@ void pkt_free(FAR struct pkt_conn_s *conn)
DEBUGASSERT(conn->crefs == 0);
- NET_BUFPOOL_LOCK(g_pkt_connections);
+ pkt_conn_list_lock();
/* Remove the connection from the active list */
@@ -165,9 +172,9 @@ void pkt_free(FAR struct pkt_conn_s *conn)
/* Free the connection. */
- NET_BUFPOOL_FREE(g_pkt_connections, conn);
+ mempool_release(&g_pkt_connections, conn);
- NET_BUFPOOL_UNLOCK(g_pkt_connections);
+ pkt_conn_list_unlock();
}
/****************************************************************************
@@ -362,7 +369,7 @@ int pkt_sendmsg_is_valid(FAR struct socket *psock,
void pkt_conn_list_lock(void)
{
- NET_BUFPOOL_LOCK(g_pkt_connections);
+ nxrmutex_lock(&g_pkt_connections_lock);
}
/****************************************************************************
@@ -378,7 +385,7 @@ void pkt_conn_list_lock(void)
void pkt_conn_list_unlock(void)
{
- NET_BUFPOOL_UNLOCK(g_pkt_connections);
+ nxrmutex_unlock(&g_pkt_connections_lock);
}
#endif /* CONFIG_NET && CONFIG_NET_PKT */
diff --git a/net/route/net_alloc_ramroute.c b/net/route/net_alloc_ramroute.c
index 2f4c62617fa..c0ef6f1d8db 100644
--- a/net/route/net_alloc_ramroute.c
+++ b/net/route/net_alloc_ramroute.c
@@ -30,7 +30,9 @@
#include <errno.h>
#include <assert.h>
+#include <nuttx/mutex.h>
#include <nuttx/net/net.h>
+#include <nuttx/mm/mempool.h>
#include <arch/irq.h>
#include "utils/utils.h"
@@ -62,13 +64,21 @@ FAR struct net_route_ipv6_queue_s g_ipv6_routes;
/* The array containing all routing table entries. */
#ifdef CONFIG_ROUTE_IPv4_RAMROUTE
-NET_BUFPOOL_DECLARE(g_ipv4routes, sizeof(struct net_route_ipv4_entry_s),
- CONFIG_ROUTE_MAX_IPv4_RAMROUTES, 0, 0);
+MEMPOOL_DEFINE(g_ipv4routes, sizeof(struct net_route_ipv4_entry_s),
+ CONFIG_ROUTE_MAX_IPv4_RAMROUTES, 0, 0);
+
+/* The IPv4 routing table pool is protected by this rmutex. */
+
+static rmutex_t g_ipv4routes_lock = NXRMUTEX_INITIALIZER;
#endif
#ifdef CONFIG_ROUTE_IPv6_RAMROUTE
-NET_BUFPOOL_DECLARE(g_ipv6routes, sizeof(struct net_route_ipv6_entry_s),
- CONFIG_ROUTE_MAX_IPv6_RAMROUTES, 0, 0);
+MEMPOOL_DEFINE(g_ipv6routes, sizeof(struct net_route_ipv6_entry_s),
+ CONFIG_ROUTE_MAX_IPv6_RAMROUTES, 0, 0);
+
+/* The IPv6 routing table pool is protected by this rmutex. */
+
+static rmutex_t g_ipv6routes_lock = NXRMUTEX_INITIALIZER;
#endif
/****************************************************************************
@@ -99,7 +109,7 @@ FAR struct net_route_ipv4_s *net_allocroute_ipv4(void)
* then remove the first entry from the g_ipv4routes pool
*/
- route = NET_BUFPOOL_TRYALLOC(g_ipv4routes);
+ route = mempool_allocate(&g_ipv4routes, 0);
if (!route)
{
return NULL;
@@ -118,7 +128,7 @@ FAR struct net_route_ipv6_s *net_allocroute_ipv6(void)
* then remove the first entry from the g_ipv6routes pool
*/
- route = NET_BUFPOOL_TRYALLOC(g_ipv6routes);
+ route = mempool_allocate(&g_ipv6routes, 0);
if (!route)
{
return NULL;
@@ -149,7 +159,7 @@ void net_freeroute_ipv4(FAR struct net_route_ipv4_s *route)
/* Add the new entry to the g_ipv4routes pool */
- NET_BUFPOOL_FREE(g_ipv4routes, (FAR struct net_route_ipv4_entry_s *)route);
+ mempool_release(&g_ipv4routes, (FAR struct net_route_ipv4_entry_s *)route);
}
#endif
@@ -160,7 +170,7 @@ void net_freeroute_ipv6(FAR struct net_route_ipv6_s *route)
/* Add the new entry to the g_ipv6routes pool */
- NET_BUFPOOL_FREE(g_ipv6routes, (FAR struct net_route_ipv6_entry_s *)route);
+ mempool_release(&g_ipv6routes, (FAR struct net_route_ipv6_entry_s *)route);
}
#endif
@@ -175,12 +185,12 @@ void net_freeroute_ipv6(FAR struct net_route_ipv6_s
*route)
#ifdef CONFIG_ROUTE_IPv4_RAMROUTE
void net_lockroute_ipv4(void)
{
- NET_BUFPOOL_LOCK(g_ipv4routes);
+ nxrmutex_lock(&g_ipv4routes_lock);
}
void net_unlockroute_ipv4(void)
{
- NET_BUFPOOL_UNLOCK(g_ipv4routes);
+ nxrmutex_unlock(&g_ipv4routes_lock);
}
#endif
@@ -195,12 +205,12 @@ void net_unlockroute_ipv4(void)
#ifdef CONFIG_ROUTE_IPv6_RAMROUTE
void net_lockroute_ipv6(void)
{
- NET_BUFPOOL_LOCK(g_ipv6routes);
+ nxrmutex_lock(&g_ipv6routes_lock);
}
void net_unlockroute_ipv6(void)
{
- NET_BUFPOOL_UNLOCK(g_ipv6routes);
+ nxrmutex_unlock(&g_ipv6routes_lock);
}
#endif
diff --git a/net/udp/udp_conn.c b/net/udp/udp_conn.c
index ff072a139bf..051e53fe0f6 100644
--- a/net/udp/udp_conn.c
+++ b/net/udp/udp_conn.c
@@ -64,6 +64,7 @@
#include <nuttx/net/netdev.h>
#include <nuttx/net/ip.h>
#include <nuttx/net/udp.h>
+#include <nuttx/mm/mempool.h>
#include "devif/devif.h"
#include "inet/inet.h"
@@ -88,9 +89,13 @@
/* The array containing all UDP connections. */
-NET_BUFPOOL_DECLARE(g_udp_connections, sizeof(struct udp_conn_s),
- CONFIG_NET_UDP_PREALLOC_CONNS,
- CONFIG_NET_UDP_ALLOC_CONNS, CONFIG_NET_UDP_MAX_CONNS);
+MEMPOOL_DEFINE(g_udp_connections, sizeof(struct udp_conn_s),
+ CONFIG_NET_UDP_PREALLOC_CONNS, CONFIG_NET_UDP_MAX_CONNS,
+ CONFIG_NET_UDP_ALLOC_CONNS);
+
+/* The list of all allocated UDP connections is protected by this rmutex. */
+
+static rmutex_t g_udp_connections_lock = NXRMUTEX_INITIALIZER;
/* A list of all allocated UDP connections */
@@ -684,9 +689,9 @@ FAR struct udp_conn_s *udp_alloc(uint8_t domain)
/* The free list is protected by a mutex. */
- NET_BUFPOOL_LOCK(g_udp_connections);
+ udp_conn_list_lock();
- conn = NET_BUFPOOL_TRYALLOC(g_udp_connections);
+ conn = mempool_allocate(&g_udp_connections, 0);
if (conn)
{
@@ -720,7 +725,7 @@ FAR struct udp_conn_s *udp_alloc(uint8_t domain)
dq_addlast(&conn->sconn.s_node, &g_active_udp_connections);
}
- NET_BUFPOOL_UNLOCK(g_udp_connections);
+ udp_conn_list_unlock();
return conn;
}
@@ -743,7 +748,7 @@ void udp_free(FAR struct udp_conn_s *conn)
DEBUGASSERT(conn->crefs == 0);
- NET_BUFPOOL_LOCK(g_udp_connections);
+ udp_conn_list_lock();
conn->lport = 0;
/* Remove the connection from the active list */
@@ -781,9 +786,9 @@ void udp_free(FAR struct udp_conn_s *conn)
/* Free the connection. */
- NET_BUFPOOL_FREE(g_udp_connections, conn);
+ mempool_release(&g_udp_connections, conn);
- NET_BUFPOOL_UNLOCK(g_udp_connections);
+ udp_conn_list_unlock();
}
/****************************************************************************
@@ -834,7 +839,7 @@ FAR struct udp_conn_s *udp_active(FAR struct net_driver_s
*dev,
void udp_conn_list_lock(void)
{
- NET_BUFPOOL_LOCK(g_udp_connections);
+ nxrmutex_lock(&g_udp_connections_lock);
}
/****************************************************************************
@@ -850,7 +855,7 @@ void udp_conn_list_lock(void)
void udp_conn_list_unlock(void)
{
- NET_BUFPOOL_UNLOCK(g_udp_connections);
+ nxrmutex_unlock(&g_udp_connections_lock);
}
/****************************************************************************
diff --git a/net/udp/udp_wrbuffer.c b/net/udp/udp_wrbuffer.c
index 76c387a7313..c72c434a492 100644
--- a/net/udp/udp_wrbuffer.c
+++ b/net/udp/udp_wrbuffer.c
@@ -43,6 +43,7 @@
#include <nuttx/semaphore.h>
#include <nuttx/net/net.h>
#include <nuttx/mm/iob.h>
+#include <nuttx/mm/mempool.h>
#include "utils/utils.h"
#include "udp/udp.h"
@@ -53,9 +54,9 @@
/* This is the state of the global write buffer resource */
-NET_BUFPOOL_DECLARE(g_wrbuffer, sizeof(struct udp_wrbuffer_s),
- CONFIG_NET_UDP_NWRBCHAINS,
- CONFIG_NET_UDP_ALLOC_WRBCHAINS, 0);
+MEMPOOL_DEFINE(g_wrbuffer, sizeof(struct udp_wrbuffer_s),
+ CONFIG_NET_UDP_NWRBCHAINS, 0,
+ CONFIG_NET_UDP_ALLOC_WRBCHAINS);
/****************************************************************************
* Public Functions
@@ -90,7 +91,7 @@ FAR struct udp_wrbuffer_s *udp_wrbuffer_timedalloc(unsigned
int timeout)
* buffer
*/
- wrb = NET_BUFPOOL_TIMEDALLOC(g_wrbuffer, timeout);
+ wrb = mempool_allocate(&g_wrbuffer, timeout);
if (wrb == NULL)
{
return NULL;
@@ -148,7 +149,7 @@ FAR struct udp_wrbuffer_s *udp_wrbuffer_tryalloc(void)
* buffer
*/
- wrb = NET_BUFPOOL_TRYALLOC(g_wrbuffer);
+ wrb = mempool_allocate(&g_wrbuffer, 0);
if (wrb == NULL)
{
return NULL;
@@ -199,7 +200,7 @@ void udp_wrbuffer_release(FAR struct udp_wrbuffer_s *wrb)
/* Then free the write buffer structure */
- NET_BUFPOOL_FREE(g_wrbuffer, wrb);
+ mempool_release(&g_wrbuffer, wrb);
}
/****************************************************************************
@@ -247,7 +248,7 @@ uint32_t udp_wrbuffer_inqueue_size(FAR struct udp_conn_s
*conn)
int udp_wrbuffer_test(void)
{
- return NET_BUFPOOL_TEST(g_wrbuffer);
+ return (mempool_navail(&g_wrbuffer) > 0 ? OK : -ENOSPC);
}
#endif /* CONFIG_NET && CONFIG_NET_UDP && CONFIG_NET_UDP_WRITE_BUFFERS */