diff --git a/makefiles/pseudomodules.inc.mk b/makefiles/pseudomodules.inc.mk index 510e6fecd8..b444af4ef7 100644 --- a/makefiles/pseudomodules.inc.mk +++ b/makefiles/pseudomodules.inc.mk @@ -86,6 +86,7 @@ PSEUDOMODULES += newlib_gnu_source PSEUDOMODULES += newlib_nano PSEUDOMODULES += openthread PSEUDOMODULES += picolibc +PSEUDOMODULES += picolibc_stdout_buffered PSEUDOMODULES += pktqueue PSEUDOMODULES += posix_headers PSEUDOMODULES += printf_float diff --git a/sys/picolibc_syscalls_default/syscalls.c b/sys/picolibc_syscalls_default/syscalls.c index 1782610d08..48b0b903e6 100644 --- a/sys/picolibc_syscalls_default/syscalls.c +++ b/sys/picolibc_syscalls_default/syscalls.c @@ -63,10 +63,12 @@ int kill(pid_t pid, int sig) #include "mutex.h" -static mutex_t picolibc_put_mutex = MUTEX_INIT; - +#ifndef PICOLIBC_STDOUT_BUFSIZE #define PICOLIBC_STDOUT_BUFSIZE 64 +#endif +#ifdef MODULE_PICOLIBC_STDOUT_BUFFERED +static mutex_t picolibc_put_mutex = MUTEX_INIT; static char picolibc_stdout[PICOLIBC_STDOUT_BUFSIZE]; static int picolibc_stdout_queued; @@ -81,10 +83,14 @@ static void _picolibc_flush(void) static int picolibc_put(char c, FILE *file) { (void)file; + mutex_lock(&picolibc_put_mutex); picolibc_stdout[picolibc_stdout_queued++] = c; - if (picolibc_stdout_queued == PICOLIBC_STDOUT_BUFSIZE || c == '\n') + + if (picolibc_stdout_queued == PICOLIBC_STDOUT_BUFSIZE || c == '\n') { _picolibc_flush(); + } + mutex_unlock(&picolibc_put_mutex); return 1; } @@ -98,6 +104,22 @@ static int picolibc_flush(FILE *file) return 0; } +#else +int picolibc_put(char c, FILE *file) +{ + (void)file; + stdio_write(&c, 1); + return 1; +} + +static int picolibc_flush(FILE *file) +{ + (void)file; + return 0; +} + +#endif + static int picolibc_get(FILE *file) { (void)file;