graphics/nxterm: Use small lock to protect resource in graphics.

Use small lock to protect resource in graphics.

Signed-off-by: wangzhi16 <wangzhi16@xiaomi.com>
This commit is contained in:
wangzhi16
2025-03-05 10:45:27 +08:00
committed by archer
parent 4fa66a6850
commit 6fc2d010a6
3 changed files with 14 additions and 10 deletions

View File

@@ -32,6 +32,7 @@
#include <stdint.h> #include <stdint.h>
#include <nuttx/mutex.h> #include <nuttx/mutex.h>
#include <nuttx/spinlock.h>
#include <nuttx/fs/fs.h> #include <nuttx/fs/fs.h>
#include <nuttx/nx/nx.h> #include <nuttx/nx/nx.h>
#include <nuttx/nx/nxtk.h> #include <nuttx/nx/nxtk.h>
@@ -161,6 +162,10 @@ struct nxterm_state_s
FAR struct pollfd *fds[CONFIG_NXTERM_NPOLLWAITERS]; FAR struct pollfd *fds[CONFIG_NXTERM_NPOLLWAITERS];
#endif /* CONFIG_NXTERM_NXKBDIN */ #endif /* CONFIG_NXTERM_NXKBDIN */
/* Spinlock */
spinlock_t spinlock;
}; };
/**************************************************************************** /****************************************************************************

View File

@@ -34,7 +34,7 @@
#include <errno.h> #include <errno.h>
#include <debug.h> #include <debug.h>
#include <nuttx/irq.h> #include <nuttx/spinlock.h>
#include "nxterm.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 */ /* 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); 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 inode *inode = filep->f_inode;
FAR struct nxterm_state_s *priv; FAR struct nxterm_state_s *priv;
pollevent_t eventset; pollevent_t eventset;
spinlock_t flags;
int ret; int ret;
int i; 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 */ /* Get exclusive access to the driver structure */
ret = nxmutex_lock(&priv->lock); flags = spin_lock_irqsave_nopreempt(&priv->spinlock);
if (ret < 0)
{
gerr("ERROR: nxmutex_lock failed\n");
return ret;
}
/* Are we setting up the poll? Or tearing it down? */ /* 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: errout:
nxmutex_unlock(&priv->lock); spin_unlock_irqrestore_nopreempt(&priv->spinlock, flags);
return ret; return ret;
} }

View File

@@ -36,6 +36,7 @@
#include <nuttx/kmalloc.h> #include <nuttx/kmalloc.h>
#include <nuttx/fs/fs.h> #include <nuttx/fs/fs.h>
#include <nuttx/spinlock.h>
#include "nxterm.h" #include "nxterm.h"
@@ -85,6 +86,8 @@ FAR struct nxterm_state_s *
nxsem_init(&priv->waitsem, 0, 0); nxsem_init(&priv->waitsem, 0, 0);
#endif #endif
spin_lock_init(&priv->spinlock);
/* Connect to the font cache for the configured font characteristics */ /* Connect to the font cache for the configured font characteristics */
priv->fcache = nxf_cache_connect(wndo->fontid, wndo->fcolor[0], priv->fcache = nxf_cache_connect(wndo->fontid, wndo->fcolor[0],