mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
picolibc: make stdout buffering optional
This commit is contained in:
parent
f3e1032f6e
commit
ea27064d21
@ -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
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user