mirror of
https://github.com/0xFEEDC0DE64/arduino-esp32.git
synced 2025-07-29 10:17:15 +02:00
optimize log facility for multi threading
- Shorten filenames - Add log_printf with mutex locking to play nice with Serial and two cores
This commit is contained in:
@ -358,5 +358,38 @@ int uartGetDebug()
|
||||
return s_uart_debug_nr;
|
||||
}
|
||||
|
||||
|
||||
int log_printf(const char *format, ...)
|
||||
{
|
||||
if(s_uart_debug_nr < 0){
|
||||
return 0;
|
||||
}
|
||||
char loc_buf[64];
|
||||
char * temp = loc_buf;
|
||||
int len;
|
||||
va_list arg;
|
||||
va_list copy;
|
||||
va_start(arg, format);
|
||||
va_copy(copy, arg);
|
||||
len = vsnprintf(NULL, 0, format, arg);
|
||||
va_end(copy);
|
||||
if(len >= sizeof(loc_buf)){
|
||||
temp = (char*)malloc(len+1);
|
||||
if(temp == NULL) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
vsnprintf(temp, len+1, format, arg);
|
||||
if(_uart_bus_array[s_uart_debug_nr].lock){
|
||||
while (xSemaphoreTake(_uart_bus_array[s_uart_debug_nr].lock, portMAX_DELAY) != pdPASS);
|
||||
ets_printf("%s", temp);
|
||||
xSemaphoreGive(_uart_bus_array[s_uart_debug_nr].lock);
|
||||
} else {
|
||||
ets_printf("%s", temp);
|
||||
}
|
||||
va_end(arg);
|
||||
if(len > 64){
|
||||
free(temp);
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user