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 11c4bb7f318c8b61630d1ab2eb71d5e12742add3 Author: zhanghongyu <[email protected]> AuthorDate: Mon Nov 17 20:46:25 2025 +0800 utils.h: add conn_dev_sem_timedwait interface to simplify code logic the following code can be modified conn_dev_unlock(&conn->sconn, conn->dev); ret = net_sem_timedwait_uninterruptible(&conn->snd_sem, tcp_send_gettimeout(start, timeout)); conn_dev_lock(&conn->sconn, conn->dev); to ret = conn_dev_sem_timedwait(&conn->snd_sem, false, tcp_send_gettimeout(start, timeout), &conn->sconn, conn->dev); Signed-off-by: zhanghongyu <[email protected]> --- net/utils/utils.h | 102 +++++++++++++++++++++++++++++++++--------------------- 1 file changed, 62 insertions(+), 40 deletions(-) diff --git a/net/utils/utils.h b/net/utils/utils.h index 899d918ddbf..8acb53b3621 100644 --- a/net/utils/utils.h +++ b/net/utils/utils.h @@ -153,6 +153,68 @@ extern "C" #define EXTERN extern #endif +/**************************************************************************** + * Inline Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: conn_lock, conn_unlock, conn_dev_lock, conn_dev_unlock + * + * Description: + * Lock and unlock the connection and device. + * + ****************************************************************************/ + +static inline_function void conn_lock(FAR struct socket_conn_s *sconn) +{ + nxrmutex_lock(&sconn->s_lock); +} + +static inline_function void conn_unlock(FAR struct socket_conn_s *sconn) +{ + nxrmutex_unlock(&sconn->s_lock); +} + +static inline_function void conn_dev_lock(FAR struct socket_conn_s *sconn, + FAR struct net_driver_s *dev) +{ + if (dev != NULL) + { + netdev_lock(dev); + } + + nxrmutex_lock(&sconn->s_lock); +} + +static inline_function void conn_dev_unlock(FAR struct socket_conn_s *sconn, + FAR struct net_driver_s *dev) +{ + nxrmutex_unlock(&sconn->s_lock); + + if (dev != NULL) + { + netdev_unlock(dev); + } +} + +/**************************************************************************** + * Name: conn_dev_sem_timedwait + * + * Description: + * Wait on the connection semaphore, unlocking the device and connection + * locks while waiting. + * + ****************************************************************************/ + +static inline_function int +conn_dev_sem_timedwait(FAR sem_t *sem, bool interruptible, + unsigned int timeout, FAR struct socket_conn_s *sconn, + FAR struct net_driver_s *dev) +{ + return net_sem_timedwait2(sem, interruptible, timeout, &sconn->s_lock, + dev ? &dev->d_lock : NULL); +} + /**************************************************************************** * Public Function Prototypes ****************************************************************************/ @@ -607,46 +669,6 @@ uint16_t icmpv6_chksum(FAR struct net_driver_s *dev, unsigned int iplen); FAR void *cmsg_append(FAR struct msghdr *msg, int level, int type, FAR void *value, int value_len); -/**************************************************************************** - * Name: conn_lock, conn_unlock, conn_dev_lock, conn_dev_unlock - * - * Description: - * Lock and unlock the connection and device. - * - ****************************************************************************/ - -static inline_function void conn_lock(FAR struct socket_conn_s *sconn) -{ - nxrmutex_lock(&sconn->s_lock); -} - -static inline_function void conn_unlock(FAR struct socket_conn_s *sconn) -{ - nxrmutex_unlock(&sconn->s_lock); -} - -static inline_function void conn_dev_lock(FAR struct socket_conn_s *sconn, - FAR struct net_driver_s *dev) -{ - if (dev != NULL) - { - netdev_lock(dev); - } - - nxrmutex_lock(&sconn->s_lock); -} - -static inline_function void conn_dev_unlock(FAR struct socket_conn_s *sconn, - FAR struct net_driver_s *dev) -{ - nxrmutex_unlock(&sconn->s_lock); - - if (dev != NULL) - { - netdev_unlock(dev); - } -} - #undef EXTERN #ifdef __cplusplus }
