Replace nxsem API when used as a lock with nxmutex API

Signed-off-by: anjiahao <anjiahao@xiaomi.com>
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
anjiahao
2022-09-06 14:18:45 +08:00
committed by Masayuki Ishikawa
parent 0dfd1f004d
commit d1d46335df
710 changed files with 7503 additions and 14852 deletions
+17 -16
View File
@@ -34,6 +34,7 @@
#include <debug.h>
#include <nuttx/kmalloc.h>
#include <nuttx/mutex.h>
#include <nuttx/signal.h>
#include <nuttx/fs/fs.h>
#include <nuttx/i2c/i2c_master.h>
@@ -108,7 +109,7 @@ struct scd41_dev_s
#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
int16_t crefs; /* Number of open references */
#endif
sem_t devsem;
mutex_t devlock;
uint16_t pressure_comp; /* Pressure compensation in mbar (non-zero
* value overrides altitude compensation). */
uint16_t altitude_comp; /* Altitude compensation in meters */
@@ -581,7 +582,7 @@ static int scd41_open(FAR struct file *filep)
/* Get exclusive access */
ret = nxsem_wait_uninterruptible(&priv->devsem);
ret = nxmutex_lock(&priv->devlock);
if (ret < 0)
{
return ret;
@@ -602,7 +603,7 @@ static int scd41_open(FAR struct file *filep)
priv->crefs--;
}
nxsem_post(&priv->devsem);
nxmutex_unlock(&priv->devlock);
return ret;
}
#endif
@@ -624,7 +625,7 @@ static int scd41_close(FAR struct file *filep)
/* Get exclusive access */
ret = nxsem_wait_uninterruptible(&priv->devsem);
ret = nxmutex_lock(&priv->devlock);
if (ret < 0)
{
return ret;
@@ -641,12 +642,12 @@ static int scd41_close(FAR struct file *filep)
if (priv->crefs <= 0 && priv->unlinked)
{
nxsem_destroy(&priv->devsem);
nxmutex_destroy(&priv->devlock);
kmm_free(priv);
return OK;
}
nxsem_post(&priv->devsem);
nxmutex_unlock(&priv->devlock);
return OK;
}
#endif
@@ -671,7 +672,7 @@ static ssize_t scd41_read(FAR struct file *filep, FAR char *buffer,
/* Get exclusive access */
ret = nxsem_wait_uninterruptible(&priv->devsem);
ret = nxmutex_lock(&priv->devlock);
if (ret < 0)
{
return (ssize_t)ret;
@@ -684,7 +685,7 @@ static ssize_t scd41_read(FAR struct file *filep, FAR char *buffer,
* sensor use on hot swappable I2C bus.
*/
nxsem_post(&priv->devsem);
nxmutex_unlock(&priv->devlock);
return -ENODEV;
}
#endif
@@ -718,7 +719,7 @@ static ssize_t scd41_read(FAR struct file *filep, FAR char *buffer,
}
}
nxsem_post(&priv->devsem);
nxmutex_unlock(&priv->devlock);
return length;
}
@@ -745,7 +746,7 @@ static int scd41_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
/* Get exclusive access */
ret = nxsem_wait_uninterruptible(&priv->devsem);
ret = nxmutex_lock(&priv->devlock);
if (ret < 0)
{
return ret;
@@ -758,7 +759,7 @@ static int scd41_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
* sensor use on hot swappable I2C bus.
*/
nxsem_post(&priv->devsem);
nxmutex_unlock(&priv->devlock);
return -ENODEV;
}
#endif
@@ -922,7 +923,7 @@ static int scd41_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
break;
}
nxsem_post(&priv->devsem);
nxmutex_unlock(&priv->devlock);
return ret;
}
@@ -941,7 +942,7 @@ static int scd41_unlink(FAR struct inode *inode)
/* Get exclusive access */
ret = nxsem_wait_uninterruptible(&priv->devsem);
ret = nxmutex_lock(&priv->devlock);
if (ret < 0)
{
return ret;
@@ -951,7 +952,7 @@ static int scd41_unlink(FAR struct inode *inode)
if (priv->crefs <= 0)
{
nxsem_destroy(&priv->devsem);
nxmutex_destroy(&priv->devlock);
kmm_free(priv);
return OK;
}
@@ -961,7 +962,7 @@ static int scd41_unlink(FAR struct inode *inode)
*/
priv->unlinked = true;
nxsem_post(&priv->devsem);
nxmutex_unlock(&priv->devlock);
return OK;
}
#endif
@@ -1012,7 +1013,7 @@ int scd41_register_i2c(FAR const char *devpath, FAR struct i2c_master_s *i2c)
priv->altitude_comp = SCD41_DEFAULT_ALTITUDE_COMPENSATION;
priv->temperature_offset = SCD41_DEFAULT_TEMPERATURE_OFFSET;
nxsem_init(&priv->devsem, 0, 1);
nxmutex_init(&priv->devlock);
/* Register the character driver */