Skip to content

Commit 2e3fc77

Browse files
committed
extmod/utime_mphal: Don't exit/enter the GIL in generic sleep functions.
GIL behaviour should be handled by the port. And ports probably want to define sleep_us so that it doesn't release the GIL, to improve timing accuracy.
1 parent 96c35d0 commit 2e3fc77

1 file changed

Lines changed: 0 additions & 6 deletions

File tree

extmod/utime_mphal.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,23 +37,19 @@
3737
#include "extmod/utime_mphal.h"
3838

3939
STATIC mp_obj_t time_sleep(mp_obj_t seconds_o) {
40-
MP_THREAD_GIL_EXIT();
4140
#if MICROPY_PY_BUILTINS_FLOAT
4241
mp_hal_delay_ms(1000 * mp_obj_get_float(seconds_o));
4342
#else
4443
mp_hal_delay_ms(1000 * mp_obj_get_int(seconds_o));
4544
#endif
46-
MP_THREAD_GIL_ENTER();
4745
return mp_const_none;
4846
}
4947
MP_DEFINE_CONST_FUN_OBJ_1(mp_utime_sleep_obj, time_sleep);
5048

5149
STATIC mp_obj_t time_sleep_ms(mp_obj_t arg) {
5250
mp_int_t ms = mp_obj_get_int(arg);
5351
if (ms > 0) {
54-
MP_THREAD_GIL_EXIT();
5552
mp_hal_delay_ms(ms);
56-
MP_THREAD_GIL_ENTER();
5753
}
5854
return mp_const_none;
5955
}
@@ -62,9 +58,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(mp_utime_sleep_ms_obj, time_sleep_ms);
6258
STATIC mp_obj_t time_sleep_us(mp_obj_t arg) {
6359
mp_int_t us = mp_obj_get_int(arg);
6460
if (us > 0) {
65-
MP_THREAD_GIL_EXIT();
6661
mp_hal_delay_us(us);
67-
MP_THREAD_GIL_ENTER();
6862
}
6963
return mp_const_none;
7064
}

0 commit comments

Comments
 (0)