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 #include +#include #include #include #include @@ -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 #include -#include +#include #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 #include +#include #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],