mirror of
https://github.com/apache/nuttx.git
synced 2026-06-04 14:53:47 +08:00
Fix wait loop and void cast (#24)
* Simplify EINTR/ECANCEL error handling 1. Add semaphore uninterruptible wait function 2 .Replace semaphore wait loop with a single uninterruptible wait 3. Replace all sem_xxx to nxsem_xxx * Unify the void cast usage 1. Remove void cast for function because many place ignore the returned value witout cast 2. Replace void cast for variable with UNUSED macro
This commit is contained in:
@@ -195,7 +195,7 @@ int mac802154_txdesc_alloc(FAR struct ieee802154_privmac_s *priv,
|
||||
/* MAC is already released */
|
||||
|
||||
wlwarn("WARNING: mac802154_takesem failed: %d\n", ret);
|
||||
return -EINTR;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* If we've taken a count from the semaphore, we have "reserved" the
|
||||
@@ -209,7 +209,7 @@ int mac802154_txdesc_alloc(FAR struct ieee802154_privmac_s *priv,
|
||||
wlwarn("WARNING: mac802154_lock failed: %d\n", ret);
|
||||
|
||||
mac802154_givesem(&priv->txdesc_sem);
|
||||
return -EINTR;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* We can now safely unlink the next free structure from the free list */
|
||||
|
||||
@@ -151,7 +151,7 @@ int mac802154_get_mhrlen(MACHANDLE mac,
|
||||
|
||||
int mac802154_req_data(MACHANDLE mac,
|
||||
FAR const struct ieee802154_frame_meta_s *meta,
|
||||
FAR struct iob_s *frame);
|
||||
FAR struct iob_s *frame, bool allowinterrupt);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: mac802154_req_purge
|
||||
|
||||
@@ -73,7 +73,7 @@
|
||||
|
||||
int mac802154_req_data(MACHANDLE mac,
|
||||
FAR const struct ieee802154_frame_meta_s *meta,
|
||||
FAR struct iob_s *frame)
|
||||
FAR struct iob_s *frame, bool allowinterrupt)
|
||||
{
|
||||
FAR struct ieee802154_privmac_s *priv =
|
||||
(FAR struct ieee802154_privmac_s *)mac;
|
||||
@@ -156,7 +156,7 @@ int mac802154_req_data(MACHANDLE mac,
|
||||
|
||||
/* From this point on, we need exclusive access to the privmac struct */
|
||||
|
||||
ret = mac802154_lock(priv, true);
|
||||
ret = mac802154_lock(priv, allowinterrupt);
|
||||
if (ret < 0)
|
||||
{
|
||||
/* Should only fail if interrupted by a signal */
|
||||
|
||||
@@ -179,18 +179,7 @@ static const struct file_operations mac802154dev_fops =
|
||||
|
||||
static inline int mac802154dev_takesem(sem_t *sem)
|
||||
{
|
||||
int ret;
|
||||
|
||||
/* Take the semaphore (perhaps waiting) */
|
||||
|
||||
ret = nxsem_wait(sem);
|
||||
|
||||
/* The only case that an error should occur here is if the wait were
|
||||
* awakened by a signal.
|
||||
*/
|
||||
|
||||
DEBUGASSERT(ret == OK || ret == -EINTR);
|
||||
return ret;
|
||||
return nxsem_wait(sem);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
@@ -440,7 +429,6 @@ static ssize_t mac802154dev_read(FAR struct file *filep, FAR char *buffer,
|
||||
ret = nxsem_wait(&dev->readsem);
|
||||
if (ret < 0)
|
||||
{
|
||||
DEBUGASSERT(ret == -EINTR || ret == -ECANCELED);
|
||||
dev->readpending = false;
|
||||
return ret;
|
||||
}
|
||||
@@ -568,7 +556,7 @@ static ssize_t mac802154dev_write(FAR struct file *filep,
|
||||
|
||||
/* Pass the request to the MAC layer */
|
||||
|
||||
ret = mac802154_req_data(dev->md_mac, &tx->meta, iob);
|
||||
ret = mac802154_req_data(dev->md_mac, &tx->meta, iob, true);
|
||||
if (ret < 0)
|
||||
{
|
||||
iob_free(iob, IOBUSER_WIRELESS_MAC802154_CHARDEV);
|
||||
@@ -681,7 +669,6 @@ static int mac802154dev_ioctl(FAR struct file *filep, int cmd,
|
||||
ret = nxsem_wait(&dev->geteventsem);
|
||||
if (ret < 0)
|
||||
{
|
||||
DEBUGASSERT(ret == -EINTR || ret == -ECANCELED);
|
||||
dev->geteventpending = false;
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -540,27 +540,14 @@ void mac802154_notify(FAR struct ieee802154_privmac_s *priv,
|
||||
|
||||
static inline int mac802154_takesem(sem_t *sem, bool allowinterrupt)
|
||||
{
|
||||
int ret;
|
||||
do
|
||||
if (allowinterrupt)
|
||||
{
|
||||
/* Take a count from the semaphore, possibly waiting */
|
||||
|
||||
ret = nxsem_wait(sem);
|
||||
if (ret < 0)
|
||||
{
|
||||
/* EINTR and ECANCELED are the only errors that we expect */
|
||||
|
||||
DEBUGASSERT(ret == -EINTR || ret == -ECANCELED);
|
||||
|
||||
if (allowinterrupt)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
return nxsem_wait(sem);
|
||||
}
|
||||
else
|
||||
{
|
||||
return nxsem_wait_uninterruptible(sem);
|
||||
}
|
||||
while (ret == -EINTR);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_MAC802154_LOCK_VERBOSE
|
||||
|
||||
@@ -439,7 +439,7 @@ static void lo_loopback_work(FAR void *arg)
|
||||
/* Perform the loopback */
|
||||
|
||||
net_lock();
|
||||
(void)lo_loopback(&priv->lo_radio.r_dev);
|
||||
lo_loopback(&priv->lo_radio.r_dev);
|
||||
net_unlock();
|
||||
}
|
||||
|
||||
@@ -476,11 +476,11 @@ static void lo_poll_work(FAR void *arg)
|
||||
|
||||
/* Then perform the poll */
|
||||
|
||||
(void)devif_timer(&priv->lo_radio.r_dev, LO_WDDELAY, lo_loopback);
|
||||
devif_timer(&priv->lo_radio.r_dev, LO_WDDELAY, lo_loopback);
|
||||
|
||||
/* Setup the watchdog poll timer again */
|
||||
|
||||
(void)wd_start(priv->lo_polldog, LO_WDDELAY, lo_poll_expiry, 1, priv);
|
||||
wd_start(priv->lo_polldog, LO_WDDELAY, lo_poll_expiry, 1, priv);
|
||||
net_unlock();
|
||||
}
|
||||
|
||||
@@ -582,8 +582,8 @@ static int lo_ifup(FAR struct net_driver_s *dev)
|
||||
|
||||
/* Set and activate a timer process */
|
||||
|
||||
(void)wd_start(priv->lo_polldog, LO_WDDELAY, lo_poll_expiry,
|
||||
1, (wdparm_t)priv);
|
||||
wd_start(priv->lo_polldog, LO_WDDELAY, lo_poll_expiry,
|
||||
1, (wdparm_t)priv);
|
||||
|
||||
priv->lo_bifup = true;
|
||||
return OK;
|
||||
@@ -657,7 +657,7 @@ static void lo_txavail_work(FAR void *arg)
|
||||
priv->lo_radio.r_dev.d_buf = g_iobuffer.rb_buf;
|
||||
#endif
|
||||
|
||||
(void)devif_poll(&priv->lo_radio.r_dev, lo_loopback);
|
||||
devif_poll(&priv->lo_radio.r_dev, lo_loopback);
|
||||
}
|
||||
|
||||
net_unlock();
|
||||
@@ -1118,7 +1118,7 @@ int ieee8021514_loopback(void)
|
||||
* performed.
|
||||
*/
|
||||
|
||||
(void)netdev_register(&priv->lo_radio.r_dev, NET_LL_IEEE802154);
|
||||
netdev_register(&priv->lo_radio.r_dev, NET_LL_IEEE802154);
|
||||
|
||||
/* Put the network in the UP state */
|
||||
|
||||
|
||||
@@ -580,12 +580,12 @@ static void macnet_txpoll_work(FAR void *arg)
|
||||
|
||||
/* Then perform the poll */
|
||||
|
||||
(void)devif_timer(&priv->md_dev.r_dev, TXPOLL_WDDELAY, macnet_txpoll_callback);
|
||||
devif_timer(&priv->md_dev.r_dev, TXPOLL_WDDELAY, macnet_txpoll_callback);
|
||||
|
||||
/* Setup the watchdog poll timer again */
|
||||
|
||||
(void)wd_start(priv->md_txpoll, TXPOLL_WDDELAY, macnet_txpoll_expiry, 1,
|
||||
(wdparm_t)priv);
|
||||
wd_start(priv->md_txpoll, TXPOLL_WDDELAY, macnet_txpoll_expiry, 1,
|
||||
(wdparm_t)priv);
|
||||
net_unlock();
|
||||
}
|
||||
|
||||
@@ -765,8 +765,8 @@ static int macnet_ifup(FAR struct net_driver_s *dev)
|
||||
|
||||
/* Set and activate a timer process */
|
||||
|
||||
(void)wd_start(priv->md_txpoll, TXPOLL_WDDELAY, macnet_txpoll_expiry,
|
||||
1, (wdparm_t)priv);
|
||||
wd_start(priv->md_txpoll, TXPOLL_WDDELAY, macnet_txpoll_expiry,
|
||||
1, (wdparm_t)priv);
|
||||
|
||||
ret = OK;
|
||||
}
|
||||
@@ -861,7 +861,7 @@ static void macnet_txavail_work(FAR void *arg)
|
||||
|
||||
/* Then poll the network for new XMIT data */
|
||||
|
||||
(void)devif_poll(&priv->md_dev.r_dev, macnet_txpoll_callback);
|
||||
devif_poll(&priv->md_dev.r_dev, macnet_txpoll_callback);
|
||||
}
|
||||
|
||||
net_unlock();
|
||||
@@ -1077,7 +1077,6 @@ static int macnet_ioctl(FAR struct net_driver_s *dev, int cmd,
|
||||
ret = nxsem_wait(&priv->md_eventsem);
|
||||
if (ret < 0)
|
||||
{
|
||||
DEBUGASSERT(ret == -EINTR || ret == -ECANCELED);
|
||||
priv->md_eventpending = false;
|
||||
return ret;
|
||||
}
|
||||
@@ -1200,17 +1199,9 @@ static int macnet_req_data(FAR struct radio_driver_s *netdev,
|
||||
framelist = iob->io_flink;
|
||||
iob->io_flink = NULL;
|
||||
|
||||
/* Transfer the frame to the MAC. mac802154_req_data will return
|
||||
* -EINTR if a signal is received during certain phases of processing.
|
||||
* In this context we just need to ignore -EINTR errors and try again.
|
||||
*/
|
||||
|
||||
do
|
||||
{
|
||||
ret = mac802154_req_data(priv->md_mac, pktmeta, iob);
|
||||
}
|
||||
while (ret == -EINTR);
|
||||
/* Transfer the frame to the MAC. */
|
||||
|
||||
ret = mac802154_req_data(priv->md_mac, pktmeta, iob, false);
|
||||
if (ret < 0)
|
||||
{
|
||||
wlerr("ERROR: mac802154_req_data failed: %d\n", ret);
|
||||
@@ -1295,10 +1286,10 @@ static int macnet_properties(FAR struct radio_driver_s *netdev,
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_NET_6LOWPAN_EXTENDEDADDR
|
||||
(void)macnet_coord_eaddr(netdev, properties->sp_hubnode.nv_addr);
|
||||
macnet_coord_eaddr(netdev, properties->sp_hubnode.nv_addr);
|
||||
properties->sp_hubnode.nv_addrlen = IEEE802154_EADDRSIZE;
|
||||
#else
|
||||
(void)macnet_coord_saddr(netdev, properties->sp_hubnode.nv_addr);
|
||||
macnet_coord_saddr(netdev, properties->sp_hubnode.nv_addr);
|
||||
properties->sp_hubnode.nv_addrlen = IEEE802154_SADDRSIZE;
|
||||
#endif
|
||||
#endif
|
||||
@@ -1431,7 +1422,7 @@ int mac802154netdev_register(MACHANDLE mac)
|
||||
|
||||
/* Register the device with the OS so that socket IOCTLs can be performed */
|
||||
|
||||
(void)netdev_register(&priv->md_dev.r_dev, NET_LL_IEEE802154);
|
||||
netdev_register(&priv->md_dev.r_dev, NET_LL_IEEE802154);
|
||||
|
||||
/* Put the network in the DOWN state, let the user decide when to bring it up */
|
||||
|
||||
|
||||
@@ -102,7 +102,6 @@ int mac802154_req_scan(MACHANDLE mac, FAR struct ieee802154_scan_req_s *req)
|
||||
ret = mac802154_takesem(&priv->opsem, true);
|
||||
if (ret < 0)
|
||||
{
|
||||
ret = -EINTR;
|
||||
goto errout;
|
||||
}
|
||||
|
||||
@@ -114,7 +113,6 @@ int mac802154_req_scan(MACHANDLE mac, FAR struct ieee802154_scan_req_s *req)
|
||||
if (ret < 0)
|
||||
{
|
||||
mac802154_givesem(&priv->opsem);
|
||||
ret = -EINTR;
|
||||
goto errout;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user