1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-18 12:52:44 +01:00

picolibc: make stdout buffering optional

This commit is contained in:
Benjamin Valentin 2020-08-24 18:28:30 +02:00
parent f3e1032f6e
commit ea27064d21
2 changed files with 26 additions and 3 deletions

View File

@ -86,6 +86,7 @@ PSEUDOMODULES += newlib_gnu_source
PSEUDOMODULES += newlib_nano PSEUDOMODULES += newlib_nano
PSEUDOMODULES += openthread PSEUDOMODULES += openthread
PSEUDOMODULES += picolibc PSEUDOMODULES += picolibc
PSEUDOMODULES += picolibc_stdout_buffered
PSEUDOMODULES += pktqueue PSEUDOMODULES += pktqueue
PSEUDOMODULES += posix_headers PSEUDOMODULES += posix_headers
PSEUDOMODULES += printf_float PSEUDOMODULES += printf_float

View File

@ -63,10 +63,12 @@ int kill(pid_t pid, int sig)
#include "mutex.h" #include "mutex.h"
static mutex_t picolibc_put_mutex = MUTEX_INIT; #ifndef PICOLIBC_STDOUT_BUFSIZE
#define PICOLIBC_STDOUT_BUFSIZE 64 #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 char picolibc_stdout[PICOLIBC_STDOUT_BUFSIZE];
static int picolibc_stdout_queued; static int picolibc_stdout_queued;
@ -81,10 +83,14 @@ static void _picolibc_flush(void)
static int picolibc_put(char c, FILE *file) static int picolibc_put(char c, FILE *file)
{ {
(void)file; (void)file;
mutex_lock(&picolibc_put_mutex); mutex_lock(&picolibc_put_mutex);
picolibc_stdout[picolibc_stdout_queued++] = c; 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(); _picolibc_flush();
}
mutex_unlock(&picolibc_put_mutex); mutex_unlock(&picolibc_put_mutex);
return 1; return 1;
} }
@ -98,6 +104,22 @@ static int picolibc_flush(FILE *file)
return 0; 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) static int picolibc_get(FILE *file)
{ {
(void)file; (void)file;