- add an IO lock to synchronite the access to the IO buffer
git-svn-id: http://svn.lfbs.rwth-aachen.de/svn/scc/trunk/MetalSVM@6 315a16e6-25f9-4109-90ae-ca3045a26c18
This commit is contained in:
parent
763b19a3c5
commit
d2293f130d
1 changed files with 14 additions and 6 deletions
20
lib/stdio.c
20
lib/stdio.c
|
@ -20,12 +20,14 @@
|
|||
#include <metalsvm/stdio.h>
|
||||
#include <metalsvm/string.h>
|
||||
#include <metalsvm/stdarg.h>
|
||||
#include <metalsvm/spinlocks.h>
|
||||
#ifdef USE_VGA
|
||||
#include <asm/vga.h>
|
||||
#endif
|
||||
|
||||
static unsigned int kmsg_counter = 0;
|
||||
static unsigned char kmessages[KMSG_SIZE];
|
||||
static spinlock_t kio_lock = SPINLOCK_INIT;
|
||||
|
||||
int koutput_init(void)
|
||||
{
|
||||
|
@ -39,25 +41,31 @@ int koutput_init(void)
|
|||
|
||||
int kputchar(int c)
|
||||
{
|
||||
int ret = 1;
|
||||
|
||||
spinlock_lock(&kio_lock);
|
||||
kmessages[kmsg_counter++ % KMSG_SIZE] = c;
|
||||
#ifdef USE_VGA
|
||||
return vga_putchar(c);
|
||||
#else
|
||||
return 1;
|
||||
ret = vga_putchar(c);
|
||||
#endif
|
||||
spinlock_unlock(&kio_lock);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int kputs(const char *str)
|
||||
{
|
||||
int i;
|
||||
|
||||
spinlock_lock(&kio_lock);
|
||||
for(i=0; str[i] != '\0'; i++)
|
||||
kmessages[kmsg_counter++ % KMSG_SIZE] = str[i];
|
||||
#ifdef USE_VGA
|
||||
return vga_puts(str);
|
||||
#else
|
||||
return i;
|
||||
i = vga_puts(str);
|
||||
#endif
|
||||
spinlock_unlock(&kio_lock);
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
static void kprintu(unsigned int val, int* count)
|
||||
|
|
Loading…
Add table
Reference in a new issue