fix(linux): prevent build error on MacOS and optimize buffer usage on Linux

pull/13338/head
Jakob Hasse 2024-02-22 11:49:47 +08:00
rodzic 293f529cd7
commit f9c9e18bca
2 zmienionych plików z 13 dodań i 4 usunięć

Wyświetl plik

@ -107,7 +107,11 @@
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <stdio_ext.h>
#if !CONFIG_IDF_TARGET_LINUX
// On Linux, we don't need __fbufsize (see comments below), and
// __fbufsize not available on MacOS (which is also considered "Linux" target)
#include <stdio_ext.h> // for __fbufsize
#endif
#include <errno.h>
#include <string.h>
#include <stdlib.h>
@ -216,9 +220,14 @@ bool linenoiseIsDumbMode(void) {
}
static void flushWrite(void) {
// On Linux, we set stdout to unbuffered mode to facilitate interaction with tools.
// Performance on Linux is not considered as critical as on chip targets. Additionally,
// MacOS does not have __fbufsize.
#if !CONFIG_IDF_TARGET_LINUX
if (__fbufsize(stdout) > 0) {
fflush(stdout);
}
#endif
fsync(fileno(stdout));
}

Wyświetl plik

@ -50,9 +50,9 @@ static void main_task(void* args)
int main(int argc, const char **argv)
{
// This makes sure that stdio is flushed after each '\n' so that idf.py monitor
// reads the program output on time.
setvbuf(stdout, NULL, _IOLBF, 0);
// This makes sure that stdio is always syncronized so that idf.py monitor
// and other tools read text output on time.
setvbuf(stdout, NULL, _IONBF, 0);
usleep(1000);
BaseType_t res = xTaskCreatePinnedToCore(&main_task, "main",