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:
Xiang Xiao
2020-01-02 10:49:34 -06:00
committed by Gregory Nutt
parent 316675f4db
commit 6a3c2aded6
1602 changed files with 6311 additions and 10874 deletions
+3 -21
View File
@@ -149,13 +149,7 @@ static int conn_tx_kthread(int argc, FAR char *argv[])
wlinfo("calling nxsem_wait\n");
do
{
ret = nxsem_wait(&g_btdev.le_pkts_sem);
}
while (ret == -EINTR);
DEBUGASSERT(ret == OK);
nxsem_wait_uninterruptible(&g_btdev.le_pkts_sem);
/* Check for disconnection */
@@ -574,13 +568,7 @@ void bt_conn_set_state(FAR struct bt_conn_s *conn,
* zero when we complete this.
*/
do
{
ret = nxsem_wait(&g_conn_handoff.sync_sem);
}
while (ret == -EINTR);
DEBUGASSERT(ret == OK);
nxsem_wait_uninterruptible(&g_conn_handoff.sync_sem);
/* Start the Tx connection kernel thread */
@@ -595,13 +583,7 @@ void bt_conn_set_state(FAR struct bt_conn_s *conn,
* sem_count at -1. It will be zero again when we continue.
*/
do
{
ret = nxsem_wait(&g_conn_handoff.sync_sem);
}
while (ret == -EINTR);
DEBUGASSERT(ret == OK);
nxsem_wait_uninterruptible(&g_conn_handoff.sync_sem);
nxsem_post(&g_conn_handoff.sync_sem);
}
break;
+3 -15
View File
@@ -439,7 +439,7 @@ static void hci_num_completed_packets(FAR struct bt_buf_s *buf)
while (count--)
{
sem_post(&g_btdev.le_pkts_sem);
nxsem_post(&g_btdev.le_pkts_sem);
}
}
}
@@ -978,13 +978,7 @@ static int hci_tx_kthread(int argc, FAR char *argv[])
/* Wait until ncmd > 0 */
do
{
ret = nxsem_wait(&g_btdev.ncmd_sem);
}
while (ret == -EINTR);
DEBUGASSERT(ret >= 0);
nxsem_wait_uninterruptible(&g_btdev.ncmd_sem);
/* Get next command - wait if necessary */
@@ -1765,13 +1759,7 @@ int bt_hci_cmd_send_sync(uint16_t opcode, FAR struct bt_buf_s *buf,
* released while we are waiting.
*/
do
{
/* The timed wait could also be awakened by a signal */
ret = nxsem_timedwait(&sync_sem, &abstime);
}
while (ret == -EINTR);
nxsem_timedwait_uninterruptible(&sync_sem, &abstime);
}
sched_unlock();
+1 -10
View File
@@ -157,7 +157,6 @@ static void btnet_scan_callback(FAR const bt_addr_le_t *addr, int8_t rssi,
uint8_t nexttail;
uint8_t head;
uint8_t tail;
int ret;
if (!g_scanstate.bs_scanning)
{
@@ -173,14 +172,7 @@ static void btnet_scan_callback(FAR const bt_addr_le_t *addr, int8_t rssi,
/* Get exclusive access to the scan data */
while ((ret = nxsem_wait(&g_scanstate.bs_exclsem)) < 0)
{
DEBUGASSERT(ret == -EINTR || ret == -ECANCELED);
if (ret != -EINTR)
{
return;
}
}
nxsem_wait_uninterruptible(&g_scanstate.bs_exclsem);
/* Add the scan data to the cache */
@@ -260,7 +252,6 @@ static int btnet_scan_result(FAR struct bt_scanresponse_s *result,
ret = nxsem_wait(&g_scanstate.bs_exclsem);
if (ret < 0)
{
DEBUGASSERT(ret == -EINTR || ret == -ECANCELED);
return ret;
}
}
+6 -6
View File
@@ -543,12 +543,12 @@ static void btnet_txpoll_work(FAR void *arg)
/* Then perform the poll */
(void)devif_timer(&priv->bd_dev.r_dev, TXPOLL_WDDELAY, btnet_txpoll_callback);
devif_timer(&priv->bd_dev.r_dev, TXPOLL_WDDELAY, btnet_txpoll_callback);
/* Setup the watchdog poll timer again */
(void)wd_start(priv->bd_txpoll, TXPOLL_WDDELAY, btnet_txpoll_expiry, 1,
(wdparm_t)priv);
wd_start(priv->bd_txpoll, TXPOLL_WDDELAY, btnet_txpoll_expiry, 1,
(wdparm_t)priv);
net_unlock();
}
@@ -627,8 +627,8 @@ static int btnet_ifup(FAR struct net_driver_s *netdev)
/* Set and activate a timer process */
(void)wd_start(priv->bd_txpoll, TXPOLL_WDDELAY, btnet_txpoll_expiry,
1, (wdparm_t)priv);
wd_start(priv->bd_txpoll, TXPOLL_WDDELAY, btnet_txpoll_expiry,
1, (wdparm_t)priv);
/* The interface is now up */
@@ -724,7 +724,7 @@ static void btnet_txavail_work(FAR void *arg)
/* Then poll the network for new XMIT data */
(void)devif_poll(&priv->bd_dev.r_dev, btnet_txpoll_callback);
devif_poll(&priv->bd_dev.r_dev, btnet_txpoll_callback);
}
net_unlock();