Skip to content
Snippets Groups Projects
Commit 94d2919b authored by Damien George's avatar Damien George
Browse files

unix/modtime: Release the GIL when sleeping.

parent c567afc5
No related branches found
No related tags found
No related merge requests found
...@@ -121,7 +121,9 @@ STATIC mp_obj_t mod_time_sleep(mp_obj_t arg) { ...@@ -121,7 +121,9 @@ STATIC mp_obj_t mod_time_sleep(mp_obj_t arg) {
tv.tv_sec = ipart; tv.tv_sec = ipart;
int res; int res;
while (1) { while (1) {
MP_THREAD_GIL_EXIT();
res = sleep_select(0, NULL, NULL, NULL, &tv); res = sleep_select(0, NULL, NULL, NULL, &tv);
MP_THREAD_GIL_ENTER();
#if MICROPY_SELECT_REMAINING_TIME #if MICROPY_SELECT_REMAINING_TIME
// TODO: This assumes Linux behavior of modifying tv to the remaining // TODO: This assumes Linux behavior of modifying tv to the remaining
// time. // time.
...@@ -139,20 +141,26 @@ STATIC mp_obj_t mod_time_sleep(mp_obj_t arg) { ...@@ -139,20 +141,26 @@ STATIC mp_obj_t mod_time_sleep(mp_obj_t arg) {
RAISE_ERRNO(res, errno); RAISE_ERRNO(res, errno);
#else #else
// TODO: Handle EINTR // TODO: Handle EINTR
MP_THREAD_GIL_EXIT();
sleep(mp_obj_get_int(arg)); sleep(mp_obj_get_int(arg));
MP_THREAD_GIL_ENTER();
#endif #endif
return mp_const_none; return mp_const_none;
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_time_sleep_obj, mod_time_sleep); STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_time_sleep_obj, mod_time_sleep);
STATIC mp_obj_t mod_time_sleep_ms(mp_obj_t arg) { STATIC mp_obj_t mod_time_sleep_ms(mp_obj_t arg) {
MP_THREAD_GIL_EXIT();
usleep(mp_obj_get_int(arg) * 1000); usleep(mp_obj_get_int(arg) * 1000);
MP_THREAD_GIL_ENTER();
return mp_const_none; return mp_const_none;
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_time_sleep_ms_obj, mod_time_sleep_ms); STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_time_sleep_ms_obj, mod_time_sleep_ms);
STATIC mp_obj_t mod_time_sleep_us(mp_obj_t arg) { STATIC mp_obj_t mod_time_sleep_us(mp_obj_t arg) {
MP_THREAD_GIL_EXIT();
usleep(mp_obj_get_int(arg)); usleep(mp_obj_get_int(arg));
MP_THREAD_GIL_ENTER();
return mp_const_none; return mp_const_none;
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_time_sleep_us_obj, mod_time_sleep_us); STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_time_sleep_us_obj, mod_time_sleep_us);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment