Skip to content

Commit 6a87084

Browse files
committed
extmod/utime_mphal: Add MP_THREAD_GIL_EXIT/ENTER warppers for sleep functions.
Ported from unix port.
1 parent 99ed0f2 commit 6a87084

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

extmod/utime_mphal.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,27 @@
3333
#include "py/obj.h"
3434
#include "py/mphal.h"
3535
#include "py/smallint.h"
36+
#include "py/runtime.h"
3637
#include "extmod/utime_mphal.h"
3738

3839
STATIC mp_obj_t time_sleep(mp_obj_t seconds_o) {
40+
MP_THREAD_GIL_EXIT();
3941
#if MICROPY_PY_BUILTINS_FLOAT
4042
mp_hal_delay_ms(1000 * mp_obj_get_float(seconds_o));
4143
#else
4244
mp_hal_delay_ms(1000 * mp_obj_get_int(seconds_o));
4345
#endif
46+
MP_THREAD_GIL_ENTER();
4447
return mp_const_none;
4548
}
4649
MP_DEFINE_CONST_FUN_OBJ_1(mp_utime_sleep_obj, time_sleep);
4750

4851
STATIC mp_obj_t time_sleep_ms(mp_obj_t arg) {
4952
mp_int_t ms = mp_obj_get_int(arg);
5053
if (ms > 0) {
54+
MP_THREAD_GIL_EXIT();
5155
mp_hal_delay_ms(ms);
56+
MP_THREAD_GIL_ENTER();
5257
}
5358
return mp_const_none;
5459
}
@@ -57,7 +62,9 @@ MP_DEFINE_CONST_FUN_OBJ_1(mp_utime_sleep_ms_obj, time_sleep_ms);
5762
STATIC mp_obj_t time_sleep_us(mp_obj_t arg) {
5863
mp_int_t us = mp_obj_get_int(arg);
5964
if (us > 0) {
65+
MP_THREAD_GIL_EXIT();
6066
mp_hal_delay_us(us);
67+
MP_THREAD_GIL_ENTER();
6168
}
6269
return mp_const_none;
6370
}

0 commit comments

Comments
 (0)