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 8f416133746df3b2ba70330370b7893af3aea356
Author: zhanghongyu <[email protected]>
AuthorDate: Mon Nov 24 20:17:18 2025 +0800

    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 <[email protected]>
---
 net/arp/arp_notify.c                |  2 +-
 net/arp/arp_send.c                  |  6 +++---
 net/bluetooth/bluetooth_recvmsg.c   |  7 ++++---
 net/bluetooth/bluetooth_sendmsg.c   |  9 +++++----
 net/can/can_recvmsg.c               | 21 +++++++++++----------
 net/can/can_sendmsg.c               | 17 ++++++++---------
 net/can/can_sendmsg_buffered.c      |  5 +++--
 net/devif/devif_callback.c          | 11 ++++++-----
 net/icmp/icmp_recvmsg.c             |  9 ++++-----
 net/icmp/icmp_sendmsg.c             |  9 ++++-----
 net/icmpv6/icmpv6.h                 | 10 ++++++----
 net/icmpv6/icmpv6_autoconfig.c      | 10 +++-------
 net/icmpv6/icmpv6_neighbor.c        | 11 ++++-------
 net/icmpv6/icmpv6_notify.c          |  6 ++++--
 net/icmpv6/icmpv6_recvmsg.c         | 11 ++++++-----
 net/icmpv6/icmpv6_rnotify.c         |  5 +++--
 net/icmpv6/icmpv6_sendmsg.c         |  9 ++++-----
 net/ieee802154/ieee802154_recvmsg.c |  7 ++++---
 net/ieee802154/ieee802154_sendmsg.c |  9 +++++----
 net/igmp/igmp_msg.c                 |  2 +-
 net/ipfrag/ipfrag.c                 |  4 ++--
 net/mld/mld_msg.c                   |  2 +-
 net/netlink/netlink_conn.c          |  7 ++-----
 net/pkt/pkt_recvmsg.c               | 18 +++++++++---------
 net/pkt/pkt_sendmsg_buffered.c      |  5 +++--
 net/pkt/pkt_sendmsg_unbuffered.c    | 14 +++++++-------
 net/pkt/pkt_sockif.c                |  7 +++----
 net/sixlowpan/sixlowpan_internal.h  |  8 +++-----
 net/sixlowpan/sixlowpan_send.c      | 30 ++++++++++++++++++------------
 net/sixlowpan/sixlowpan_tcpsend.c   | 10 ++++++----
 net/sixlowpan/sixlowpan_udpsend.c   |  8 ++------
 net/tcp/tcp_accept.c                | 13 ++++++-------
 net/tcp/tcp_connect.c               | 11 ++++++-----
 net/tcp/tcp_recvfrom.c              | 15 +++++----------
 net/tcp/tcp_send_buffered.c         |  7 +++----
 net/tcp/tcp_send_unbuffered.c       | 14 +++++++-------
 net/tcp/tcp_sendfile.c              |  5 +++--
 net/tcp/tcp_txdrain.c               |  5 ++---
 net/udp/udp_recvfrom.c              | 17 ++++++++---------
 net/udp/udp_sendto_buffered.c       | 10 +++++-----
 net/udp/udp_sendto_unbuffered.c     | 10 ++++------
 net/udp/udp_txdrain.c               |  5 ++---
 42 files changed, 196 insertions(+), 205 deletions(-)

diff --git a/net/arp/arp_notify.c b/net/arp/arp_notify.c
index a4568ed1367..aa6dce1fa12 100644
--- a/net/arp/arp_notify.c
+++ b/net/arp/arp_notify.c
@@ -156,7 +156,7 @@ int arp_wait(FAR struct arp_notify_s *notify, unsigned int 
timeout)
 
   /* And wait for the ARP response (or a timeout). */
 
-  net_sem_timedwait_uninterruptible(&notify->nt_sem, timeout);
+  nxsem_tickwait_uninterruptible(&notify->nt_sem, MSEC2TICK(timeout));
 
   /* Then get the real result of the transfer */
 
diff --git a/net/arp/arp_send.c b/net/arp/arp_send.c
index 17cf96d2218..2825a708ce5 100644
--- a/net/arp/arp_send.c
+++ b/net/arp/arp_send.c
@@ -374,15 +374,15 @@ int arp_send(in_addr_t ipaddr)
       netdev_txnotify_dev(dev, ARP_POLL);
 
       /* Wait for the send to complete or an error to occur.
-       * net_sem_wait will also terminate if a signal is received.
+       * nxsem_tickwait will also terminate if a signal is received.
        */
 
       netdev_unlock(dev);
 
       do
         {
-          ret = net_sem_timedwait_uninterruptible(&state.snd_sem,
-                                              CONFIG_ARP_SEND_DELAYMSEC);
+          ret = nxsem_tickwait(&state.snd_sem,
+                               MSEC2TICK(CONFIG_ARP_SEND_DELAYMSEC));
           if (ret == -ETIMEDOUT)
             {
               arp_wait_cancel(&notify);
diff --git a/net/bluetooth/bluetooth_recvmsg.c 
b/net/bluetooth/bluetooth_recvmsg.c
index 8ba4d22038e..48eac303e47 100644
--- a/net/bluetooth/bluetooth_recvmsg.c
+++ b/net/bluetooth/bluetooth_recvmsg.c
@@ -385,9 +385,10 @@ ssize_t bluetooth_recvmsg(FAR struct socket *psock, FAR 
struct msghdr *msg,
       state.ir_cb->event = bluetooth_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_sem_timedwait(&state.ir_sem, true, UINT_MAX,
diff --git a/net/bluetooth/bluetooth_sendmsg.c 
b/net/bluetooth/bluetooth_sendmsg.c
index 2ca5a5694fa..da4df8cc5b4 100644
--- a/net/bluetooth/bluetooth_sendmsg.c
+++ b/net/bluetooth/bluetooth_sendmsg.c
@@ -347,7 +347,8 @@ static ssize_t bluetooth_sendto(FAR struct socket *psock,
           netdev_txnotify_dev(&radio->r_dev, BLUETOOTH_POLL);
 
           /* Wait for the send to complete or an error to occur.
-           * net_sem_wait will also terminate if a signal is received.
+           * conn_dev_sem_timedwait will also terminate if a signal is
+           * received.
            */
 
           ret = conn_dev_sem_timedwait(&state.is_sem, true, UINT_MAX,
@@ -371,9 +372,9 @@ static ssize_t bluetooth_sendto(FAR struct socket *psock,
       return state.is_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)
diff --git a/net/can/can_recvmsg.c b/net/can/can_recvmsg.c
index 3d9f90eaac9..de6768cc75b 100644
--- a/net/can/can_recvmsg.c
+++ b/net/can/can_recvmsg.c
@@ -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 */
 
diff --git a/net/can/can_sendmsg.c b/net/can/can_sendmsg.c
index 846d8ecc2d3..1f3054618a7 100644
--- a/net/can/can_sendmsg.c
+++ b/net/can/can_sendmsg.c
@@ -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)
diff --git a/net/can/can_sendmsg_buffered.c b/net/can/can_sendmsg_buffered.c
index b5977c2a9ba..7b0df1ad873 100644
--- a/net/can/can_sendmsg_buffered.c
+++ b/net/can/can_sendmsg_buffered.c
@@ -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;
diff --git a/net/devif/devif_callback.c b/net/devif/devif_callback.c
index 01c49878a51..d9423ea16d1 100644
--- a/net/devif/devif_callback.c
+++ b/net/devif/devif_callback.c
@@ -256,11 +256,12 @@ devif_callback_alloc(FAR struct net_driver_s *dev,
    */
 
   /* Note: dev->d_flags may be asynchronously changed by netdev_ifdown()
-   * (in net/netdev/netdev_ioctl.c). Nevertheless, net_lock() / net_unlock()
-   * are not required in netdev_ifdown() to prevent dev->d_flags from
-   * asynchronous change here. There is not an issue because net_lock() and
-   * net_unlock() present inside of devif_dev_event(). That should be enough
-   * to de-allocate connection callbacks reliably on NETDEV_DOWN event.
+   * (in net/netdev/netdev_ioctl.c). Nevertheless, netdev_lock() /
+   * netdev_unlock() are not required in netdev_ifdown() to prevent
+   * dev->d_flags from asynchronous change here. There is not an issue
+   * because netdev_lock() and netdev_unlock() present inside of
+   * devif_dev_event(). That should be enough to de-allocate connection
+   * callbacks reliably on NETDEV_DOWN event.
    */
 
   if (dev && !netdev_verify(dev))
diff --git a/net/icmp/icmp_recvmsg.c b/net/icmp/icmp_recvmsg.c
index 83ca75e5a6e..0bff47c08ac 100644
--- a/net/icmp/icmp_recvmsg.c
+++ b/net/icmp/icmp_recvmsg.c
@@ -374,14 +374,13 @@ ssize_t icmp_recvmsg(FAR struct socket *psock, FAR struct 
msghdr *msg,
           state.recv_cb->event = recvfrom_eventhandler;
 
           /* Wait for either the response to be received or for timeout to
-           * occur. net_sem_timedwait will also terminate if a signal is
+           * occur. conn_dev_sem_timedwait will also terminate if a signal is
            * received.
            */
 
-          conn_dev_unlock(&conn->sconn, dev);
-          ret = net_sem_timedwait(&state.recv_sem,
-                              _SO_TIMEOUT(conn->sconn.s_rcvtimeo));
-          conn_dev_lock(&conn->sconn, dev);
+          ret = conn_dev_sem_timedwait(&state.recv_sem, true,
+                                       _SO_TIMEOUT(conn->sconn.s_rcvtimeo),
+                                       &conn->sconn, dev);
           if (ret < 0)
             {
               state.recv_result = ret;
diff --git a/net/icmp/icmp_sendmsg.c b/net/icmp/icmp_sendmsg.c
index 808db35ac96..0aaeacdf438 100644
--- a/net/icmp/icmp_sendmsg.c
+++ b/net/icmp/icmp_sendmsg.c
@@ -406,13 +406,12 @@ ssize_t icmp_sendmsg(FAR struct socket *psock, FAR struct 
msghdr *msg,
       netdev_txnotify_dev(dev, ICMP_POLL);
 
       /* Wait for either the send to complete or for timeout 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);
-      ret = net_sem_timedwait(&state.snd_sem,
-                          _SO_TIMEOUT(conn->sconn.s_sndtimeo));
-      conn_dev_lock(&conn->sconn, dev);
+      ret = conn_dev_sem_timedwait(&state.snd_sem, true,
+                                   _SO_TIMEOUT(conn->sconn.s_sndtimeo),
+                                   &conn->sconn, dev);
       if (ret < 0)
         {
           if (ret == -ETIMEDOUT)
diff --git a/net/icmpv6/icmpv6.h b/net/icmpv6/icmpv6.h
index 6f0c0e58226..6c3b6eb6763 100644
--- a/net/icmpv6/icmpv6.h
+++ b/net/icmpv6/icmpv6.h
@@ -417,9 +417,10 @@ int icmpv6_wait_cancel(FAR struct icmpv6_notify_s *notify);
  ****************************************************************************/
 
 #ifdef CONFIG_NET_ICMPv6_NEIGHBOR
-int icmpv6_wait(FAR struct icmpv6_notify_s *notify, unsigned int timeout);
+int icmpv6_wait(FAR struct net_driver_s *dev,
+                FAR struct icmpv6_notify_s *notify, unsigned int timeout);
 #else
-#  define icmpv6_wait(n,t) (0)
+#  define icmpv6_wait(d,n,t) (0)
 #endif
 
 /****************************************************************************
@@ -538,9 +539,10 @@ int icmpv6_rwait_cancel(FAR struct icmpv6_rnotify_s 
*notify);
  ****************************************************************************/
 
 #ifdef CONFIG_NET_ICMPv6_AUTOCONF
-int icmpv6_rwait(FAR struct icmpv6_rnotify_s *notify, unsigned int timeout);
+int icmpv6_rwait(FAR struct net_driver_s *dev,
+                 FAR struct icmpv6_rnotify_s *notify, unsigned int timeout);
 #else
-#  define icmpv6_rwait(n,t) (0)
+#  define icmpv6_rwait(d,n,t) (0)
 #endif
 
 /****************************************************************************
diff --git a/net/icmpv6/icmpv6_autoconfig.c b/net/icmpv6/icmpv6_autoconfig.c
index c8603b57802..1121807f01c 100644
--- a/net/icmpv6/icmpv6_autoconfig.c
+++ b/net/icmpv6/icmpv6_autoconfig.c
@@ -227,19 +227,15 @@ static int icmpv6_send_message(FAR struct net_driver_s 
*dev, bool advertise)
   netdev_txnotify_dev(dev, ICMPv6_POLL);
 
   /* Wait for the send to complete or an error to occur
-   * net_sem_wait will also terminate if a signal is received.
+   * nxsem_wait will also terminate if a signal is received.
    */
 
-  netdev_unlock(dev);
-
   do
     {
-      net_sem_wait(&state.snd_sem);
+      conn_dev_sem_timedwait(&state.snd_sem, true, UINT_MAX, NULL, dev);
     }
   while (!state.snd_sent);
 
-  netdev_lock(dev);
-
   ret = state.snd_result;
   devif_dev_callback_free(dev, state.snd_cb);
 
@@ -395,7 +391,7 @@ got_lladdr:
 
       /* Wait to receive the Router Advertisement message */
 
-      ret = icmpv6_rwait(&notify, CONFIG_ICMPv6_AUTOCONF_DELAYMSEC);
+      ret = icmpv6_rwait(dev, &notify, CONFIG_ICMPv6_AUTOCONF_DELAYMSEC);
       if (ret != -ETIMEDOUT)
         {
           /* ETIMEDOUT is the only expected failure.  We will retry on that
diff --git a/net/icmpv6/icmpv6_neighbor.c b/net/icmpv6/icmpv6_neighbor.c
index 0756ac1cbcf..13679ddc77c 100644
--- a/net/icmpv6/icmpv6_neighbor.c
+++ b/net/icmpv6/icmpv6_neighbor.c
@@ -44,6 +44,7 @@
 #include "inet/inet.h"
 #include "neighbor/neighbor.h"
 #include "route/route.h"
+#include "utils/utils.h"
 #include "icmpv6/icmpv6.h"
 
 #ifdef CONFIG_NET_ICMPv6_NEIGHBOR
@@ -339,14 +340,12 @@ int icmpv6_neighbor(FAR struct net_driver_s *dev,
       netdev_txnotify_dev(dev, ICMPv6_POLL);
 
       /* Wait for the send to complete or an error to occur.
-       * net_sem_wait will also terminate if a signal is received.
+       * nxsem_wait will also terminate if a signal is received.
        */
 
-      netdev_unlock(dev);
-
       do
         {
-          net_sem_wait(&state.snd_sem);
+          conn_dev_sem_timedwait(&state.snd_sem, true, UINT_MAX, NULL, dev);
         }
       while (!state.snd_sent);
 
@@ -354,9 +353,7 @@ int icmpv6_neighbor(FAR struct net_driver_s *dev,
        * received.
        */
 
-      ret = icmpv6_wait(&notify, CONFIG_ICMPv6_NEIGHBOR_DELAYMSEC);
-
-      netdev_lock(dev);
+      ret = icmpv6_wait(dev, &notify, CONFIG_ICMPv6_NEIGHBOR_DELAYMSEC);
 
       /* icmpv6_wait will return OK if and only if the matching Neighbor
        * Advertisement is received.  Otherwise, it will return -ETIMEDOUT.
diff --git a/net/icmpv6/icmpv6_notify.c b/net/icmpv6/icmpv6_notify.c
index 7361b4a30b5..3faf3dda94b 100644
--- a/net/icmpv6/icmpv6_notify.c
+++ b/net/icmpv6/icmpv6_notify.c
@@ -36,6 +36,7 @@
 #include <nuttx/spinlock.h>
 #include <nuttx/net/net.h>
 
+#include "utils/utils.h"
 #include "icmpv6/icmpv6.h"
 
 #ifdef CONFIG_NET_ICMPv6_NEIGHBOR
@@ -165,13 +166,14 @@ int icmpv6_wait_cancel(FAR struct icmpv6_notify_s *notify)
  *
  ****************************************************************************/
 
-int icmpv6_wait(FAR struct icmpv6_notify_s *notify, unsigned int timeout)
+int icmpv6_wait(FAR struct net_driver_s *dev,
+                FAR struct icmpv6_notify_s *notify, unsigned int timeout)
 {
   int ret;
 
   /* And wait for the Neighbor Advertisement (or a timeout). */
 
-  ret = net_sem_timedwait(&notify->nt_sem, timeout);
+  ret = conn_dev_sem_timedwait(&notify->nt_sem, true, timeout, NULL, dev);
   if (ret >= 0)
     {
       ret = notify->nt_result;
diff --git a/net/icmpv6/icmpv6_recvmsg.c b/net/icmpv6/icmpv6_recvmsg.c
index ff5a20ad390..e86e93ecc13 100644
--- a/net/icmpv6/icmpv6_recvmsg.c
+++ b/net/icmpv6/icmpv6_recvmsg.c
@@ -384,14 +384,15 @@ ssize_t icmpv6_recvmsg(FAR struct socket *psock, FAR 
struct msghdr *msg,
           state.recv_cb->event = recvfrom_eventhandler;
 
           /* Wait for either the response to be received or for timeout to
-           * occur. (1) net_sem_timedwait will also terminate if a signal is
-           * received, (2) interrupts may be disabled!  They will be
-           * re-enabled while the task sleeps and automatically re-enabled
+           * occur. (1) conn_dev_sem_timedwait will also terminate if a
+           * signal is received, (2) interrupts may be disabled!  They will
+           * be re-enabled while the task sleeps and automatically re-enabled
            * when the task restarts.
            */
 
-          ret = net_sem_timedwait(&state.recv_sem,
-                              _SO_TIMEOUT(conn->sconn.s_rcvtimeo));
+          ret = conn_dev_sem_timedwait(&state.recv_sem, true,
+                                       _SO_TIMEOUT(conn->sconn.s_rcvtimeo),
+                                       &conn->sconn, dev);
           if (ret < 0)
             {
               state.recv_result = ret;
diff --git a/net/icmpv6/icmpv6_rnotify.c b/net/icmpv6/icmpv6_rnotify.c
index 2b8751c1060..424cb893f48 100644
--- a/net/icmpv6/icmpv6_rnotify.c
+++ b/net/icmpv6/icmpv6_rnotify.c
@@ -258,7 +258,8 @@ int icmpv6_rwait_cancel(FAR struct icmpv6_rnotify_s *notify)
  *
  ****************************************************************************/
 
-int icmpv6_rwait(FAR struct icmpv6_rnotify_s *notify, unsigned int timeout)
+int icmpv6_rwait(FAR struct net_driver_s *dev,
+                 FAR struct icmpv6_rnotify_s *notify, unsigned int timeout)
 {
   int ret;
 
@@ -266,7 +267,7 @@ int icmpv6_rwait(FAR struct icmpv6_rnotify_s *notify, 
unsigned int timeout)
 
   /* And wait for the Neighbor Advertisement (or a timeout). */
 
-  ret = net_sem_timedwait(&notify->rn_sem, timeout);
+  ret = conn_dev_sem_timedwait(&notify->rn_sem, true, timeout, NULL, dev);
   if (ret >= 0)
     {
       ret = notify->rn_result;
diff --git a/net/icmpv6/icmpv6_sendmsg.c b/net/icmpv6/icmpv6_sendmsg.c
index 03a3b3e83c9..60e678f220f 100644
--- a/net/icmpv6/icmpv6_sendmsg.c
+++ b/net/icmpv6/icmpv6_sendmsg.c
@@ -402,13 +402,12 @@ ssize_t icmpv6_sendmsg(FAR struct socket *psock, FAR 
struct msghdr *msg,
       netdev_txnotify_dev(dev, ICMPv6_POLL);
 
       /* Wait for either the send to complete or for timeout 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);
-      ret = net_sem_timedwait(&state.snd_sem,
-                          _SO_TIMEOUT(conn->sconn.s_sndtimeo));
-      conn_dev_lock(&conn->sconn, dev);
+      ret = conn_dev_sem_timedwait(&state.snd_sem, true,
+                                   _SO_TIMEOUT(conn->sconn.s_sndtimeo),
+                                   &conn->sconn, dev);
       if (ret < 0)
         {
           if (ret == -ETIMEDOUT)
diff --git a/net/ieee802154/ieee802154_recvmsg.c 
b/net/ieee802154/ieee802154_recvmsg.c
index e33f35092dc..53b0cecb887 100644
--- a/net/ieee802154/ieee802154_recvmsg.c
+++ b/net/ieee802154/ieee802154_recvmsg.c
@@ -385,9 +385,10 @@ ssize_t ieee802154_recvmsg(FAR struct socket *psock, FAR 
struct msghdr *msg,
       state.ir_cb->event  = ieee802154_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_sem_timedwait(&state.ir_sem, true, UINT_MAX,
diff --git a/net/ieee802154/ieee802154_sendmsg.c 
b/net/ieee802154/ieee802154_sendmsg.c
index b166e64dbbd..7da627aea14 100644
--- a/net/ieee802154/ieee802154_sendmsg.c
+++ b/net/ieee802154/ieee802154_sendmsg.c
@@ -501,7 +501,8 @@ static ssize_t ieee802154_sendto(FAR struct socket *psock,
           netdev_txnotify_dev(&radio->r_dev, IEEE802154_POLL);
 
           /* Wait for the send to complete or an error to occur.
-           * net_sem_wait will also terminate if a signal is received.
+           * conn_dev_sem_timedwait will also terminate if a signal is
+           * received.
            */
 
           ret = conn_dev_sem_timedwait(&state.is_sem, true, UINT_MAX,
@@ -525,9 +526,9 @@ static ssize_t ieee802154_sendto(FAR struct socket *psock,
       return state.is_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)
diff --git a/net/igmp/igmp_msg.c b/net/igmp/igmp_msg.c
index 7d57033e527..d6a138b415a 100644
--- a/net/igmp/igmp_msg.c
+++ b/net/igmp/igmp_msg.c
@@ -145,7 +145,7 @@ int igmp_waitmsg(FAR struct igmp_group_s *group, uint8_t 
msgid)
     {
       /* Wait for the semaphore to be posted */
 
-      ret = net_sem_wait_uninterruptible(&group->sem);
+      ret = nxsem_wait_uninterruptible(&group->sem);
       if (ret < 0)
         {
           break;
diff --git a/net/ipfrag/ipfrag.c b/net/ipfrag/ipfrag.c
index efc1f58989b..621f78f884d 100644
--- a/net/ipfrag/ipfrag.c
+++ b/net/ipfrag/ipfrag.c
@@ -232,7 +232,7 @@ static void ip_fragin_timerwork(FAR void *arg)
             {
               FAR struct net_driver_s *dev = node->dev;
 
-              net_lock();
+              netdev_lock(dev);
 
               netdev_iob_replace(dev, node->frags->frag);
               node->frags->frag = NULL;
@@ -266,7 +266,7 @@ static void ip_fragin_timerwork(FAR void *arg)
                   netdev_txnotify_dev(dev, IPFRAG_POLL);
                 }
 
-              net_unlock();
+              netdev_unlock(dev);
             }
 #endif
 
diff --git a/net/mld/mld_msg.c b/net/mld/mld_msg.c
index 4cb6a6b1d4a..13b94451798 100644
--- a/net/mld/mld_msg.c
+++ b/net/mld/mld_msg.c
@@ -120,7 +120,7 @@ int mld_waitmsg(FAR struct mld_group_s *group, uint8_t 
msgtype)
     {
       /* Wait for the semaphore to be posted */
 
-      ret = net_sem_wait_uninterruptible(&group->sem);
+      ret = nxsem_wait_uninterruptible(&group->sem);
       if (ret < 0)
         {
           break;
diff --git a/net/netlink/netlink_conn.c b/net/netlink/netlink_conn.c
index 9295297ee1d..22b6f45f973 100644
--- a/net/netlink/netlink_conn.c
+++ b/net/netlink/netlink_conn.c
@@ -475,14 +475,11 @@ int netlink_get_response(FAR struct netlink_conn_s *conn,
         }
       else
         {
-          unsigned int count;
-
           /* Wait for a response to be queued */
 
           tls_cleanup_push(tls_get_info(), netlink_notifier_teardown, conn);
-          nxrmutex_breaklock(&g_netlink_lock, &count);
-          ret = net_sem_wait(&waitsem);
-          nxrmutex_restorelock(&g_netlink_lock, count);
+          ret = net_sem_timedwait2(&waitsem, true, UINT_MAX, &g_netlink_lock,
+                                   NULL);
           tls_cleanup_pop(tls_get_info(), 0);
         }
 
diff --git a/net/pkt/pkt_recvmsg.c b/net/pkt/pkt_recvmsg.c
index cd30728b1ea..57cf3471de1 100644
--- a/net/pkt/pkt_recvmsg.c
+++ b/net/pkt/pkt_recvmsg.c
@@ -312,7 +312,8 @@ static void pkt_recvfrom_initialize(FAR struct pkt_conn_s 
*conn,
  *   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:
@@ -338,9 +339,9 @@ static ssize_t pkt_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)
@@ -559,15 +560,14 @@ ssize_t pkt_recvmsg(FAR struct socket *psock, FAR struct 
msghdr *msg,
           state.pr_cb->event  = pkt_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
+           * to 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 */
 
diff --git a/net/pkt/pkt_sendmsg_buffered.c b/net/pkt/pkt_sendmsg_buffered.c
index 2ebbdc01507..e511a0a11c2 100644
--- a/net/pkt/pkt_sendmsg_buffered.c
+++ b/net/pkt/pkt_sendmsg_buffered.c
@@ -254,8 +254,9 @@ ssize_t pkt_sendmsg(FAR struct socket *psock, FAR const 
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;
diff --git a/net/pkt/pkt_sendmsg_unbuffered.c b/net/pkt/pkt_sendmsg_unbuffered.c
index db954e0d746..039a4a99410 100644
--- a/net/pkt/pkt_sendmsg_unbuffered.c
+++ b/net/pkt/pkt_sendmsg_unbuffered.c
@@ -242,12 +242,12 @@ ssize_t pkt_sendmsg(FAR struct socket *psock, FAR struct 
msghdr *msg,
           netdev_txnotify_dev(dev, PKT_POLL);
 
           /* Wait for the send to complete or an error to occur.
-           * net_sem_wait 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);
-          ret = net_sem_wait(&state.snd_sem);
-          conn_dev_lock(&conn->sconn, dev);
+          ret = conn_dev_sem_timedwait(&state.snd_sem, true, UINT_MAX,
+                                       &conn->sconn, dev);
 
           /* Make sure that no further events are processed */
 
@@ -267,9 +267,9 @@ ssize_t pkt_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)
diff --git a/net/pkt/pkt_sockif.c b/net/pkt/pkt_sockif.c
index e880141a1db..02c6fb505bb 100644
--- a/net/pkt/pkt_sockif.c
+++ b/net/pkt/pkt_sockif.c
@@ -377,10 +377,9 @@ static int pkt_close(FAR struct socket *psock)
 
                   while (iob_get_queue_entry_count(&conn->write_q) != 0)
                     {
-                      conn_dev_unlock(&conn->sconn, dev);
-                      ret = net_sem_timedwait_uninterruptible(&conn->sndsem,
-                            _SO_TIMEOUT(conn->sconn.s_sndtimeo));
-                      conn_dev_lock(&conn->sconn, dev);
+                      ret = conn_dev_sem_timedwait(&conn->sndsem, false,
+                                         _SO_TIMEOUT(conn->sconn.s_sndtimeo),
+                                         &conn->sconn, dev);
                       if (ret < 0)
                         {
                           break;
diff --git a/net/sixlowpan/sixlowpan_internal.h 
b/net/sixlowpan/sixlowpan_internal.h
index 5c169b23204..dd053bf1a4a 100644
--- a/net/sixlowpan/sixlowpan_internal.h
+++ b/net/sixlowpan/sixlowpan_internal.h
@@ -250,6 +250,7 @@ struct devif_callback_s;    /* Forward reference */
 struct ipv6_hdr_s;          /* Forward reference */
 struct netdev_varaddr_s;    /* Forward reference */
 struct iob_s;               /* Forward reference */
+struct udp_conn_s;          /* Forward reference */
 
 /****************************************************************************
  * Name: sixlowpan_send
@@ -284,12 +285,9 @@ struct iob_s;               /* Forward reference */
  *
  ****************************************************************************/
 
-int sixlowpan_send(FAR struct net_driver_s *dev,
-                   FAR struct devif_callback_s **list,
-                   FAR struct devif_callback_s **list_tail,
+int sixlowpan_send(FAR struct net_driver_s *dev, FAR struct udp_conn_s *conn,
                    FAR const struct ipv6_hdr_s *ipv6hdr, FAR const void *buf,
-                   size_t len, FAR const struct netdev_varaddr_s *destmac,
-                   unsigned int timeout);
+                   size_t len, FAR const struct netdev_varaddr_s *destmac);
 
 /****************************************************************************
  * Name: sixlowpan_meta_data
diff --git a/net/sixlowpan/sixlowpan_send.c b/net/sixlowpan/sixlowpan_send.c
index 0f9e3a2b4c0..0c50a92b907 100644
--- a/net/sixlowpan/sixlowpan_send.c
+++ b/net/sixlowpan/sixlowpan_send.c
@@ -36,6 +36,9 @@
 
 #include "netdev/netdev.h"
 #include "devif/devif.h"
+#include "udp/udp.h"
+#include "utils/utils.h"
+#include "socket/socket.h"
 
 #include "sixlowpan/sixlowpan_internal.h"
 
@@ -202,16 +205,14 @@ end_wait:
  *
  ****************************************************************************/
 
-int sixlowpan_send(FAR struct net_driver_s *dev,
-                   FAR struct devif_callback_s **list,
-                   FAR struct devif_callback_s **list_tail,
+int sixlowpan_send(FAR struct net_driver_s *dev, FAR struct udp_conn_s *conn,
                    FAR const struct ipv6_hdr_s *ipv6hdr, FAR const void *buf,
-                   size_t len, FAR const struct netdev_varaddr_s *destmac,
-                   unsigned int timeout)
+                   size_t len, FAR const struct netdev_varaddr_s *destmac)
 {
   struct sixlowpan_send_s sinfo;
 
-  ninfo("len=%lu timeout=%u\n", (unsigned long)len, timeout);
+  ninfo("len=%lu timeout=%u\n", (unsigned long)len,
+        (unsigned int)_SO_TIMEOUT(conn->sconn.s_sndtimeo));
 
   /* Initialize the send state structure */
 
@@ -223,7 +224,7 @@ int sixlowpan_send(FAR struct net_driver_s *dev,
   sinfo.s_buf     = buf;
   sinfo.s_len     = len;
 
-  net_lock();
+  conn_dev_lock(&conn->sconn, dev);
   if (len > 0)
     {
       /* Allocate resources to receive a callback.
@@ -232,7 +233,8 @@ int sixlowpan_send(FAR struct net_driver_s *dev,
        * device related events, no connect-related events.
        */
 
-      sinfo.s_cb = devif_callback_alloc(dev, list, list_tail);
+      sinfo.s_cb = devif_callback_alloc(dev, &conn->sconn.list,
+                                        &conn->sconn.list_tail);
       if (sinfo.s_cb != NULL)
         {
           int ret;
@@ -248,12 +250,15 @@ int sixlowpan_send(FAR struct net_driver_s *dev,
           netdev_txnotify_dev(dev, UDP_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.
            */
 
           ninfo("Wait for send complete\n");
 
-          ret = net_sem_timedwait(&sinfo.s_waitsem, timeout);
+          ret = conn_dev_sem_timedwait(&sinfo.s_waitsem, true,
+                                       _SO_TIMEOUT(conn->sconn.s_sndtimeo),
+                                       &conn->sconn, dev);
           if (ret < 0)
             {
               if (ret == -ETIMEDOUT)
@@ -267,12 +272,13 @@ int sixlowpan_send(FAR struct net_driver_s *dev,
 
           /* Make sure that no further events are processed */
 
-          devif_conn_callback_free(dev, sinfo.s_cb, list, list_tail);
+          devif_conn_callback_free(dev, sinfo.s_cb, &conn->sconn.list,
+                                   &conn->sconn.list_tail);
         }
     }
 
   nxsem_destroy(&sinfo.s_waitsem);
-  net_unlock();
+  conn_dev_unlock(&conn->sconn, dev);
 
   return (sinfo.s_result < 0 ? sinfo.s_result : len);
 }
diff --git a/net/sixlowpan/sixlowpan_tcpsend.c 
b/net/sixlowpan/sixlowpan_tcpsend.c
index 043a239b6eb..6e8151cf150 100644
--- a/net/sixlowpan/sixlowpan_tcpsend.c
+++ b/net/sixlowpan/sixlowpan_tcpsend.c
@@ -597,7 +597,7 @@ static int sixlowpan_send_packet(FAR struct socket *psock,
 
   memset(&sinfo, 0, sizeof(struct sixlowpan_send_s));
 
-  net_lock();
+  conn_dev_lock(&conn->sconn, dev);
   if (len > 0)
     {
       /* Allocate resources to receive a callback.
@@ -643,7 +643,8 @@ static int sixlowpan_send_packet(FAR struct socket *psock,
           netdev_txnotify_dev(dev, TCP_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.
            */
 
           ninfo("Wait for send complete\n");
@@ -652,7 +653,8 @@ static int sixlowpan_send_packet(FAR struct socket *psock,
             {
               uint32_t acked = sinfo.s_acked;
 
-              ret = net_sem_timedwait(&sinfo.s_waitsem, timeout);
+              ret = conn_dev_sem_timedwait(&sinfo.s_waitsem, true, timeout,
+                                           &conn->sconn, dev);
               if (ret != -ETIMEDOUT || acked == sinfo.s_acked)
                 {
                   if (ret == -ETIMEDOUT)
@@ -676,7 +678,7 @@ static int sixlowpan_send_packet(FAR struct socket *psock,
     }
 
   nxsem_destroy(&sinfo.s_waitsem);
-  net_unlock();
+  conn_dev_unlock(&conn->sconn, dev);
 
   return (sinfo.s_result < 0 ? sinfo.s_result : len);
 }
diff --git a/net/sixlowpan/sixlowpan_udpsend.c 
b/net/sixlowpan/sixlowpan_udpsend.c
index 70ae8c5400d..077f19b9683 100644
--- a/net/sixlowpan/sixlowpan_udpsend.c
+++ b/net/sixlowpan/sixlowpan_udpsend.c
@@ -295,12 +295,8 @@ ssize_t psock_6lowpan_udp_sendto(FAR struct socket *psock,
    * packet.
    */
 
-  ret = sixlowpan_send(dev,
-                       &conn->sconn.list,
-                       &conn->sconn.list_tail,
-                       (FAR const struct ipv6_hdr_s *)&ipv6udp,
-                       buf, buflen, &destmac,
-                       _SO_TIMEOUT(conn->sconn.s_sndtimeo));
+  ret = sixlowpan_send(dev, conn, (FAR const struct ipv6_hdr_s *)&ipv6udp,
+                       buf, buflen, &destmac);
   if (ret < 0)
     {
       nerr("ERROR: sixlowpan_send() failed: %d\n", ret);
diff --git a/net/tcp/tcp_accept.c b/net/tcp/tcp_accept.c
index a2fb6135b35..38e31ec0106 100644
--- a/net/tcp/tcp_accept.c
+++ b/net/tcp/tcp_accept.c
@@ -272,12 +272,11 @@ int psock_tcp_accept(FAR struct socket *psock, FAR struct 
sockaddr *addr,
       conn->accept          = accept_eventhandler;
 
       /* Wait for the send to complete or an error to occur:  NOTES:
-       * net_sem_wait will also terminate if a signal is received.
+       * conn_dev_sem_timedwait will also terminate if a signal is received.
        */
 
-      conn_unlock(&conn->sconn);
-      ret = net_sem_wait(&state.acpt_sem);
-      conn_lock(&conn->sconn);
+      ret = conn_dev_sem_timedwait(&state.acpt_sem, true, UINT_MAX,
+                                   &conn->sconn, NULL);
 
       /* Make sure that no further events are processed */
 
@@ -296,9 +295,9 @@ int psock_tcp_accept(FAR struct socket *psock, FAR struct 
sockaddr *addr,
           ret = -state.acpt_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 (ret < 0)
diff --git a/net/tcp/tcp_connect.c b/net/tcp/tcp_connect.c
index abc2e12711e..f3858c69990 100644
--- a/net/tcp/tcp_connect.c
+++ b/net/tcp/tcp_connect.c
@@ -383,22 +383,23 @@ int psock_tcp_connect(FAR struct socket *psock,
 
               /* Wait for either the connect to complete or for an
                * error/timeout to occur.
-               * NOTES:  net_sem_wait will also terminate if a
+               * NOTES:  conn_dev_sem_timedwait will also terminate if a
                * signal is received.
                */
 
-              conn_dev_unlock(&conn->sconn, conn->dev);
               tls_cleanup_push(tls_get_info(), tcp_callback_cleanup, &info);
-              ret = net_sem_wait(&state.tc_sem);
+              ret = conn_dev_sem_timedwait(&state.tc_sem, true, UINT_MAX,
+                                           &conn->sconn, conn->dev);
 
               tls_cleanup_pop(tls_get_info(), 0);
-              conn_dev_lock(&conn->sconn, conn->dev);
 
               /* Uninitialize the state structure */
 
               nxsem_destroy(&state.tc_sem);
 
-              /* If net_sem_wait failed, negated errno was returned. */
+              /* If conn_dev_sem_timedwait failed, negated errno was
+               * returned.
+               */
 
               if (ret >= 0)
                 {
diff --git a/net/tcp/tcp_recvfrom.c b/net/tcp/tcp_recvfrom.c
index 736fc12c131..bfa3b03847f 100644
--- a/net/tcp/tcp_recvfrom.c
+++ b/net/tcp/tcp_recvfrom.c
@@ -576,7 +576,7 @@ static void tcp_recvfrom_initialize(FAR struct tcp_conn_s 
*conn,
  *   Evaluate the result of the recv operations
  *
  * Input Parameters:
- *   result   The result of the net_sem_timedwait operation
+ *   result   The result of the conn_dev_sem_timedwait operation
  *            (may indicate EINTR)
  *   pstate   A pointer to the state structure to be initialized
  *
@@ -801,18 +801,17 @@ static ssize_t tcp_recvfrom_one(FAR struct tcp_conn_s 
*conn, FAR void *buf,
           info.tc_conn = conn;
           info.tc_cb   = &state.ir_cb;
           info.tc_sem  = &state.ir_sem;
-          conn_dev_unlock(&conn->sconn, conn->dev);
           tls_cleanup_push(tls_get_info(), tcp_callback_cleanup, &info);
 
           /* Wait for either the receive to complete or for an
-           * error/timeout to occur.  net_sem_timedwait will also
+           * error/timeout to occur.  conn_dev_sem_timedwait will also
            * terminate if a signal is received.
            */
 
-          ret = net_sem_timedwait(&state.ir_sem,
-                              _SO_TIMEOUT(conn->sconn.s_rcvtimeo));
+          ret = conn_dev_sem_timedwait(&state.ir_sem, true,
+                                       _SO_TIMEOUT(conn->sconn.s_rcvtimeo),
+                                       &conn->sconn, conn->dev);
           tls_cleanup_pop(tls_get_info(), 0);
-          conn_dev_lock(&conn->sconn, conn->dev);
           if (ret == -ETIMEDOUT)
             {
               ret = -EAGAIN;
@@ -837,11 +836,7 @@ static ssize_t tcp_recvfrom_one(FAR struct tcp_conn_s 
*conn, FAR void *buf,
 
   if (tcp_should_send_recvwindow(conn))
     {
-      conn_unlock(&conn->sconn);
-      netdev_lock(conn->dev);
       netdev_txnotify_dev(conn->dev, TCP_POLL);
-      netdev_unlock(conn->dev);
-      conn_lock(&conn->sconn);
     }
 
   tcp_notify_recvcpu(conn);
diff --git a/net/tcp/tcp_send_buffered.c b/net/tcp/tcp_send_buffered.c
index 5ab17b54c91..35b510e77db 100644
--- a/net/tcp/tcp_send_buffered.c
+++ b/net/tcp/tcp_send_buffered.c
@@ -1475,13 +1475,12 @@ ssize_t psock_tcp_send(FAR struct socket *psock, FAR 
const void *buf,
           info.tc_conn = conn;
           info.tc_cb   = &conn->sndcb;
           info.tc_sem  = &conn->snd_sem;
-          conn_dev_unlock(&conn->sconn, conn->dev);
           tls_cleanup_push(tls_get_info(), tcp_callback_cleanup, &info);
 
-          ret = net_sem_timedwait_uninterruptible(&conn->snd_sem,
-            tcp_send_gettimeout(start, timeout));
+          ret = conn_dev_sem_timedwait(&conn->snd_sem, false,
+                                       tcp_send_gettimeout(start, timeout),
+                                       &conn->sconn, conn->dev);
           tls_cleanup_pop(tls_get_info(), 0);
-          conn_dev_lock(&conn->sconn, conn->dev);
           if (ret < 0)
             {
               if (ret == -ETIMEDOUT)
diff --git a/net/tcp/tcp_send_unbuffered.c b/net/tcp/tcp_send_unbuffered.c
index 77a62ef30ad..d7217f24573 100644
--- a/net/tcp/tcp_send_unbuffered.c
+++ b/net/tcp/tcp_send_unbuffered.c
@@ -607,7 +607,8 @@ ssize_t psock_tcp_send(FAR struct socket *psock,
           tcp_send_txnotify(psock, conn);
 
           /* Wait for the send to complete or an error to occur:  NOTES:
-           * net_sem_wait will also terminate if a signal is received.
+           * conn_dev_sem_timedwait will also terminate if a signal is
+           * received.
            */
 
           for (; ; )
@@ -621,13 +622,12 @@ ssize_t psock_tcp_send(FAR struct socket *psock,
               info.tc_conn = conn;
               info.tc_cb   = &state.snd_cb;
               info.tc_sem  = &state.snd_sem;
-              conn_dev_unlock(&conn->sconn, conn->dev);
               tls_cleanup_push(tls_get_info(), tcp_callback_cleanup, &info);
 
-              ret = net_sem_timedwait(&state.snd_sem,
-                                  _SO_TIMEOUT(conn->sconn.s_sndtimeo));
+              ret = conn_dev_sem_timedwait(&state.snd_sem, true,
+                                         _SO_TIMEOUT(conn->sconn.s_sndtimeo),
+                                         &conn->sconn, conn->dev);
               tls_cleanup_pop(tls_get_info(), 0);
-              conn_dev_lock(&conn->sconn, conn->dev);
               if (ret != -ETIMEDOUT || acked == state.snd_acked)
                 {
                   if (ret == -ETIMEDOUT)
@@ -658,8 +658,8 @@ ssize_t psock_tcp_send(FAR struct socket *psock,
       goto errout;
     }
 
-  /* If net_sem_timedwait failed, then we were probably reawakened by a
-   * signal. In this case, net_sem_timedwait will have returned negated
+  /* 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.
    */
 
diff --git a/net/tcp/tcp_sendfile.c b/net/tcp/tcp_sendfile.c
index 0aabc9c88d1..455e92eb6be 100644
--- a/net/tcp/tcp_sendfile.c
+++ b/net/tcp/tcp_sendfile.c
@@ -525,8 +525,9 @@ ssize_t tcp_sendfile(FAR struct socket *psock, FAR struct 
file *infile,
     {
       uint32_t acked = state.snd_acked;
 
-      ret = net_sem_timedwait_uninterruptible(
-              &state.snd_sem, _SO_TIMEOUT(conn->sconn.s_sndtimeo));
+      ret = conn_dev_sem_timedwait(&state.snd_sem, false,
+                                   _SO_TIMEOUT(conn->sconn.s_sndtimeo),
+                                   &conn->sconn, conn->dev);
       if (ret != -ETIMEDOUT || acked == state.snd_acked)
         {
           if (ret == -ETIMEDOUT)
diff --git a/net/tcp/tcp_txdrain.c b/net/tcp/tcp_txdrain.c
index 2ae4760d876..95a1f375db6 100644
--- a/net/tcp/tcp_txdrain.c
+++ b/net/tcp/tcp_txdrain.c
@@ -145,9 +145,8 @@ int tcp_txdrain(FAR struct socket *psock, unsigned int 
timeout)
            * wait for it to drain or be be disconnected.
            */
 
-          conn_dev_unlock(&conn->sconn, conn->dev);
-          ret = net_sem_timedwait_uninterruptible(&waitsem, timeout);
-          conn_dev_lock(&conn->sconn, conn->dev);
+          ret = conn_dev_sem_timedwait(&waitsem, false, timeout,
+                                       &conn->sconn, conn->dev);
 
           /* Tear down the disconnect notifier */
 
diff --git a/net/udp/udp_recvfrom.c b/net/udp/udp_recvfrom.c
index 38fbfda7829..fabfc2f6cfc 100644
--- a/net/udp/udp_recvfrom.c
+++ b/net/udp/udp_recvfrom.c
@@ -562,7 +562,7 @@ static void udp_recvfrom_initialize(FAR struct udp_conn_s 
*conn,
  *   Evaluate the result of the recv operations
  *
  * Input Parameters:
- *   result   The result of the net_sem_timedwait operation
+ *   result   The result of the conn_dev_sem_timedwait operation
  *            (may indicate EINTR)
  *   pstate   A pointer to the state structure to be initialized
  *
@@ -588,8 +588,8 @@ static ssize_t udp_recvfrom_result(int result, struct 
udp_recvfrom_s *pstate)
       return pstate->ir_result;
     }
 
-  /* If net_sem_timedwait failed, then we were probably reawakened by a
-   * signal. In this case, net_sem_timedwait will have returned negated
+  /* 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.
    */
 
@@ -765,14 +765,13 @@ ssize_t psock_udp_recvfrom(FAR struct socket *psock, FAR 
struct msghdr *msg,
           tls_cleanup_push(tls_get_info(), udp_callback_cleanup, &info);
 
           /* Wait for either the receive to complete or for an error/timeout
-           * to occur.  net_sem_timedwait will also terminate if a signal is
-           * received.
+           * to occur.  conn_dev_sem_timedwait will also terminate if a
+           * signal is received.
            */
 
-          conn_dev_unlock(&conn->sconn, dev);
-          ret = net_sem_timedwait(&state.ir_sem,
-                              _SO_TIMEOUT(conn->sconn.s_rcvtimeo));
-          conn_dev_lock(&conn->sconn, dev);
+          ret = conn_dev_sem_timedwait(&state.ir_sem, true,
+                                       _SO_TIMEOUT(conn->sconn.s_rcvtimeo),
+                                       &conn->sconn, dev);
           tls_cleanup_pop(tls_get_info(), 0);
           if (ret == -ETIMEDOUT)
             {
diff --git a/net/udp/udp_sendto_buffered.c b/net/udp/udp_sendto_buffered.c
index 683879577e6..d78dd2bf041 100644
--- a/net/udp/udp_sendto_buffered.c
+++ b/net/udp/udp_sendto_buffered.c
@@ -717,14 +717,15 @@ ssize_t psock_udp_sendto(FAR struct socket *psock, FAR 
const void *buf,
   conn_lock(&conn->sconn);
   while (udp_wrbuffer_inqueue_size(conn) + len > conn->sndbufs)
     {
-      conn_unlock(&conn->sconn);
       if (nonblock)
         {
+          conn_unlock(&conn->sconn);
           return -EAGAIN;
         }
 
-      ret = net_sem_timedwait_uninterruptible(&conn->sndsem,
-                            udp_send_gettimeout(start, timeout));
+      ret = conn_dev_sem_timedwait(&conn->sndsem, false,
+                                   udp_send_gettimeout(start, timeout),
+                                   &conn->sconn, NULL);
       if (ret < 0)
         {
           if (ret == -ETIMEDOUT)
@@ -732,10 +733,9 @@ ssize_t psock_udp_sendto(FAR struct socket *psock, FAR 
const void *buf,
               ret = -EAGAIN;
             }
 
+          conn_unlock(&conn->sconn);
           return ret;
         }
-
-      conn_lock(&conn->sconn);
     }
 
   conn_unlock(&conn->sconn);
diff --git a/net/udp/udp_sendto_unbuffered.c b/net/udp/udp_sendto_unbuffered.c
index 5eecb9f7402..cb95624062a 100644
--- a/net/udp/udp_sendto_unbuffered.c
+++ b/net/udp/udp_sendto_unbuffered.c
@@ -480,13 +480,13 @@ ssize_t psock_udp_sendto(FAR struct socket *psock, FAR 
const void *buf,
       netdev_txnotify_dev(state.st_dev, UDP_POLL);
 
       /* Wait for either the receive to complete or for an error/timeout to
-       * occur. NOTES:  net_sem_timedwait will also terminate if a signal
+       * occur. NOTES: conn_dev_sem_timedwait will also terminate if a signal
        * is received.
        */
 
-      conn_dev_unlock(&conn->sconn, state.st_dev);
-      ret = net_sem_timedwait(&state.st_sem,
-                          _SO_TIMEOUT(conn->sconn.s_sndtimeo));
+      ret = conn_dev_sem_timedwait(&state.st_sem, true,
+                                   _SO_TIMEOUT(conn->sconn.s_sndtimeo),
+                                   &conn->sconn, state.st_dev);
       if (ret >= 0)
         {
           /* The result of the sendto operation is the number of bytes
@@ -496,8 +496,6 @@ ssize_t psock_udp_sendto(FAR struct socket *psock, FAR 
const void *buf,
           ret = state.st_sndlen;
         }
 
-      conn_dev_lock(&conn->sconn, state.st_dev);
-
       /* Make sure that no further events are processed */
 
       udp_callback_free(state.st_dev, conn, state.st_cb);
diff --git a/net/udp/udp_txdrain.c b/net/udp/udp_txdrain.c
index f5013eaa64a..3c344a2bf56 100644
--- a/net/udp/udp_txdrain.c
+++ b/net/udp/udp_txdrain.c
@@ -85,9 +85,8 @@ int udp_txdrain(FAR struct socket *psock, unsigned int 
timeout)
   if (!sq_empty(&conn->write_q))
     {
       conn->txdrain_sem = &waitsem;
-      conn_unlock(&conn->sconn);
-      ret = net_sem_timedwait_uninterruptible(&waitsem, timeout);
-      conn_lock(&conn->sconn);
+      ret = conn_dev_sem_timedwait(&waitsem, false, timeout,
+                                   &conn->sconn, NULL);
       conn->txdrain_sem = NULL;
     }
 

Reply via email to