net: replace net_sem*wait with conn_dev_sem*wait to simplify code logic

optimize the current code format according to the previous net_xxx_wait
implementation to reduce multiple calls of similar code

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
This commit is contained in:
zhanghongyu
2025-11-24 20:17:18 +08:00
committed by Alan C. Assis
parent aee7ea0d7d
commit 8f41613374
42 changed files with 196 additions and 205 deletions
+11 -10
View File
@@ -360,7 +360,8 @@ static uint32_t can_recvfrom_eventhandler(FAR struct net_driver_s *dev,
* Evaluate the result of the recv operations
*
* Input Parameters:
* result The result of the net_sem_wait operation (may indicate EINTR)
* result The result of the conn_dev_sem_timedwait operation
* (may indicate EINTR)
* pstate A pointer to the state structure to be initialized
*
* Returned Value:
@@ -384,9 +385,9 @@ static ssize_t can_recvfrom_result(int result,
return pstate->pr_result;
}
/* If net_sem_wait failed, then we were probably reawakened by a signal.
* In this case, net_sem_wait will have returned negated errno
* appropriately.
/* If conn_dev_sem_timedwait failed, then we were probably reawakened by
* a signal. In this case, conn_dev_sem_timedwait will have returned
* negated errno appropriately.
*/
if (result < 0)
@@ -518,14 +519,14 @@ ssize_t can_recvmsg(FAR struct socket *psock, FAR struct msghdr *msg,
state.pr_cb->event = can_recvfrom_eventhandler;
/* Wait for either the receive to complete or for an error/timeout to
* occur. NOTES: (1) net_sem_wait will also terminate if a signal
* is received, (2) the network is locked! It will be un-locked while
* the task sleeps and automatically re-locked when the task restarts.
* occur. NOTES: (1) conn_dev_sem_timedwait will also terminate if a
* signal is received, (2) the network is locked! It will be un-locked
* while the task sleeps and automatically re-locked when the task
* restarts.
*/
conn_dev_unlock(&conn->sconn, dev);
ret = net_sem_wait(&state.pr_sem);
conn_dev_lock(&conn->sconn, dev);
ret = conn_dev_sem_timedwait(&state.pr_sem, true, UINT_MAX,
&conn->sconn, dev);
/* Make sure that no further events are processed */
+8 -9
View File
@@ -264,21 +264,20 @@ ssize_t can_sendmsg(FAR struct socket *psock, FAR struct msghdr *msg,
netdev_txnotify_dev(dev, CAN_POLL);
/* Wait for the send to complete or an error to occur.
* net_sem_timedwait will also terminate if a signal is received.
* conn_dev_sem_timedwait will also terminate if a signal is received.
*/
conn_dev_unlock(&conn->sconn, dev);
if (_SS_ISNONBLOCK(conn->sconn.s_flags) || (flags & MSG_DONTWAIT) != 0)
{
ret = net_sem_timedwait(&state.snd_sem, 0);
ret = conn_dev_sem_timedwait(&state.snd_sem, true, 0,
&conn->sconn, dev);
}
else
{
ret = net_sem_timedwait(&state.snd_sem, UINT_MAX);
ret = conn_dev_sem_timedwait(&state.snd_sem, true, UINT_MAX,
&conn->sconn, dev);
}
conn_dev_lock(&conn->sconn, dev);
/* Make sure that no further events are processed */
can_callback_free(dev, conn, state.snd_cb);
@@ -296,9 +295,9 @@ ssize_t can_sendmsg(FAR struct socket *psock, FAR struct msghdr *msg,
return state.snd_sent;
}
/* If net_sem_wait failed, then we were probably reawakened by a signal.
* In this case, net_sem_wait will have returned negated errno
* appropriately.
/* If conn_dev_sem_timedwait failed, then we were probably reawakened by
* a signal. In this case, conn_dev_sem_timedwait will have returned
* negated errno appropriately.
*/
if (ret < 0)
+3 -2
View File
@@ -263,8 +263,9 @@ ssize_t can_sendmsg(FAR struct socket *psock, FAR struct msghdr *msg,
goto errout_with_lock;
}
ret = net_sem_timedwait_uninterruptible(&conn->sndsem,
_SO_TIMEOUT(conn->sconn.s_sndtimeo));
ret = conn_dev_sem_timedwait(&conn->sndsem, false,
_SO_TIMEOUT(conn->sconn.s_sndtimeo),
&conn->sconn, dev);
if (ret < 0)
{
goto errout_with_lock;