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:
+5
-30
@@ -276,12 +276,7 @@ static void ft5x06_data_worker(FAR void *arg)
|
||||
* corrupt any read operation that is in place.
|
||||
*/
|
||||
|
||||
do
|
||||
{
|
||||
ret = nxsem_wait(&priv->devsem);
|
||||
DEBUGASSERT(ret >= 0 || ret == -EINTR);
|
||||
}
|
||||
while (ret < 0);
|
||||
nxsem_wait_uninterruptible(&priv->devsem);
|
||||
|
||||
/* Read touch data */
|
||||
/* Set up the address write operation */
|
||||
@@ -356,7 +351,7 @@ static void ft5x06_data_worker(FAR void *arg)
|
||||
#ifdef CONFIG_FT5X06_POLLMODE
|
||||
/* Exit, re-starting the poll. */
|
||||
|
||||
(void)wd_start(priv->polltimer, priv->delay, ft5x06_poll_timeout, 1, priv);
|
||||
wd_start(priv->polltimer, priv->delay, ft5x06_poll_timeout, 1, priv);
|
||||
|
||||
#else
|
||||
/* Exit, re-enabling FT5x06 interrupts */
|
||||
@@ -670,12 +665,7 @@ static ssize_t ft5x06_waitsample(FAR struct ft5x06_dev_s *priv,
|
||||
|
||||
if (ret < 0)
|
||||
{
|
||||
/* If we are awakened by a signal, then we need to return
|
||||
* the failure now.
|
||||
*/
|
||||
|
||||
ierr("ERROR: nxsem_wait failed: %d\n", ret);
|
||||
DEBUGASSERT(ret == -EINTR || ret == -ECANCELED);
|
||||
goto errout;
|
||||
}
|
||||
}
|
||||
@@ -761,7 +751,7 @@ static void ft5x06_shutdown(FAR struct ft5x06_dev_s *priv)
|
||||
#ifdef CONFIG_FT5X06_POLLMODE
|
||||
/* Stop the poll timer */
|
||||
|
||||
(void)wd_cancel(priv->polltimer);
|
||||
wd_cancel(priv->polltimer);
|
||||
|
||||
#else
|
||||
FAR const struct ft5x06_config_s *config = priv->config;
|
||||
@@ -795,10 +785,7 @@ static int ft5x06_open(FAR struct file *filep)
|
||||
ret = nxsem_wait(&priv->devsem);
|
||||
if (ret < 0)
|
||||
{
|
||||
/* This should only happen if the wait was cancelled by an signal */
|
||||
|
||||
ierr("ERROR: nxsem_wait failed: %d\n", ret);
|
||||
DEBUGASSERT(ret == -EINTR || ret == -ECANCELED);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -857,10 +844,7 @@ static int ft5x06_close(FAR struct file *filep)
|
||||
ret = nxsem_wait(&priv->devsem);
|
||||
if (ret < 0)
|
||||
{
|
||||
/* This should only happen if the wait was cancelled by an signal */
|
||||
|
||||
ierr("ERROR: nxsem_wait failed: %d\n", ret);
|
||||
DEBUGASSERT(ret == -EINTR || ret == -ECANCELED);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -921,10 +905,7 @@ static ssize_t ft5x06_read(FAR struct file *filep, FAR char *buffer,
|
||||
ret = nxsem_wait(&priv->devsem);
|
||||
if (ret < 0)
|
||||
{
|
||||
/* This should only happen if the wait was cancelled by an signal */
|
||||
|
||||
ierr("ERROR: nxsem_wait failed: %d\n", ret);
|
||||
DEBUGASSERT(ret == -EINTR || ret == -ECANCELED);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -984,10 +965,7 @@ static int ft5x06_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
|
||||
ret = nxsem_wait(&priv->devsem);
|
||||
if (ret < 0)
|
||||
{
|
||||
/* This should only happen if the wait was cancelled by an signal */
|
||||
|
||||
ierr("ERROR: nxsem_wait failed: %d\n", ret);
|
||||
DEBUGASSERT(ret == -EINTR || ret == -ECANCELED);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -1044,10 +1022,7 @@ static int ft5x06_poll(FAR struct file *filep, FAR struct pollfd *fds,
|
||||
ret = nxsem_wait(&priv->devsem);
|
||||
if (ret < 0)
|
||||
{
|
||||
/* This should only happen if the wait was canceled by an signal */
|
||||
|
||||
ierr("ERROR: nxsem_wait failed: %d\n", ret);
|
||||
DEBUGASSERT(ret == -EINTR || ret == -ECANCELED);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -1214,7 +1189,7 @@ int ft5x06_register(FAR struct i2c_master_s *i2c,
|
||||
|
||||
/* Register the device as an input device */
|
||||
|
||||
(void)snprintf(devname, DEV_NAMELEN, DEV_FORMAT, minor);
|
||||
snprintf(devname, DEV_NAMELEN, DEV_FORMAT, minor);
|
||||
iinfo("Registering %s\n", devname);
|
||||
|
||||
ret = register_driver(devname, &ft5x06_fops, 0666, priv);
|
||||
@@ -1241,7 +1216,7 @@ int ft5x06_register(FAR struct i2c_master_s *i2c,
|
||||
|
||||
errout_with_timer:
|
||||
#ifdef CONFIG_FT5X06_POLLMODE
|
||||
(void)wd_delete(priv->polltimer);
|
||||
wd_delete(priv->polltimer);
|
||||
|
||||
errout_with_priv:
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user