esp32/mphalport: When tx'ing to REPL only release GIL if many chars sent

Otherwise, if multiple threads are active, printing data to the REPL may be
very slow because in some cases only one character is output per call to
mp_hal_stdout_tx_strn.
This commit is contained in:
Damien George 2019-01-10 15:43:47 +11:00
parent afecc124e6
commit efe0569c26
1 changed files with 8 additions and 2 deletions

View File

@ -61,11 +61,17 @@ void mp_hal_stdout_tx_str(const char *str) {
}
void mp_hal_stdout_tx_strn(const char *str, uint32_t len) {
MP_THREAD_GIL_EXIT();
// Only release the GIL if many characters are being sent
bool release_gil = len > 20;
if (release_gil) {
MP_THREAD_GIL_EXIT();
}
for (uint32_t i = 0; i < len; ++i) {
uart_tx_one_char(str[i]);
}
MP_THREAD_GIL_ENTER();
if (release_gil) {
MP_THREAD_GIL_ENTER();
}
mp_uos_dupterm_tx_strn(str, len);
}