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 1a65f5ed88 sched_lock refine: remove sched_[un]lock in xxx_waitsample 1a65f5ed88 is described below commit 1a65f5ed88c55dcb380c91594a6e3f68e2d775e8 Author: hujun5 <huj...@xiaomi.com> AuthorDate: Tue Sep 26 20:37:09 2023 +0800 sched_lock refine: remove sched_[un]lock in xxx_waitsample Signed-off-by: hujun5 <huj...@xiaomi.com> --- arch/arm/src/sama5/sam_tsd.c | 12 ------------ boards/arm/stm32/mikroe-stm32f4/src/stm32_touchscreen.c | 17 +++++++++-------- boards/mips/pic32mx/pic32mx7mmb/src/pic32_touchscreen.c | 16 ++++++++-------- drivers/usbhost/usbhost_hidmouse.c | 12 ------------ drivers/usbhost/usbhost_xboxcontroller.c | 12 ------------ 5 files changed, 17 insertions(+), 52 deletions(-) diff --git a/arch/arm/src/sama5/sam_tsd.c b/arch/arm/src/sama5/sam_tsd.c index de2cae1af3..a9fa465515 100644 --- a/arch/arm/src/sama5/sam_tsd.c +++ b/arch/arm/src/sama5/sam_tsd.c @@ -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 @@ -408,14 +404,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 touchscreen ADC for some reason, the - * data might be read out of order. - */ - - sched_unlock(); return ret; } diff --git a/boards/arm/stm32/mikroe-stm32f4/src/stm32_touchscreen.c b/boards/arm/stm32/mikroe-stm32f4/src/stm32_touchscreen.c index 45b6f69acc..ea2a82a221 100644 --- a/boards/arm/stm32/mikroe-stm32f4/src/stm32_touchscreen.c +++ b/boards/arm/stm32/mikroe-stm32f4/src/stm32_touchscreen.c @@ -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 @@ -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; } diff --git a/boards/mips/pic32mx/pic32mx7mmb/src/pic32_touchscreen.c b/boards/mips/pic32mx/pic32mx7mmb/src/pic32_touchscreen.c index 3dcb992b23..becb9bb45d 100644 --- a/boards/mips/pic32mx/pic32mx7mmb/src/pic32_touchscreen.c +++ b/boards/mips/pic32mx/pic32mx7mmb/src/pic32_touchscreen.c @@ -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 @@ -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; } diff --git a/drivers/usbhost/usbhost_hidmouse.c b/drivers/usbhost/usbhost_hidmouse.c index d325719e79..6b6f824cd8 100644 --- a/drivers/usbhost/usbhost_hidmouse.c +++ b/drivers/usbhost/usbhost_hidmouse.c @@ -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 @@ -1322,14 +1318,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 HIDMOUSE for some reason, the data - * might be read out of order. - */ - - sched_unlock(); return ret; } diff --git a/drivers/usbhost/usbhost_xboxcontroller.c b/drivers/usbhost/usbhost_xboxcontroller.c index 4de0f405bf..cc89ce1cec 100644 --- a/drivers/usbhost/usbhost_xboxcontroller.c +++ b/drivers/usbhost/usbhost_xboxcontroller.c @@ -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 @@ -1019,14 +1015,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 HIDMOUSE for some reason, the data - * might be read out of order. - */ - - sched_unlock(); return ret; }