Skip to content

Commit

Permalink
sched_lock refine: remove sched_[un]lock in xxx_waitsample
Browse files Browse the repository at this point in the history
Signed-off-by: hujun5 <[email protected]>
  • Loading branch information
hujun260 committed Nov 21, 2023
1 parent 11b3adf commit 8ae64ca
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 52 deletions.
12 changes: 0 additions & 12 deletions arch/arm/src/sama5/sam_tsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -357,12 +357,8 @@ static int sam_tsd_waitsample(struct sam_tsd_s *priv,
/* Interrupts must be disabled when this is called to (1) prevent posting
* of semaphores from interrupt handlers, and (2) to prevent sampled data
* from changing until it has been reported.
*
* In addition, we will also disable pre-emption to prevent other threads
* 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 @@ -408,14 +404,6 @@ static int sam_tsd_waitsample(struct sam_tsd_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 touchscreen ADC for some reason, the
* data might be read out of order.
*/

sched_unlock();
return ret;
}

Expand Down
17 changes: 9 additions & 8 deletions boards/arm/stm32/mikroe-stm32f4/src/stm32_touchscreen.c
Original file line number Diff line number Diff line change
Expand Up @@ -666,12 +666,14 @@ static int tc_waitsample(struct tc_dev_s *priv,
struct tc_sample_s *sample)
{
int ret;
irqstate_t flags;

/* Pre-emption must be disabled when this is called to prevent sampled
* data from changing until it has been reported.
/* Interrupts must be disabled when this is called to (1) prevent posting
* of semaphores from interrupt handlers, and (2) to prevent sampled data
* from changing until it has been reported.
*/

sched_lock();
flags = enter_critical_section();

/* Now release the mutex that manages mutually exclusive access to
* the device structure. This may cause other tasks to become ready to
Expand Down Expand Up @@ -706,13 +708,12 @@ static int tc_waitsample(struct tc_dev_s *priv,
ret = nxmutex_lock(&priv->devlock);

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 touchscreen 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
16 changes: 8 additions & 8 deletions boards/mips/pic32mx/pic32mx7mmb/src/pic32_touchscreen.c
Original file line number Diff line number Diff line change
Expand Up @@ -556,11 +556,12 @@ static int tc_waitsample(struct tc_dev_s *priv,
{
int ret;

/* Pre-emption must be disabled when this is called to prevent sampled
* data from changing until it has been reported.
/* Interrupts must be disabled when this is called to (1) prevent posting
* of semaphores from interrupt handlers, and (2) to prevent sampled data
* from changing until it has been reported.
*/

sched_lock();
flags = enter_critical_section();

/* Now release the mutex that manages mutually exclusive access to
* the device structure. This may cause other tasks to become ready to
Expand Down Expand Up @@ -595,13 +596,12 @@ static int tc_waitsample(struct tc_dev_s *priv,
ret = nxmutex_lock(&priv->devlock);

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 touchscreen 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
12 changes: 0 additions & 12 deletions drivers/usbhost/usbhost_hidmouse.c
Original file line number Diff line number Diff line change
Expand Up @@ -1263,12 +1263,8 @@ static int usbhost_waitsample(FAR struct usbhost_state_s *priv,
/* Interrupts must be disabled when this is called to (1) prevent posting
* of semaphores from interrupt handlers, and (2) to prevent sampled data
* from changing until it has been reported.
*
* In addition, we will also disable pre-emption to prevent other threads
* 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 @@ -1322,14 +1318,6 @@ static int usbhost_waitsample(FAR struct usbhost_state_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 HIDMOUSE for some reason, the data
* might be read out of order.
*/

sched_unlock();
return ret;
}

Expand Down
12 changes: 0 additions & 12 deletions drivers/usbhost/usbhost_xboxcontroller.c
Original file line number Diff line number Diff line change
Expand Up @@ -960,12 +960,8 @@ static int usbhost_waitsample(FAR struct usbhost_state_s *priv,
/* Interrupts must be disabled when this is called to (1) prevent posting
* of semaphores from interrupt handlers, and (2) to prevent sampled data
* from changing until it has been reported.
*
* In addition, we will also disable pre-emption to prevent other threads
* 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 @@ -1019,14 +1015,6 @@ static int usbhost_waitsample(FAR struct usbhost_state_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 HIDMOUSE for some reason, the data
* might be read out of order.
*/

sched_unlock();
return ret;
}

Expand Down

0 comments on commit 8ae64ca

Please sign in to comment.