1
0
Fork 0
mirror of https://github.com/hermitcore/libhermit.git synced 2025-03-09 00:00:03 +01:00

add IO lock to get nicer output messages

This commit is contained in:
Stefan Lankes 2016-08-02 20:30:52 +02:00
parent 72a20c766b
commit 00499bb97b
3 changed files with 19 additions and 8 deletions

View file

@ -45,6 +45,7 @@
//TODO: don't use one big kernel lock to comminicate with all proxies
static spinlock_t lwip_lock = SPINLOCK_INIT;
extern spinlock_irqsave_t stdio_lock;
extern int32_t isle;
extern int32_t possible_isles;
extern volatile int libc_sd;
@ -191,8 +192,10 @@ ssize_t sys_write(int fd, const char* buf, size_t len)
{
spinlock_unlock(&lwip_lock);
spinlock_irqsave_lock(&stdio_lock);
for(i=0; i<len; i++)
kputchar(buf[i]);
spinlock_irqsave_unlock(&stdio_lock);
return len;
}

View file

@ -45,6 +45,7 @@
*/
#include <hermit/string.h>
#include <hermit/spinlock.h>
/* HermitCore use only the 64bit version */
#define __64BIT__
@ -75,6 +76,8 @@ static char const hex2ascii_data[] = "0123456789abcdefghijklmnopqrstuvwxyz";
/* Max number conversion buffer length: a u_quad_t in base 2, plus NUL byte. */
#define MAXNBUF (sizeof(intmax_t) * NBBY + 1)
extern spinlock_irqsave_t stdio_lock;
/*
* Put a NUL-terminated ASCII number (base <= 36) in a buffer in reverse
* order; return an optional length and a pointer to the last character
@ -150,12 +153,16 @@ int kvprintf(char const *fmt, void (*func) (int, void *), void *arg, int radix,
if (radix < 2 || radix > 36)
radix = 10;
spinlock_irqsave_lock(&stdio_lock);
for (;;) {
padc = ' ';
width = 0;
while ((ch = (u_char) * fmt++) != '%' || stop) {
if (ch == '\0')
if (ch == '\0') {
spinlock_irqsave_unlock(&stdio_lock);
return (retval);
}
PCHAR(ch);
}
percent = fmt - 1;
@ -449,6 +456,9 @@ int kvprintf(char const *fmt, void (*func) (int, void *), void *arg, int radix,
break;
}
}
spinlock_irqsave_unlock(&stdio_lock);
#undef PCHAR
}

View file

@ -36,9 +36,7 @@
#include <asm/uart.h>
static atomic_int32_t kmsg_counter = ATOMIC_INIT(-1);
#ifdef CONFIG_VGA
static spinlock_irqsave_t vga_lock = SPINLOCK_IRQSAVE_INIT;
#endif
spinlock_irqsave_t stdio_lock = SPINLOCK_IRQSAVE_INIT;
/* Workaround for a compiler bug. gcc 5.1 seems to ignore this array, if we
defined it as as static array. At least it is as static array not part of
@ -72,9 +70,7 @@ int kputchar(int c)
if (is_single_kernel()) {
#ifdef CONFIG_VGA
spinlock_irqsave_lock(&vga_lock);
vga_putchar(c);
spinlock_irqsave_unlock(&vga_lock);
#else
uart_putchar(c);
#endif
@ -87,6 +83,8 @@ int kputs(const char *str)
{
int pos, i, len = strlen(str);
spinlock_irqsave_lock(&stdio_lock);
for(i=0; i<len; i++) {
pos = atomic_int32_inc(&kmsg_counter);
kmessages[pos % KMSG_SIZE] = str[i];
@ -94,13 +92,13 @@ int kputs(const char *str)
if (is_single_kernel()) {
#ifdef CONFIG_VGA
spinlock_irqsave_lock(&vga_lock);
vga_puts(str);
spinlock_irqsave_unlock(&vga_lock);
#else
uart_puts(str);
#endif
}
spinlock_irqsave_unlock(&stdio_lock);
return len;
}