Skip to content

Commit 94d2919

Browse files
committed
unix/modtime: Release the GIL when sleeping.
1 parent c567afc commit 94d2919

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

unix/modtime.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,9 @@ STATIC mp_obj_t mod_time_sleep(mp_obj_t arg) {
121121
tv.tv_sec = ipart;
122122
int res;
123123
while (1) {
124+
MP_THREAD_GIL_EXIT();
124125
res = sleep_select(0, NULL, NULL, NULL, &tv);
126+
MP_THREAD_GIL_ENTER();
125127
#if MICROPY_SELECT_REMAINING_TIME
126128
// TODO: This assumes Linux behavior of modifying tv to the remaining
127129
// time.
@@ -139,20 +141,26 @@ STATIC mp_obj_t mod_time_sleep(mp_obj_t arg) {
139141
RAISE_ERRNO(res, errno);
140142
#else
141143
// TODO: Handle EINTR
144+
MP_THREAD_GIL_EXIT();
142145
sleep(mp_obj_get_int(arg));
146+
MP_THREAD_GIL_ENTER();
143147
#endif
144148
return mp_const_none;
145149
}
146150
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_time_sleep_obj, mod_time_sleep);
147151

148152
STATIC mp_obj_t mod_time_sleep_ms(mp_obj_t arg) {
153+
MP_THREAD_GIL_EXIT();
149154
usleep(mp_obj_get_int(arg) * 1000);
155+
MP_THREAD_GIL_ENTER();
150156
return mp_const_none;
151157
}
152158
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_time_sleep_ms_obj, mod_time_sleep_ms);
153159

154160
STATIC mp_obj_t mod_time_sleep_us(mp_obj_t arg) {
161+
MP_THREAD_GIL_EXIT();
155162
usleep(mp_obj_get_int(arg));
163+
MP_THREAD_GIL_ENTER();
156164
return mp_const_none;
157165
}
158166
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_time_sleep_us_obj, mod_time_sleep_us);

0 commit comments

Comments
 (0)