This is an automated email from the ASF dual-hosted git repository. archer pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 6fc2d010a606c78c50f73eb9864bac7e922117f3 Author: wangzhi16 <[email protected]> AuthorDate: Wed Mar 5 10:45:27 2025 +0800 graphics/nxterm: Use small lock to protect resource in graphics. Use small lock to protect resource in graphics. Signed-off-by: wangzhi16 <[email protected]> --- graphics/nxterm/nxterm.h | 5 +++++ graphics/nxterm/nxterm_kbdin.c | 16 ++++++---------- graphics/nxterm/nxterm_register.c | 3 +++ 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/graphics/nxterm/nxterm.h b/graphics/nxterm/nxterm.h index 35ff3166ce9..5b77f94829d 100644 --- a/graphics/nxterm/nxterm.h +++ b/graphics/nxterm/nxterm.h @@ -32,6 +32,7 @@ #include <stdint.h> #include <nuttx/mutex.h> +#include <nuttx/spinlock.h> #include <nuttx/fs/fs.h> #include <nuttx/nx/nx.h> #include <nuttx/nx/nxtk.h> @@ -161,6 +162,10 @@ struct nxterm_state_s FAR struct pollfd *fds[CONFIG_NXTERM_NPOLLWAITERS]; #endif /* CONFIG_NXTERM_NXKBDIN */ + + /* Spinlock */ + + spinlock_t spinlock; }; /**************************************************************************** diff --git a/graphics/nxterm/nxterm_kbdin.c b/graphics/nxterm/nxterm_kbdin.c index 8021d779005..dedd47d16bc 100644 --- a/graphics/nxterm/nxterm_kbdin.c +++ b/graphics/nxterm/nxterm_kbdin.c @@ -34,7 +34,7 @@ #include <errno.h> #include <debug.h> -#include <nuttx/irq.h> +#include <nuttx/spinlock.h> #include "nxterm.h" @@ -55,9 +55,9 @@ static void nxterm_pollnotify(FAR struct nxterm_state_s *priv, /* This function may be called from an interrupt handler */ - flags = enter_critical_section(); + flags = spin_lock_irqsave_nopreempt(&priv->spinlock); poll_notify(priv->fds, CONFIG_NXTERM_NPOLLWAITERS, eventset); - leave_critical_section(flags); + spin_unlock_irqrestore_nopreempt(&priv->spinlock, flags); } /**************************************************************************** @@ -224,6 +224,7 @@ int nxterm_poll(FAR struct file *filep, FAR struct pollfd *fds, bool setup) FAR struct inode *inode = filep->f_inode; FAR struct nxterm_state_s *priv; pollevent_t eventset; + spinlock_t flags; int ret; int i; @@ -234,12 +235,7 @@ int nxterm_poll(FAR struct file *filep, FAR struct pollfd *fds, bool setup) /* Get exclusive access to the driver structure */ - ret = nxmutex_lock(&priv->lock); - if (ret < 0) - { - gerr("ERROR: nxmutex_lock failed\n"); - return ret; - } + flags = spin_lock_irqsave_nopreempt(&priv->spinlock); /* Are we setting up the poll? Or tearing it down? */ @@ -310,7 +306,7 @@ int nxterm_poll(FAR struct file *filep, FAR struct pollfd *fds, bool setup) } errout: - nxmutex_unlock(&priv->lock); + spin_unlock_irqrestore_nopreempt(&priv->spinlock, flags); return ret; } diff --git a/graphics/nxterm/nxterm_register.c b/graphics/nxterm/nxterm_register.c index f7744c18f65..830b0d7a7c8 100644 --- a/graphics/nxterm/nxterm_register.c +++ b/graphics/nxterm/nxterm_register.c @@ -36,6 +36,7 @@ #include <nuttx/kmalloc.h> #include <nuttx/fs/fs.h> +#include <nuttx/spinlock.h> #include "nxterm.h" @@ -85,6 +86,8 @@ FAR struct nxterm_state_s * nxsem_init(&priv->waitsem, 0, 0); #endif + spin_lock_init(&priv->spinlock); + /* Connect to the font cache for the configured font characteristics */ priv->fcache = nxf_cache_connect(wndo->fontid, wndo->fcolor[0],
