You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2023/08/12 15:32:44 UTC

[nuttx] branch master updated: drivers/input: rm sched_[un]lock

This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new c712a00620 drivers/input: rm sched_[un]lock
c712a00620 is described below

commit c712a00620e8b05c3289b2ba41234993a2dc356d
Author: hujun5 <hu...@xiaomi.com>
AuthorDate: Wed Aug 9 15:02:54 2023 +0800

    drivers/input: rm sched_[un]lock
    
    We use enter_critical_section to protect the read and write of priv structures,
    sched_lock is mainly used to prevent active context switching caused by nxsem_post.
    We do not actively switch contexts when reading and writing priv structures,
    so sched_lock can be removed.
    
    Signed-off-by: hujun5 <hu...@xiaomi.com>
---
 drivers/input/ads7843e.c     |  9 ---------
 drivers/input/ft5x06.c       | 13 -------------
 drivers/input/max11802.c     |  9 ---------
 drivers/input/mxt.c          |  7 -------
 drivers/input/stmpe811_tsc.c | 17 +++++++++++------
 drivers/input/tsc2007.c      | 14 +++++---------
 6 files changed, 16 insertions(+), 53 deletions(-)

diff --git a/drivers/input/ads7843e.c b/drivers/input/ads7843e.c
index cd308955e7..10fed4eac2 100644
--- a/drivers/input/ads7843e.c
+++ b/drivers/input/ads7843e.c
@@ -372,7 +372,6 @@ static int ads7843e_waitsample(FAR struct ads7843e_dev_s *priv,
    * from getting control while we muck with the semaphores.
    */
 
-  sched_lock();
   flags = enter_critical_section();
 
   /* Now release the semaphore that manages mutually exclusive access to
@@ -418,14 +417,6 @@ errout:
    */
 
   leave_critical_section(flags);
-
-  /* Restore pre-emption.  We might get suspended here but that is okay
-   * because we already have our sample.  Note:  this means that if there
-   * were two threads reading from the ADS7843E for some reason, the data
-   * might be read out of order.
-   */
-
-  sched_unlock();
   return ret;
 }
 
diff --git a/drivers/input/ft5x06.c b/drivers/input/ft5x06.c
index 54972ac887..fc491b4b22 100644
--- a/drivers/input/ft5x06.c
+++ b/drivers/input/ft5x06.c
@@ -606,12 +606,6 @@ static ssize_t ft5x06_waitsample(FAR struct ft5x06_dev_s *priv,
 {
   int ret;
 
-  /* Disable pre-emption to prevent other threads from getting control while
-   * we muck with the semaphores.
-   */
-
-  sched_lock();
-
   /* Now release the semaphore that manages mutually exclusive access to
    * the device structure.  This may cause other tasks to become ready to
    * run, but they cannot run yet because pre-emption is disabled.
@@ -659,13 +653,6 @@ static ssize_t ft5x06_waitsample(FAR struct ft5x06_dev_s *priv,
     }
 
 errout:
-  /* Restore pre-emption.  We might get suspended here but that is okay
-   * because we already have our sample.  Note:  this means that if there
-   * were two threads reading from the FT5x06 for some reason, the data
-   * might be read out of order.
-   */
-
-  sched_unlock();
   return ret;
 }
 
diff --git a/drivers/input/max11802.c b/drivers/input/max11802.c
index e6e9ce1411..f3af7f6f25 100644
--- a/drivers/input/max11802.c
+++ b/drivers/input/max11802.c
@@ -329,7 +329,6 @@ static int max11802_waitsample(FAR struct max11802_dev_s *priv,
    * from getting control while we muck with the semaphores.
    */
 
-  sched_lock();
   flags = enter_critical_section();
 
   /* Now release the semaphore that manages mutually exclusive access to
@@ -375,14 +374,6 @@ errout:
    */
 
   leave_critical_section(flags);
-
-  /* Restore pre-emption.  We might get suspended here but that is okay
-   * because we already have our sample.  Note:  this means that if there
-   * were two threads reading from the MAX11802 for some reason, the data
-   * might be read out of order.
-   */
-
-  sched_unlock();
   return ret;
 }
 
diff --git a/drivers/input/mxt.c b/drivers/input/mxt.c
index ca7620a46c..8354dac347 100644
--- a/drivers/input/mxt.c
+++ b/drivers/input/mxt.c
@@ -1264,12 +1264,6 @@ static ssize_t mxt_read(FAR struct file *filep, FAR char *buffer, size_t len)
       return ret;
     }
 
-  /* Locking the scheduler will prevent the worker thread from running
-   * until we finish here.
-   */
-
-  sched_lock();
-
   /* Try to read sample data. */
 
   ret = mxt_checksample(priv);
@@ -1455,7 +1449,6 @@ static ssize_t mxt_read(FAR struct file *filep, FAR char *buffer, size_t len)
   ret = samplesize;
 
 errout:
-  sched_unlock();
   nxmutex_unlock(&priv->devlock);
   return ret;
 }
diff --git a/drivers/input/stmpe811_tsc.c b/drivers/input/stmpe811_tsc.c
index 364b349499..ebe023d155 100644
--- a/drivers/input/stmpe811_tsc.c
+++ b/drivers/input/stmpe811_tsc.c
@@ -239,12 +239,13 @@ static inline int stmpe811_waitsample(FAR struct stmpe811_dev_s *priv,
                                       FAR struct stmpe811_sample_s *sample)
 {
   int ret;
+  irqstate_t flags;
 
   /* Disable pre-emption to prevent the worker thread from running
    * asynchronously.
    */
 
-  sched_lock();
+  flags = enter_critical_section();
 
   /* Now release the semaphore that manages mutually exclusive access to
    * the device structure.  This may cause other tasks to become ready to
@@ -282,13 +283,12 @@ static inline int stmpe811_waitsample(FAR struct stmpe811_dev_s *priv,
   ret = nxmutex_lock(&priv->lock);
 
 errout:
-  /* Restore pre-emption.  We might get suspended here but that is okay
-   * because we already have our sample.  Note:  this means that if there
-   * were two threads reading from the STMPE811 for some reason, the data
-   * might be read out of order.
+  /* Then re-enable interrupts.  We might get interrupt here and there
+   * could be a new sample.  But no new threads will run because we still
+   * have pre-emption disabled.
    */
 
-  sched_unlock();
+  leave_critical_section(flags);
   return ret;
 }
 
@@ -955,6 +955,10 @@ void stmpe811_tscworker(FAR struct stmpe811_dev_s *priv, uint8_t intsta)
 
   pendown = !!(stmpe811_getreg8(priv, STMPE811_TSC_CTRL) & TSC_CTRL_TSC_STA);
 
+  /* Get exclusive access to the driver data structure */
+
+  nxmutex_lock(&priv->lock);
+
   /* Handle the change from pen down to pen up */
 
   if (!pendown)
@@ -1089,6 +1093,7 @@ void stmpe811_tscworker(FAR struct stmpe811_dev_s *priv, uint8_t intsta)
    */
 
 ignored:
+  nxmutex_unlock(&priv->lock);
   if (priv->sample.contact == CONTACT_DOWN ||
       priv->sample.contact == CONTACT_MOVE)
     {
diff --git a/drivers/input/tsc2007.c b/drivers/input/tsc2007.c
index 6f72af4a74..a6a7bd57e3 100644
--- a/drivers/input/tsc2007.c
+++ b/drivers/input/tsc2007.c
@@ -331,7 +331,6 @@ static int tsc2007_waitsample(FAR struct tsc2007_dev_s *priv,
    * from getting control while we muck with the semaphores.
    */
 
-  sched_lock();
   flags = enter_critical_section();
 
   /* Now release the semaphore that manages mutually exclusive access to
@@ -374,14 +373,6 @@ errout:
    */
 
   leave_critical_section(flags);
-
-  /* Restore pre-emption.  We might get suspended here but that is okay
-   * because we already have our sample.  Note:  this means that if there
-   * were two threads reading from the TSC2007 for some reason, the data
-   * might be read out of order.
-   */
-
-  sched_unlock();
   return ret;
 }
 
@@ -541,6 +532,10 @@ static void tsc2007_worker(FAR void *arg)
 
   DEBUGASSERT(priv != NULL);
 
+  /* Get exclusive access to the driver data structure */
+
+  nxmutex_lock(&priv->devlock);
+
   /* Get a pointer the callbacks for convenience (and so the code is not so
    * ugly).
    */
@@ -715,6 +710,7 @@ static void tsc2007_worker(FAR void *arg)
 
 errout:
   config->enable(config, true);
+  nxmutex_unlock(&priv->devlock);
 }
 
 /****************************************************************************