This is an automated email from the ASF dual-hosted git repository. acassis pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit efd8e1be2b4d762043a282082a04ddc3ac90714d Author: zhanghongyu <[email protected]> AuthorDate: Mon Nov 17 22:00:05 2025 +0800 net/ieee802154: replace net_lock with conn_lock and conn_lock_dev decouple lock dependencies from other modules. Signed-off-by: zhanghongyu <[email protected]> --- net/devif/devif_poll.c | 2 ++ net/ieee802154/ieee802154.h | 35 +++++++++++++++++++++++++++++++++++ net/ieee802154/ieee802154_callback.c | 3 +++ net/ieee802154/ieee802154_conn.c | 16 ++++++++++++---- net/ieee802154/ieee802154_container.c | 12 ++++++------ net/ieee802154/ieee802154_recvmsg.c | 11 +++++++---- net/ieee802154/ieee802154_sendmsg.c | 7 ++++--- 7 files changed, 69 insertions(+), 17 deletions(-) diff --git a/net/devif/devif_poll.c b/net/devif/devif_poll.c index 00445ceb1c6..91721991e4c 100644 --- a/net/devif/devif_poll.c +++ b/net/devif/devif_poll.c @@ -385,6 +385,7 @@ devif_poll_ieee802154_connections(FAR struct net_driver_s *dev, * action. */ + ieee802154_conn_list_lock(); while (!bstop && (ieee802154_conn = ieee802154_conn_next(ieee802154_conn))) { /* Perform the packet TX poll */ @@ -399,6 +400,7 @@ devif_poll_ieee802154_connections(FAR struct net_driver_s *dev, } } + ieee802154_conn_list_unlock(); return bstop; } #endif /* CONFIG_NET_IEEE802154 */ diff --git a/net/ieee802154/ieee802154.h b/net/ieee802154/ieee802154.h index a5869dfa326..2864ba7989c 100644 --- a/net/ieee802154/ieee802154.h +++ b/net/ieee802154/ieee802154.h @@ -32,6 +32,7 @@ #include <sys/types.h> #include <netpacket/ieee802154.h> +#include <nuttx/mutex.h> #include <nuttx/net/net.h> #ifdef CONFIG_NET_IEEE802154 @@ -133,6 +134,40 @@ extern "C" EXTERN const struct sock_intf_s g_ieee802154_sockif; +/* The IEEE 802.15.4 connections rmutex */ + +extern rmutex_t g_ieee802154_connections_lock; + +/**************************************************************************** + * Inline Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: ieee802154_conn_list_lock + * + * Description: + * Lock the IEEE 802.15.4 connection list. + * + ****************************************************************************/ + +static inline_function void ieee802154_conn_list_lock(void) +{ + nxrmutex_lock(&g_ieee802154_connections_lock); +} + +/**************************************************************************** + * Name: ieee802154_conn_list_unlock + * + * Description: + * Unlock the IEEE 802.15.4 connection list. + * + ****************************************************************************/ + +static inline_function void ieee802154_conn_list_unlock(void) +{ + nxrmutex_unlock(&g_ieee802154_connections_lock); +} + /**************************************************************************** * Public Function Prototypes ****************************************************************************/ diff --git a/net/ieee802154/ieee802154_callback.c b/net/ieee802154/ieee802154_callback.c index 5d79d834130..a90bcab6129 100644 --- a/net/ieee802154/ieee802154_callback.c +++ b/net/ieee802154/ieee802154_callback.c @@ -33,6 +33,7 @@ #include <nuttx/net/ieee802154.h> #include "devif/devif.h" +#include "utils/utils.h" #include "ieee802154/ieee802154.h" #ifdef CONFIG_NET_IEEE802154 @@ -67,7 +68,9 @@ uint32_t ieee802154_callback(FAR struct radio_driver_s *radio, { /* Perform the callback */ + conn_lock(&conn->sconn); flags = devif_conn_event(&radio->r_dev, flags, conn->sconn.list); + conn_unlock(&conn->sconn); } return flags; diff --git a/net/ieee802154/ieee802154_conn.c b/net/ieee802154/ieee802154_conn.c index ce89c02c6b2..5d5049a578a 100644 --- a/net/ieee802154/ieee802154_conn.c +++ b/net/ieee802154/ieee802154_conn.c @@ -54,6 +54,14 @@ # define CONFIG_NET_IEEE802154_MAX_CONNS 0 #endif +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/* The IEEE 802.15.4 connections rmutex */ + +rmutex_t g_ieee802154_connections_lock = NXRMUTEX_INITIALIZER; + /**************************************************************************** * Private Data ****************************************************************************/ @@ -91,7 +99,7 @@ FAR struct ieee802154_conn_s *ieee802154_conn_alloc(void) /* The free list is protected by the network lock. */ - net_lock(); + ieee802154_conn_list_lock(); conn = NET_BUFPOOL_TRYALLOC(g_ieee802154_connections); if (conn) @@ -99,7 +107,7 @@ FAR struct ieee802154_conn_s *ieee802154_conn_alloc(void) dq_addlast(&conn->sconn.node, &g_active_ieee802154_connections); } - net_unlock(); + ieee802154_conn_list_unlock(); return conn; } @@ -123,7 +131,7 @@ void ieee802154_conn_free(FAR struct ieee802154_conn_s *conn) /* Remove the connection from the active list */ - net_lock(); + ieee802154_conn_list_lock(); dq_rem(&conn->sconn.node, &g_active_ieee802154_connections); /* Check if there any any frames attached to the container */ @@ -151,7 +159,7 @@ void ieee802154_conn_free(FAR struct ieee802154_conn_s *conn) NET_BUFPOOL_FREE(g_ieee802154_connections, conn); - net_unlock(); + ieee802154_conn_list_unlock(); } /**************************************************************************** diff --git a/net/ieee802154/ieee802154_container.c b/net/ieee802154/ieee802154_container.c index 14f32ee2adb..ddf9e81c70b 100644 --- a/net/ieee802154/ieee802154_container.c +++ b/net/ieee802154/ieee802154_container.c @@ -133,17 +133,17 @@ FAR struct ieee802154_container_s *ieee802154_container_allocate(void) /* Try the free list first */ - net_lock(); + ieee802154_conn_list_lock(); if (g_free_container != NULL) { container = g_free_container; g_free_container = container->ic_flink; pool = IEEE802154_POOL_PREALLOCATED; - net_unlock(); + ieee802154_conn_list_unlock(); } else { - net_unlock(); + ieee802154_conn_list_unlock(); container = (FAR struct ieee802154_container_s *) kmm_malloc((sizeof (struct ieee802154_container_s))); pool = IEEE802154_POOL_DYNAMIC; @@ -188,12 +188,12 @@ void ieee802154_container_free(FAR struct ieee802154_container_s *container) * in the free list. */ - net_lock(); + ieee802154_conn_list_lock(); if (container->ic_pool == IEEE802154_POOL_PREALLOCATED) { container->ic_flink = g_free_container; g_free_container = container; - net_unlock(); + ieee802154_conn_list_unlock(); } else { @@ -201,7 +201,7 @@ void ieee802154_container_free(FAR struct ieee802154_container_s *container) /* Otherwise, deallocate it. */ - net_unlock(); + ieee802154_conn_list_unlock(); kmm_free(container); } } diff --git a/net/ieee802154/ieee802154_recvmsg.c b/net/ieee802154/ieee802154_recvmsg.c index 1720390502b..e33f35092dc 100644 --- a/net/ieee802154/ieee802154_recvmsg.c +++ b/net/ieee802154/ieee802154_recvmsg.c @@ -45,6 +45,7 @@ #include "netdev/netdev.h" #include "devif/devif.h" #include "socket/socket.h" +#include "utils/utils.h" #include "ieee802154/ieee802154.h" #ifdef CONFIG_NET_IEEE802154 @@ -341,7 +342,6 @@ ssize_t ieee802154_recvmsg(FAR struct socket *psock, FAR struct msghdr *msg, * locked because we don't want anything to happen until we are ready. */ - net_lock(); memset(&state, 0, sizeof(struct ieee802154_recvfrom_s)); state.ir_buflen = len; @@ -358,6 +358,8 @@ ssize_t ieee802154_recvmsg(FAR struct socket *psock, FAR struct msghdr *msg, goto errout_with_lock; } + conn_dev_lock(&conn->sconn, &radio->r_dev); + /* Before we wait for data, let's check if there are already frame(s) * waiting in the RX queue. */ @@ -367,7 +369,7 @@ ssize_t ieee802154_recvmsg(FAR struct socket *psock, FAR struct msghdr *msg, { /* Good newe! We have a frame and we are done. */ - net_unlock(); + conn_dev_unlock(&conn->sconn, &radio->r_dev); return ret; } @@ -388,7 +390,8 @@ ssize_t ieee802154_recvmsg(FAR struct socket *psock, FAR struct msghdr *msg, * the task sleeps and automatically re-locked when the task restarts. */ - net_sem_wait(&state.ir_sem); + conn_dev_sem_timedwait(&state.ir_sem, true, UINT_MAX, + &conn->sconn, &radio->r_dev); /* Make sure that no further events are processed */ @@ -403,7 +406,7 @@ ssize_t ieee802154_recvmsg(FAR struct socket *psock, FAR struct msghdr *msg, nxsem_destroy(&state.ir_sem); errout_with_lock: - net_unlock(); + conn_dev_unlock(&conn->sconn, &radio->r_dev); return ret; } diff --git a/net/ieee802154/ieee802154_sendmsg.c b/net/ieee802154/ieee802154_sendmsg.c index a54e8b65da3..b166e64dbbd 100644 --- a/net/ieee802154/ieee802154_sendmsg.c +++ b/net/ieee802154/ieee802154_sendmsg.c @@ -469,7 +469,7 @@ static ssize_t ieee802154_sendto(FAR struct socket *psock, * ready. */ - net_lock(); + conn_dev_lock(&conn->sconn, &radio->r_dev); memset(&state, 0, sizeof(struct ieee802154_sendto_s)); nxsem_init(&state.is_sem, 0, 0); /* Doesn't really fail */ @@ -504,7 +504,8 @@ static ssize_t ieee802154_sendto(FAR struct socket *psock, * net_sem_wait will also terminate if a signal is received. */ - ret = net_sem_wait(&state.is_sem); + ret = conn_dev_sem_timedwait(&state.is_sem, true, UINT_MAX, + &conn->sconn, &radio->r_dev); /* Make sure that no further events are processed */ @@ -513,7 +514,7 @@ static ssize_t ieee802154_sendto(FAR struct socket *psock, } nxsem_destroy(&state.is_sem); - net_unlock(); + conn_dev_unlock(&conn->sconn, &radio->r_dev); /* Check for a errors, Errors are signaled by negative errno values * for the send length
