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 <zhanghongyu@xiaomi.com>
This commit is contained in:
zhanghongyu
2025-11-17 20:46:25 +08:00
committed by Alan C. Assis
parent b8850e4eb3
commit 11c4bb7f31
+62 -40
View File
@@ -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
}