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

View file

@ -41,7 +41,7 @@
#include <nuttx/arch.h>
#include <nuttx/fs/fs.h>
#include <nuttx/audio/audio.h>
#include <nuttx/semaphore.h>
#include <nuttx/mutex.h>
#include <arch/irq.h>
@ -73,7 +73,7 @@ struct audio_upperhalf_s
{
uint8_t crefs; /* The number of times the device has been opened */
volatile bool started; /* True: playback is active */
sem_t exclsem; /* Supports mutual exclusion */
mutex_t lock; /* Supports mutual exclusion */
FAR struct audio_lowerhalf_s *dev; /* lower-half state */
struct file *usermq; /* User mode app's message queue */
};
@ -150,7 +150,7 @@ static int audio_open(FAR struct file *filep)
/* Get exclusive access to the device structures */
ret = nxsem_wait(&upper->exclsem);
ret = nxmutex_lock(&upper->lock);
if (ret < 0)
{
goto errout;
@ -167,7 +167,7 @@ static int audio_open(FAR struct file *filep)
/* More than 255 opens; uint8_t overflows to zero */
ret = -EMFILE;
goto errout_with_sem;
goto errout_with_lock;
}
/* Save the new open count on success */
@ -175,8 +175,8 @@ static int audio_open(FAR struct file *filep)
upper->crefs = tmp;
ret = OK;
errout_with_sem:
nxsem_post(&upper->exclsem);
errout_with_lock:
nxmutex_unlock(&upper->lock);
errout:
return ret;
@ -200,7 +200,7 @@ static int audio_close(FAR struct file *filep)
/* Get exclusive access to the device structures */
ret = nxsem_wait(&upper->exclsem);
ret = nxmutex_lock(&upper->lock);
if (ret < 0)
{
goto errout;
@ -232,8 +232,7 @@ static int audio_close(FAR struct file *filep)
}
ret = OK;
nxsem_post(&upper->exclsem);
nxmutex_unlock(&upper->lock);
errout:
return ret;
@ -365,7 +364,7 @@ static int audio_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
/* Get exclusive access to the device structures */
ret = nxsem_wait(&upper->exclsem);
ret = nxmutex_lock(&upper->lock);
if (ret < 0)
{
return ret;
@ -664,7 +663,7 @@ static int audio_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
break;
}
nxsem_post(&upper->exclsem);
nxmutex_unlock(&upper->lock);
return ret;
}
@ -947,7 +946,7 @@ int audio_register(FAR const char *name, FAR struct audio_lowerhalf_s *dev)
* (it was already zeroed by kmm_zalloc())
*/
nxsem_init(&upper->exclsem, 0, 1);
nxmutex_init(&upper->lock);
upper->dev = dev;
#ifdef CONFIG_AUDIO_CUSTOM_DEV_PATH