diff --git a/arch/sim/src/sim/sim_cansock.c b/arch/sim/src/sim/sim_cansock.c index b9c8d0f713933..d602c97f31c88 100644 --- a/arch/sim/src/sim/sim_cansock.c +++ b/arch/sim/src/sim/sim_cansock.c @@ -134,13 +134,13 @@ static int sim_can_txavail(struct net_driver_s *dev) /* Ignore the notification if the interface is not yet up */ - net_lock(); + netdev_lock(dev); if (IFF_IS_UP(priv->dev.d_flags)) { devif_poll(&priv->dev, sim_can_txpoll); } - net_unlock(); + netdev_unlock(dev); return OK; } @@ -189,7 +189,7 @@ static void sim_can_work(void *arg) * in priv->dev.d_len */ - net_lock(); + netdev_lock(&priv->dev); priv->dev.d_len = ret; priv->dev.d_buf = (FAR uint8_t *)&hframe; @@ -198,7 +198,7 @@ static void sim_can_work(void *arg) NETDEV_RXPACKETS(&priv->dev); can_input(&priv->dev); - net_unlock(); + netdev_unlock(&priv->dev); } nodata: diff --git a/drivers/net/enc28j60.c b/drivers/net/enc28j60.c index becda0e1cef56..ca5cafd93eced 100644 --- a/drivers/net/enc28j60.c +++ b/drivers/net/enc28j60.c @@ -1545,7 +1545,7 @@ static void enc_irqworker(FAR void *arg) /* Get exclusive access to both the network and the SPI bus. */ - net_lock(); + netdev_lock(&priv->dev); enc_lock(priv); /* Disable further interrupts by clearing the global interrupt enable bit. @@ -1739,7 +1739,7 @@ static void enc_irqworker(FAR void *arg) /* Release lock on the SPI bus and the network */ enc_unlock(priv); - net_unlock(); + netdev_unlock(&priv->dev); } /**************************************************************************** @@ -1812,7 +1812,7 @@ static void enc_toworker(FAR void *arg) /* Get exclusive access to the network */ - net_lock(); + netdev_lock(&priv->dev); /* Increment statistics and dump debug info */ @@ -1834,7 +1834,7 @@ static void enc_toworker(FAR void *arg) /* Release lock on the network */ - net_unlock(); + netdev_unlock(&priv->dev); } /**************************************************************************** diff --git a/drivers/net/encx24j600.c b/drivers/net/encx24j600.c index 6904ae6d7984e..e2f9852aeda96 100644 --- a/drivers/net/encx24j600.c +++ b/drivers/net/encx24j600.c @@ -1735,7 +1735,7 @@ static void enc_irqworker(FAR void *arg) /* Get exclusive access to both the network and the SPI bus. */ - net_lock(); + netdev_lock(&priv->dev); enc_lock(priv); /* A good practice is for the host controller to clear the Global Interrupt @@ -1884,7 +1884,7 @@ static void enc_irqworker(FAR void *arg) /* Release lock on the SPI bus and the network */ enc_unlock(priv); - net_unlock(); + netdev_unlock(&priv->dev); } /**************************************************************************** @@ -1957,7 +1957,7 @@ static void enc_toworker(FAR void *arg) /* Get exclusive access to the network. */ - net_lock(); + netdev_lock(&priv->dev); /* Increment statistics and dump debug info */ @@ -1979,7 +1979,7 @@ static void enc_toworker(FAR void *arg) /* Release the network */ - net_unlock(); + netdev_unlock(&priv->dev); } /**************************************************************************** diff --git a/drivers/net/ftmac100.c b/drivers/net/ftmac100.c index 0c0579146d7f1..2f8c14f2d8f61 100644 --- a/drivers/net/ftmac100.c +++ b/drivers/net/ftmac100.c @@ -809,7 +809,7 @@ static void ftmac100_interrupt_work(FAR void *arg) /* Process pending Ethernet interrupts */ - net_lock(); + netdev_lock(&priv->ft_dev); status = priv->status; ninfo("status=%08x(%08x) BASE=%p ISR=%p PHYCR=%p\n", @@ -883,7 +883,7 @@ static void ftmac100_interrupt_work(FAR void *arg) putreg32 (INT_MASK_ALL_ENABLED, &iobase->imr); ninfo("ISR-done\n"); - net_unlock(); + netdev_unlock(&priv->ft_dev); /* Re-enable Ethernet interrupts */ @@ -972,12 +972,12 @@ static void ftmac100_txtimeout_work(FAR void *arg) /* Process pending Ethernet interrupts */ - net_lock(); + netdev_lock(&priv->ft_dev); /* Then poll the network for new XMIT data */ devif_poll(&priv->ft_dev, ftmac100_txpoll); - net_unlock(); + netdev_unlock(&priv->ft_dev); } /**************************************************************************** @@ -1137,7 +1137,7 @@ static void ftmac100_txavail_work(FAR void *arg) /* Perform the poll */ - net_lock(); + netdev_lock(&priv->ft_dev); /* Ignore the notification if the interface is not yet up */ @@ -1152,7 +1152,7 @@ static void ftmac100_txavail_work(FAR void *arg) devif_poll(&priv->ft_dev, ftmac100_txpoll); } - net_unlock(); + netdev_unlock(&priv->ft_dev); } /**************************************************************************** diff --git a/drivers/net/lan91c111.c b/drivers/net/lan91c111.c index 87aa051b7fec2..cbf20bedb3249 100644 --- a/drivers/net/lan91c111.c +++ b/drivers/net/lan91c111.c @@ -812,7 +812,7 @@ static void lan91c111_interrupt_work(FAR void *arg) * thread has been configured. */ - net_lock(); + netdev_lock(dev); /* Process pending Ethernet interrupts */ @@ -873,7 +873,7 @@ static void lan91c111_interrupt_work(FAR void *arg) } } - net_unlock(); + netdev_unlock(dev); /* Re-enable Ethernet interrupts */ @@ -949,7 +949,7 @@ static int lan91c111_ifup(FAR struct net_driver_s *dev) dev->d_ipv6addr[6], dev->d_ipv6addr[7]); #endif - net_lock(); + netdev_lock(dev); /* Initialize PHYs, Ethernet interface, and setup up Ethernet interrupts */ @@ -974,7 +974,7 @@ static int lan91c111_ifup(FAR struct net_driver_s *dev) copyto16(priv, ADDR0_REG, &dev->d_mac.ether, sizeof(dev->d_mac.ether)); - net_unlock(); + netdev_unlock(dev); /* Enable the Ethernet interrupt */ @@ -1056,7 +1056,7 @@ static void lan91c111_txavail_work(FAR void *arg) * thread has been configured. */ - net_lock(); + netdev_lock(dev); /* Ignore the notification if the interface is not yet up */ @@ -1074,7 +1074,7 @@ static void lan91c111_txavail_work(FAR void *arg) } } - net_unlock(); + netdev_unlock(dev); } /**************************************************************************** @@ -1187,9 +1187,9 @@ static int lan91c111_addmac(FAR struct net_driver_s *dev, /* Add the MAC address to the hardware multicast routing table */ - net_lock(); + netdev_lock(dev); modifyreg16(priv, MCAST_REG1 + off, 0, 1 << bit); - net_unlock(); + netdev_unlock(dev); return OK; } @@ -1234,9 +1234,9 @@ static int lan91c111_rmmac(FAR struct net_driver_s *dev, /* Remove the MAC address from the hardware multicast routing table */ - net_lock(); + netdev_lock(dev); modifyreg16(priv, MCAST_REG1 + off, 1 << bit, 0); - net_unlock(); + netdev_unlock(dev); return OK; } @@ -1269,7 +1269,7 @@ static int lan91c111_ioctl(FAR struct net_driver_s *dev, int cmd, FAR struct mii_ioctl_data_s *req = (FAR void *)arg; int ret = OK; - net_lock(); + netdev_lock(dev); /* Decode and dispatch the driver-specific IOCTL command */ @@ -1292,7 +1292,7 @@ static int lan91c111_ioctl(FAR struct net_driver_s *dev, int cmd, ret = -ENOTTY; /* Special return value for this case */ } - net_unlock(); + netdev_unlock(dev); return ret; } #endif diff --git a/drivers/net/lan9250.c b/drivers/net/lan9250.c index c3f55078f422a..723725ebddcd3 100644 --- a/drivers/net/lan9250.c +++ b/drivers/net/lan9250.c @@ -1525,7 +1525,7 @@ static void lan9250_txavail_work(FAR void *arg) * thread has been configured. */ - net_lock(); + netdev_lock(dev); lan9250_lock_spi(priv); /* Ignore the notification if the interface is not yet up */ @@ -1544,7 +1544,7 @@ static void lan9250_txavail_work(FAR void *arg) /* Release lock on the SPI bus and the network */ lan9250_unlock_spi(priv); - net_unlock(); + netdev_unlock(dev); } /**************************************************************************** @@ -1798,7 +1798,7 @@ static void lan9250_int_worker(FAR void *arg) /* Get exclusive access to both the network and the SPI bus. */ - net_lock(); + netdev_lock(&priv->dev); lan9250_lock_spi(priv); /* There is no infinite loop check... if there are always pending @@ -1985,7 +1985,7 @@ static void lan9250_int_worker(FAR void *arg) /* Release lock on the SPI bus and the network */ lan9250_unlock_spi(priv); - net_unlock(); + netdev_unlock(&priv->dev); /* Enable ISR_GPIO interrupts after unlocking net so that application * could have chance to process Ethernet packet and free iob. @@ -2061,7 +2061,7 @@ static void lan9250_txtout_worker(FAR void *arg) /* Get exclusive access to the network */ - net_lock(); + netdev_lock(&priv->dev); /* Increment statistics and dump debug info */ @@ -2083,7 +2083,7 @@ static void lan9250_txtout_worker(FAR void *arg) /* Release lock on the network */ - net_unlock(); + netdev_unlock(&priv->dev); } /**************************************************************************** diff --git a/drivers/net/loopback.c b/drivers/net/loopback.c index 1bff3fff64ef9..a234edcdb0f53 100644 --- a/drivers/net/loopback.c +++ b/drivers/net/loopback.c @@ -194,7 +194,7 @@ static void lo_txavail_work(FAR void *arg) /* Ignore the notification if the interface is not yet up */ - net_lock(); + netdev_lock(&priv->lo_dev); if (priv->lo_bifup) { /* Reuse the devif_loopback() logic, Polling all pending events until @@ -204,7 +204,7 @@ static void lo_txavail_work(FAR void *arg) while (devif_poll(&priv->lo_dev, NULL)); } - net_unlock(); + netdev_unlock(&priv->lo_dev); } /**************************************************************************** diff --git a/drivers/net/skeleton.c b/drivers/net/skeleton.c index 07fde235cde2d..2f83a0e12ad14 100644 --- a/drivers/net/skeleton.c +++ b/drivers/net/skeleton.c @@ -466,7 +466,7 @@ static void skel_interrupt_work(FAR void *arg) * thread has been configured. */ - net_lock(); + netdev_lock(&priv->sk_dev); /* Process pending Ethernet interrupts */ @@ -484,7 +484,7 @@ static void skel_interrupt_work(FAR void *arg) */ skel_txdone(priv); - net_unlock(); + netdev_unlock(&priv->sk_dev); /* Re-enable Ethernet interrupts */ @@ -564,7 +564,7 @@ static void skel_txtimeout_work(FAR void *arg) * thread has been configured. */ - net_lock(); + netdev_lock(&priv->sk_dev); /* Increment statistics and dump debug info */ @@ -575,7 +575,7 @@ static void skel_txtimeout_work(FAR void *arg) /* Then poll the network for new XMIT data */ devif_poll(&priv->sk_dev, skel_txpoll); - net_unlock(); + netdev_unlock(&priv->sk_dev); } /**************************************************************************** @@ -731,7 +731,7 @@ static void skel_txavail_work(FAR void *arg) * thread has been configured. */ - net_lock(); + netdev_lock(&priv->sk_dev); /* Ignore the notification if the interface is not yet up */ @@ -744,7 +744,7 @@ static void skel_txavail_work(FAR void *arg) devif_poll(&priv->sk_dev, skel_txpoll); } - net_unlock(); + netdev_unlock(&priv->sk_dev); } /**************************************************************************** diff --git a/drivers/net/slip.c b/drivers/net/slip.c index 7ca1dd118bc83..7227a1507606f 100644 --- a/drivers/net/slip.c +++ b/drivers/net/slip.c @@ -750,7 +750,7 @@ static void slip_interrupt_work(FAR void *arg) * thread has been configured. */ - net_lock(); + netdev_lock(&self->dev); /* Process pending Ethernet interrupts */ @@ -798,7 +798,7 @@ static void slip_interrupt_work(FAR void *arg) slip_txdone(self); } - net_unlock(); + netdev_unlock(&self->dev); } /**************************************************************************** @@ -899,7 +899,7 @@ static void slip_txavail_work(FAR void *arg) * thread has been configured. */ - net_lock(); + netdev_lock(&self->dev); /* Ignore the notification if the interface is not yet up */ @@ -917,7 +917,7 @@ static void slip_txavail_work(FAR void *arg) } } - net_unlock(); + netdev_unlock(&self->dev); } /**************************************************************************** diff --git a/drivers/net/tun.c b/drivers/net/tun.c index 14ab6dea5cf97..5bc06f113bc0b 100644 --- a/drivers/net/tun.c +++ b/drivers/net/tun.c @@ -748,7 +748,7 @@ static void tun_txavail_work(FAR void *arg) return; } - net_lock(); + netdev_lock(&priv->dev); if (priv->bifup) { /* Poll the network for new XMIT data */ @@ -756,7 +756,7 @@ static void tun_txavail_work(FAR void *arg) devif_poll(&priv->dev, tun_txpoll); } - net_unlock(); + netdev_unlock(&priv->dev); nxmutex_unlock(&priv->lock); } @@ -1007,13 +1007,13 @@ static ssize_t tun_write(FAR struct file *filep, FAR const char *buffer, if (priv->write_d_len == 0) { - net_lock(); + netdev_lock(&priv->dev); netdev_iob_release(&priv->dev); ret = netdev_iob_prepare(&priv->dev, false, 0); priv->dev.d_buf = NULL; if (ret < 0) { - net_unlock(); + netdev_unlock(&priv->dev); break; } @@ -1021,14 +1021,14 @@ static ssize_t tun_write(FAR struct file *filep, FAR const char *buffer, buflen, -llhdrlen, false); if (ret < 0) { - net_unlock(); + netdev_unlock(&priv->dev); break; } priv->dev.d_len = buflen; tun_net_receive(priv); - net_unlock(); + netdev_unlock(&priv->dev); ret = buflen; break; @@ -1128,9 +1128,9 @@ static ssize_t tun_read(FAR struct file *filep, FAR char *buffer, priv->read_buf = NULL; priv->read_d_len = 0; - net_lock(); + netdev_lock(&priv->dev); tun_txdone(priv); - net_unlock(); + netdev_unlock(&priv->dev); break; } diff --git a/drivers/net/w5500.c b/drivers/net/w5500.c index a968a691a96d1..154a36c6ef85f 100644 --- a/drivers/net/w5500.c +++ b/drivers/net/w5500.c @@ -1513,7 +1513,7 @@ static void w5500_interrupt_work(FAR void *arg) * thread has been configured. */ - net_lock(); + netdev_lock(&self->w_dev); /* Process pending Ethernet interrupts. Read IR, MIR and SIR in one shot * to optimize latency, although MIR is not actually used. @@ -1592,7 +1592,7 @@ static void w5500_interrupt_work(FAR void *arg) } done: - net_unlock(); + netdev_unlock(&self->w_dev); /* Re-enable Ethernet interrupts */ @@ -1602,7 +1602,7 @@ static void w5500_interrupt_work(FAR void *arg) error: w5500_fence(self); - net_unlock(); + netdev_unlock(&self->w_dev); } /**************************************************************************** @@ -1667,7 +1667,7 @@ static void w5500_txtimeout_work(FAR void *arg) * thread has been configured. */ - net_lock(); + netdev_lock(&self->w_dev); /* Increment statistics and dump debug info */ @@ -1684,7 +1684,7 @@ static void w5500_txtimeout_work(FAR void *arg) devif_poll(&self->w_dev, w5500_txpoll); } - net_unlock(); + netdev_unlock(&self->w_dev); } /**************************************************************************** @@ -1848,7 +1848,7 @@ static void w5500_txavail_work(FAR void *arg) * thread has been configured. */ - net_lock(); + netdev_lock(&priv->w_dev); /* Ignore the notification if the interface is not yet up */ @@ -1861,7 +1861,7 @@ static void w5500_txavail_work(FAR void *arg) devif_poll(&priv->w_dev, w5500_txpoll); } - net_unlock(); + netdev_unlock(&priv->w_dev); } /**************************************************************************** diff --git a/drivers/usbdev/cdcecm.c b/drivers/usbdev/cdcecm.c index 06a89ade2eff2..3abdd5a37c477 100644 --- a/drivers/usbdev/cdcecm.c +++ b/drivers/usbdev/cdcecm.c @@ -530,7 +530,7 @@ static void cdcecm_interrupt_work(FAR void *arg) * thread has been configured. */ - net_lock(); + netdev_lock(&self->dev); /* Check if we received an incoming packet, if so, call cdcecm_receive() */ @@ -558,7 +558,7 @@ static void cdcecm_interrupt_work(FAR void *arg) cdcecm_txdone(self); } - net_unlock(); + netdev_unlock(&self->dev); } /**************************************************************************** @@ -666,7 +666,7 @@ static void cdcecm_txavail_work(FAR void *arg) * thread has been configured. */ - net_lock(); + netdev_lock(&self->dev); /* Ignore the notification if the interface is not yet up */ @@ -675,7 +675,7 @@ static void cdcecm_txavail_work(FAR void *arg) devif_poll(&self->dev, cdcecm_txpoll); } - net_unlock(); + netdev_unlock(&self->dev); } /**************************************************************************** diff --git a/drivers/usbdev/rndis.c b/drivers/usbdev/rndis.c index 2ca239f27d5fb..ab39b2ccff955 100644 --- a/drivers/usbdev/rndis.c +++ b/drivers/usbdev/rndis.c @@ -1022,7 +1022,7 @@ static void rndis_rxdispatch(FAR void *arg) FAR struct eth_hdr_s *hdr; irqstate_t flags; - net_lock(); + netdev_lock(&priv->netdev); flags = enter_critical_section(); rndis_giverxreq(priv); priv->netdev.d_len = priv->current_rx_datagram_size; @@ -1099,7 +1099,7 @@ static void rndis_rxdispatch(FAR void *arg) rndis_freenetreq(priv); } - net_unlock(); + netdev_unlock(&priv->netdev); } /**************************************************************************** @@ -1192,7 +1192,7 @@ static void rndis_txavail_work(FAR void *arg) { FAR struct rndis_dev_s *priv = (FAR struct rndis_dev_s *)arg; - net_lock(); + netdev_lock(&priv->netdev); if (rndis_allocnetreq(priv)) { @@ -1203,7 +1203,7 @@ static void rndis_txavail_work(FAR void *arg) } } - net_unlock(); + netdev_unlock(&priv->netdev); } /**************************************************************************** diff --git a/drivers/usbhost/usbhost_cdcmbim.c b/drivers/usbhost/usbhost_cdcmbim.c index e70551257e90f..e989c10096a88 100644 --- a/drivers/usbhost/usbhost_cdcmbim.c +++ b/drivers/usbhost/usbhost_cdcmbim.c @@ -2209,7 +2209,7 @@ static void cdcmbim_receive(FAR struct usbhost_cdcmbim_s *priv, { uinfo("received packet: %d len\n", len); - net_lock(); + netdev_lock(&priv->netdev); NETDEV_RXPACKETS(&priv->netdev); @@ -2249,7 +2249,7 @@ static void cdcmbim_receive(FAR struct usbhost_cdcmbim_s *priv, NETDEV_RXERRORS(dev); } - net_unlock(); + netdev_unlock(&priv->netdev); } /**************************************************************************** @@ -2405,7 +2405,7 @@ static void cdcmbim_txavail_work(FAR void *arg) { FAR struct usbhost_cdcmbim_s *priv = (FAR struct usbhost_cdcmbim_s *)arg; - net_lock(); + netdev_lock(&priv->netdev); priv->netdev.d_buf = (FAR uint8_t *)priv->txpktbuf; @@ -2414,7 +2414,7 @@ static void cdcmbim_txavail_work(FAR void *arg) devif_poll(&priv->netdev, cdcmbim_txpoll); } - net_unlock(); + netdev_unlock(&priv->netdev); } /**************************************************************************** diff --git a/drivers/wireless/ieee80211/bcm43xxx/bcmf_netdev.c b/drivers/wireless/ieee80211/bcm43xxx/bcmf_netdev.c index 01f192e6c7c42..f008cf2dea0b4 100644 --- a/drivers/wireless/ieee80211/bcm43xxx/bcmf_netdev.c +++ b/drivers/wireless/ieee80211/bcm43xxx/bcmf_netdev.c @@ -437,7 +437,7 @@ static void bcmf_tx_poll_work(FAR void *arg) { FAR struct bcmf_dev_s *priv = (FAR struct bcmf_dev_s *)arg; - net_lock(); + netdev_lock(&priv->bc_dev); /* Ignore the notification if the interface is not yet up */ @@ -462,7 +462,7 @@ static void bcmf_tx_poll_work(FAR void *arg) } } - net_unlock(); + netdev_unlock(&priv->bc_dev); } /**************************************************************************** @@ -492,7 +492,7 @@ static void bcmf_rxpoll_work(FAR void *arg) * thread has been configured. */ - net_lock(); + netdev_lock(&priv->bc_dev); /* Tx work will hold the d_buf until there is data to send, * replace and cache the d_buf temporarily @@ -512,7 +512,7 @@ static void bcmf_rxpoll_work(FAR void *arg) #if 0 bcmf_txdone(priv); #endif - net_unlock(); + netdev_unlock(&priv->bc_dev); } /**************************************************************************** diff --git a/drivers/wireless/ieee802154/xbee/xbee_netdev.c b/drivers/wireless/ieee802154/xbee/xbee_netdev.c index 46ee9b69d99d6..6c7b4bec6a8d2 100644 --- a/drivers/wireless/ieee802154/xbee/xbee_netdev.c +++ b/drivers/wireless/ieee802154/xbee/xbee_netdev.c @@ -464,7 +464,7 @@ static int xbeenet_rxframe(FAR struct xbeenet_driver_s *priv, ind->frame = NULL; - net_lock(); + netdev_lock(&priv->xd_dev.r_dev); /* Transfer the frame to the network logic */ @@ -506,7 +506,7 @@ static int xbeenet_rxframe(FAR struct xbeenet_driver_s *priv, if (ret < 0) #endif { - net_unlock(); + netdev_unlock(&priv->xd_dev.r_dev); ind->frame = iob; return ret; } @@ -516,7 +516,7 @@ static int xbeenet_rxframe(FAR struct xbeenet_driver_s *priv, NETDEV_RXPACKETS(&priv->xd_dev.r_dev); NETDEV_RXIPV6(&priv->xd_dev.r_dev); - net_unlock(); + netdev_unlock(&priv->xd_dev.r_dev); /* sixlowpan_input() will free the IOB, but we must free the struct * ieee802154_primitive_s container here. @@ -752,7 +752,7 @@ static void xbeenet_txavail_work(FAR void *arg) * thread has been configured. */ - net_lock(); + netdev_lock(&priv->xd_dev.r_dev); /* Ignore the notification if the interface is not yet up */ @@ -769,7 +769,7 @@ static void xbeenet_txavail_work(FAR void *arg) devif_poll(&priv->xd_dev.r_dev, xbeenet_txpoll_callback); } - net_unlock(); + netdev_unlock(&priv->xd_dev.r_dev); } /**************************************************************************** diff --git a/drivers/wireless/spirit/drivers/spirit_netdev.c b/drivers/wireless/spirit/drivers/spirit_netdev.c index 975024a634540..784dd089fe0e7 100644 --- a/drivers/wireless/spirit/drivers/spirit_netdev.c +++ b/drivers/wireless/spirit/drivers/spirit_netdev.c @@ -955,7 +955,7 @@ static void spirit_receive_work(FAR void *arg) wlinfo("Send frame %p to the network: Offset=%u Length=%u\n", iob, iob->io_offset, iob->io_len); - net_lock(); + netdev_lock(&priv->radio.r_dev); ret = sixlowpan_input(&priv->radio, iob, (FAR void *)pktmeta); if (ret < 0) { @@ -964,7 +964,7 @@ static void spirit_receive_work(FAR void *arg) NETDEV_ERRORS(&priv->radio.r_dev); } - net_unlock(); + netdev_unlock(&priv->radio.r_dev); /* sixlowpan_input() will free the IOB, but we must free the struct * pktradio_metadata_s container here. @@ -1567,7 +1567,7 @@ static void spirit_txtimeout_work(FAR void *arg) * worker thread has been configured. */ - net_lock(); + netdev_lock(&priv->radio.r_dev); /* Increment statistics and dump debug info */ @@ -1583,7 +1583,7 @@ static void spirit_txtimeout_work(FAR void *arg) */ work_queue(LPWORK, &priv->pollwork, spirit_txpoll_work, priv, 0); - net_unlock(); + netdev_unlock(&priv->radio.r_dev); } } @@ -1653,7 +1653,7 @@ static void spirit_txpoll_work(FAR void *arg) * thread has been configured. */ - net_lock(); + netdev_lock(&priv->radio.r_dev); #ifdef CONFIG_NET_6LOWPAN /* Make sure the our single packet buffer is attached */ @@ -1670,7 +1670,7 @@ static void spirit_txpoll_work(FAR void *arg) devif_poll(&priv->radio.r_dev, spirit_txpoll_callback); } - net_unlock(); + netdev_unlock(&priv->radio.r_dev); } /**************************************************************************** diff --git a/net/local/local.h b/net/local/local.h index a15e59eeef58b..bdeb14bd4c331 100644 --- a/net/local/local.h +++ b/net/local/local.h @@ -196,6 +196,40 @@ extern "C" EXTERN const struct sock_intf_s g_local_sockif; +/* Global protection lock for local socket */ + +extern mutex_t g_local_lock; + +/**************************************************************************** + * Inline Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: local_lock + * + * Description: + * Take the global local socket lock + * + ****************************************************************************/ + +static inline_function void local_lock(void) +{ + nxmutex_lock(&g_local_lock); +} + +/**************************************************************************** + * Name: local_unlock + * + * Description: + * Release the global local socket lock + * + ****************************************************************************/ + +static inline_function void local_unlock(void) +{ + nxmutex_unlock(&g_local_lock); +} + /**************************************************************************** * Public Function Prototypes ****************************************************************************/ diff --git a/net/local/local_accept.c b/net/local/local_accept.c index a950fb7c37e87..10e675c3f91a8 100644 --- a/net/local/local_accept.c +++ b/net/local/local_accept.c @@ -56,7 +56,9 @@ static int local_waitlisten(FAR struct local_conn_s *server) { /* No.. wait for a connection or a signal */ - ret = net_sem_wait(&server->lc_waitsem); + local_unlock(); + ret = nxsem_wait(&server->lc_waitsem); + local_lock(); if (ret < 0) { return ret; @@ -125,6 +127,7 @@ int local_accept(FAR struct socket *psock, FAR struct sockaddr *addr, /* Loop as necessary if we have to wait for a connection */ + local_lock(); for (; ; ) { /* Are there pending connections. Remove the accept from the @@ -161,6 +164,7 @@ int local_accept(FAR struct socket *psock, FAR struct sockaddr *addr, ret = local_set_nonblocking(conn); } + local_unlock(); return ret; } @@ -174,6 +178,7 @@ int local_accept(FAR struct socket *psock, FAR struct sockaddr *addr, { /* Yes.. return EAGAIN */ + local_unlock(); return -EAGAIN; } @@ -182,6 +187,7 @@ int local_accept(FAR struct socket *psock, FAR struct sockaddr *addr, ret = local_waitlisten(server); if (ret < 0) { + local_unlock(); return ret; } } diff --git a/net/local/local_bind.c b/net/local/local_bind.c index 6bcb8c221f589..593534faddf2d 100644 --- a/net/local/local_bind.c +++ b/net/local/local_bind.c @@ -66,14 +66,14 @@ int psock_local_bind(FAR struct socket *psock, /* Check if local address is already in use */ - net_lock(); + local_lock(); if (local_findconn(conn, unaddr) != NULL) { - net_unlock(); + local_unlock(); return -EADDRINUSE; } - net_unlock(); + local_unlock(); /* Save the address family */ diff --git a/net/local/local_conn.c b/net/local/local_conn.c index 13f071fad0410..2ec417e4269a2 100644 --- a/net/local/local_conn.c +++ b/net/local/local_conn.c @@ -38,6 +38,14 @@ #include "local/local.h" +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/* Global protection lock for local socket */ + +mutex_t g_local_lock = NXMUTEX_INITIALIZER; + /**************************************************************************** * Private Data ****************************************************************************/ @@ -168,6 +176,7 @@ FAR struct local_conn_s *local_alloc(void) nxmutex_init(&conn->lc_sendlock); nxmutex_init(&conn->lc_polllock); + nxrmutex_init(&conn->lc_conn.s_lock); #ifdef CONFIG_NET_LOCAL_SCM conn->lc_cred.pid = nxsched_getpid(); @@ -347,6 +356,7 @@ void local_free(FAR struct local_conn_s *conn) nxmutex_destroy(&conn->lc_sendlock); nxmutex_destroy(&conn->lc_polllock); + nxrmutex_destroy(&conn->lc_conn.s_lock); /* And free the connection structure */ diff --git a/net/local/local_connect.c b/net/local/local_connect.c index 1778a5ce0dc4a..3661caba8ecc9 100644 --- a/net/local/local_connect.c +++ b/net/local/local_connect.c @@ -88,9 +88,7 @@ static int inline local_stream_connect(FAR struct local_conn_s *client, return -ECONNREFUSED; } - net_lock(); ret = local_alloc_accept(server, client, &conn); - net_unlock(); if (ret < 0) { nerr("ERROR: Failed to alloc accept conn %s: %d\n", @@ -151,9 +149,9 @@ static int inline local_stream_connect(FAR struct local_conn_s *client, errout_with_conn: local_release_fifos(conn); client->lc_state = LOCAL_STATE_BOUND; - net_lock(); + local_lock(); local_free(conn); - net_unlock(); + local_unlock(); return ret; } @@ -175,7 +173,7 @@ int32_t local_generate_instance_id(void) static int32_t g_next_instance_id = 0; int32_t id; - /* Called from local_connect with net_lock held. */ + /* Called from local_connect with local_lock held. */ id = g_next_instance_id++; if (g_next_instance_id < 0) @@ -232,7 +230,7 @@ int psock_local_connect(FAR struct socket *psock, /* Find the matching server connection */ - net_lock(); + local_lock(); while ((conn = local_nextconn(conn)) != NULL) { /* Self found, continue */ @@ -275,7 +273,7 @@ int psock_local_connect(FAR struct socket *psock, ret = local_stream_connect(client, conn, _SS_ISNONBLOCK(client->lc_conn.s_flags)); - net_unlock(); + local_unlock(); return ret; } @@ -283,12 +281,12 @@ int psock_local_connect(FAR struct socket *psock, default: /* Bad, memory must be corrupted */ DEBUGPANIC(); /* PANIC if debug on */ - net_unlock(); + local_unlock(); return -EINVAL; } } - net_unlock(); + local_unlock(); ret = nx_stat(unpath, &buf, 1); return ret < 0 ? ret : -ECONNREFUSED; } diff --git a/net/local/local_listen.c b/net/local/local_listen.c index 1104760ee9fa5..1e0fdaa3c182b 100644 --- a/net/local/local_listen.c +++ b/net/local/local_listen.c @@ -80,14 +80,14 @@ int local_listen(FAR struct socket *psock, int backlog) return -EOPNOTSUPP; } - net_lock(); + local_lock(); /* Some sanity checks */ if (server->lc_proto != SOCK_STREAM || server->lc_state == LOCAL_STATE_UNBOUND) { - net_unlock(); + local_unlock(); return -EOPNOTSUPP; } @@ -114,7 +114,7 @@ int local_listen(FAR struct socket *psock, int backlog) server->lc_state = LOCAL_STATE_LISTENING; } - net_unlock(); + local_unlock(); return OK; } diff --git a/net/local/local_recvmsg.c b/net/local/local_recvmsg.c index 14fe7c7041aa3..eff19e77826fe 100644 --- a/net/local/local_recvmsg.c +++ b/net/local/local_recvmsg.c @@ -145,7 +145,7 @@ static void local_recvctl(FAR struct local_conn_s *conn, int *fds; int i; - net_lock(); + local_lock(); if (conn->lc_peer == NULL) { @@ -197,7 +197,7 @@ static void local_recvctl(FAR struct local_conn_s *conn, } out: - net_unlock(); + local_unlock(); } #endif /* CONFIG_NET_LOCAL_SCM */ diff --git a/net/local/local_release.c b/net/local/local_release.c index 0f32da000db0b..86973b4d8fb64 100644 --- a/net/local/local_release.c +++ b/net/local/local_release.c @@ -58,7 +58,7 @@ int local_release(FAR struct local_conn_s *conn) /* There should be no references on this structure */ DEBUGASSERT(conn->lc_crefs == 0); - net_lock(); + local_lock(); #ifdef CONFIG_NET_LOCAL_STREAM /* We should not bet here with state LOCAL_STATE_ACCEPT. That is an @@ -97,6 +97,6 @@ int local_release(FAR struct local_conn_s *conn) /* Free the connection structure */ local_free(conn); - net_unlock(); + local_unlock(); return OK; } diff --git a/net/local/local_sendmsg.c b/net/local/local_sendmsg.c index 72fe2049c93e5..c74a2ec54355e 100644 --- a/net/local/local_sendmsg.c +++ b/net/local/local_sendmsg.c @@ -81,7 +81,7 @@ static int local_sendctl(FAR struct local_conn_s *conn, int ret; int i = 0; - net_lock(); + local_lock(); peer = conn->lc_peer; if (peer == NULL) { @@ -119,12 +119,12 @@ static int local_sendctl(FAR struct local_conn_s *conn, } } - net_unlock(); + local_unlock(); return count; fail: local_freectl(conn, i); - net_unlock(); + local_unlock(); return ret; } #endif /* CONFIG_NET_LOCAL_SCM */ @@ -293,17 +293,17 @@ static ssize_t local_sendto(FAR struct socket *psock, return -EISCONN; } - net_lock(); + local_lock(); server = local_findconn(conn, unaddr); if (server == NULL) { - net_unlock(); + local_unlock(); nerr("ERROR: No such file or directory\n"); return -ENOENT; } - net_unlock(); + local_unlock(); /* Make sure that dgram is sent safely */ @@ -437,9 +437,9 @@ ssize_t local_sendmsg(FAR struct socket *psock, FAR struct msghdr *msg, if (len < 0 && count > 0) { - net_lock(); + local_lock(); local_freectl(conn, count); - net_unlock(); + local_unlock(); } #else len = to ? local_sendto(psock, buf, len, flags, to, tolen) : diff --git a/net/local/local_sockif.c b/net/local/local_sockif.c index 1cefb25e1d8ea..3db4187acd9f7 100644 --- a/net/local/local_sockif.c +++ b/net/local/local_sockif.c @@ -132,9 +132,9 @@ static int local_sockif_alloc(FAR struct socket *psock) /* Allocate the local connection structure */ FAR struct local_conn_s *conn; - net_lock(); + local_lock(); conn = local_alloc(); - net_unlock(); + local_unlock(); if (conn == NULL) { /* Failed to reserve a connection structure */ @@ -655,7 +655,7 @@ static int local_setsockopt(FAR struct socket *psock, int level, int option, return -EINVAL; } - net_lock(); + local_lock(); /* Only SOCK_STREAM sockets need set the send buffer size */ @@ -681,7 +681,7 @@ static int local_setsockopt(FAR struct socket *psock, int level, int option, } #endif - net_unlock(); + local_unlock(); return ret; } @@ -696,7 +696,7 @@ static int local_setsockopt(FAR struct socket *psock, int level, int option, return -EINVAL; } - net_lock(); + local_lock(); rcvsize = *(FAR const int *)value; #ifdef CONFIG_NET_LOCAL_DGRAM @@ -740,7 +740,7 @@ static int local_setsockopt(FAR struct socket *psock, int level, int option, conn->lc_rcvsize = rcvsize; } - net_unlock(); + local_unlock(); return ret; }