wm8776: use small lock in drivers/audio/wm8776.c

reason:
We hope to remove all instances of spin_lock_irqsave(NULL).

Signed-off-by: hujun5 <hujun5@xiaomi.com>
This commit is contained in:
hujun5
2024-12-05 19:41:14 +08:00
committed by Xiang Xiao
parent 617fee66ff
commit 1ab1dbc0f0
2 changed files with 10 additions and 8 deletions
+8 -8
View File
@@ -494,7 +494,7 @@ static void wm8776_senddone(FAR struct i2s_dev_s *i2s,
* against that possibility. * against that possibility.
*/ */
flags = spin_lock_irqsave(NULL); flags = spin_lock_irqsave(&priv->lock);
/* Add the completed buffer to the end of our doneq. We do not yet /* Add the completed buffer to the end of our doneq. We do not yet
* decrement the reference count. * decrement the reference count.
@@ -512,7 +512,7 @@ static void wm8776_senddone(FAR struct i2s_dev_s *i2s,
/* REVISIT: This can be overwritten */ /* REVISIT: This can be overwritten */
priv->result = result; priv->result = result;
spin_unlock_irqrestore(NULL, flags); spin_unlock_irqrestore(&priv->lock, flags);
/* Now send a message to the worker thread, informing it that there are /* Now send a message to the worker thread, informing it that there are
* buffers in the done queue that need to be cleaned up. * buffers in the done queue that need to be cleaned up.
@@ -547,13 +547,13 @@ static void wm8776_returnbuffers(FAR struct wm8776_dev_s *priv)
* use interrupt controls to protect against that possibility. * use interrupt controls to protect against that possibility.
*/ */
flags = spin_lock_irqsave(NULL); flags = spin_lock_irqsave(&priv->lock);
while (dq_peek(&priv->doneq) != NULL) while (dq_peek(&priv->doneq) != NULL)
{ {
/* Take the next buffer from the queue of completed transfers */ /* Take the next buffer from the queue of completed transfers */
apb = (FAR struct ap_buffer_s *)dq_remfirst(&priv->doneq); apb = (FAR struct ap_buffer_s *)dq_remfirst(&priv->doneq);
spin_unlock_irqrestore(NULL, flags); spin_unlock_irqrestore(&priv->lock, flags);
audinfo("Returning: apb=%p curbyte=%d nbytes=%d flags=%04x\n", audinfo("Returning: apb=%p curbyte=%d nbytes=%d flags=%04x\n",
apb, apb->curbyte, apb->nbytes, apb->flags); apb, apb->curbyte, apb->nbytes, apb->flags);
@@ -588,10 +588,10 @@ static void wm8776_returnbuffers(FAR struct wm8776_dev_s *priv)
#else #else
priv->dev.upper(priv->dev.priv, AUDIO_CALLBACK_DEQUEUE, apb, OK); priv->dev.upper(priv->dev.priv, AUDIO_CALLBACK_DEQUEUE, apb, OK);
#endif #endif
flags = spin_lock_irqsave(NULL); flags = spin_lock_irqsave(&priv->lock);
} }
spin_unlock_irqrestore(NULL, flags); spin_unlock_irqrestore(&priv->lock, flags);
} }
/**************************************************************************** /****************************************************************************
@@ -644,9 +644,9 @@ static int wm8776_sendbuffer(FAR struct wm8776_dev_s *priv)
* to avoid a possible race condition. * to avoid a possible race condition.
*/ */
flags = spin_lock_irqsave(NULL); flags = spin_lock_irqsave(&priv->lock);
priv->inflight++; priv->inflight++;
spin_unlock_irqrestore(NULL, flags); spin_unlock_irqrestore(&priv->lock, flags);
shift = (priv->bpsamp == 8) ? 14 - 3 : 14 - 4; shift = (priv->bpsamp == 8) ? 14 - 3 : 14 - 4;
shift -= (priv->nchannels > 1) ? 1 : 0; shift -= (priv->nchannels > 1) ? 1 : 0;
+2
View File
@@ -36,6 +36,7 @@
#include <nuttx/mutex.h> #include <nuttx/mutex.h>
#include <nuttx/wqueue.h> #include <nuttx/wqueue.h>
#include <nuttx/fs/ioctl.h> #include <nuttx/fs/ioctl.h>
#include <nuttx/spinlock_type.h>
#ifdef CONFIG_AUDIO #ifdef CONFIG_AUDIO
@@ -107,6 +108,7 @@ struct wm8776_dev_s
#endif #endif
bool reserved; /* True: Device is reserved */ bool reserved; /* True: Device is reserved */
volatile int result; /* The result of the last transfer */ volatile int result; /* The result of the last transfer */
spinlock_t lock; /* Spinlock */
}; };
#endif /* CONFIG_AUDIO */ #endif /* CONFIG_AUDIO */