Skip to content

Commit

Permalink
drivers/input: rm sched_[un]lock
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
hujun260 committed Aug 12, 2023
1 parent 73867b9 commit 9e61bfd
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 53 deletions.
9 changes: 0 additions & 9 deletions drivers/input/ads7843e.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -418,14 +417,6 @@ static int ads7843e_waitsample(FAR struct ads7843e_dev_s *priv,
*/

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;
}

Expand Down
13 changes: 0 additions & 13 deletions drivers/input/ft5x06.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}

Expand Down
9 changes: 0 additions & 9 deletions drivers/input/max11802.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -375,14 +374,6 @@ static int max11802_waitsample(FAR struct max11802_dev_s *priv,
*/

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;
}

Expand Down
7 changes: 0 additions & 7 deletions drivers/input/mxt.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down
17 changes: 11 additions & 6 deletions drivers/input/stmpe811_tsc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
{
Expand Down
14 changes: 5 additions & 9 deletions drivers/input/tsc2007.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -374,14 +373,6 @@ static int tsc2007_waitsample(FAR struct tsc2007_dev_s *priv,
*/

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;
}

Expand Down Expand Up @@ -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).
*/
Expand Down Expand Up @@ -715,6 +710,7 @@ static void tsc2007_worker(FAR void *arg)

errout:
config->enable(config, true);
nxmutex_unlock(&priv->devlock);
}

/****************************************************************************
Expand Down

0 comments on commit 9e61bfd

Please sign in to comment.