net/ieee802154: replace net_lock with conn_lock and conn_lock_dev

decouple lock dependencies from other modules.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
This commit is contained in:
zhanghongyu
2025-11-17 22:00:05 +08:00
committed by Alan C. Assis
parent 92b3357182
commit efd8e1be2b
7 changed files with 69 additions and 17 deletions
+2
View File
@@ -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 */
+35
View File
@@ -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
****************************************************************************/
+3
View File
@@ -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;
+12 -4
View File
@@ -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();
}
/****************************************************************************
+6 -6
View File
@@ -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);
}
}
+7 -4
View File
@@ -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;
}
+4 -3
View File
@@ -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