- 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:
stefan 2010-08-02 07:40:40 +00:00
parent 763b19a3c5
commit d2293f130d

View file

@ -20,12 +20,14 @@
#include <metalsvm/stdio.h> #include <metalsvm/stdio.h>
#include <metalsvm/string.h> #include <metalsvm/string.h>
#include <metalsvm/stdarg.h> #include <metalsvm/stdarg.h>
#include <metalsvm/spinlocks.h>
#ifdef USE_VGA #ifdef USE_VGA
#include <asm/vga.h> #include <asm/vga.h>
#endif #endif
static unsigned int kmsg_counter = 0; static unsigned int kmsg_counter = 0;
static unsigned char kmessages[KMSG_SIZE]; static unsigned char kmessages[KMSG_SIZE];
static spinlock_t kio_lock = SPINLOCK_INIT;
int koutput_init(void) int koutput_init(void)
{ {
@ -39,25 +41,31 @@ int koutput_init(void)
int kputchar(int c) int kputchar(int c)
{ {
int ret = 1;
spinlock_lock(&kio_lock);
kmessages[kmsg_counter++ % KMSG_SIZE] = c; kmessages[kmsg_counter++ % KMSG_SIZE] = c;
#ifdef USE_VGA #ifdef USE_VGA
return vga_putchar(c); ret = vga_putchar(c);
#else
return 1;
#endif #endif
spinlock_unlock(&kio_lock);
return ret;
} }
int kputs(const char *str) int kputs(const char *str)
{ {
int i; int i;
spinlock_lock(&kio_lock);
for(i=0; str[i] != '\0'; i++) for(i=0; str[i] != '\0'; i++)
kmessages[kmsg_counter++ % KMSG_SIZE] = str[i]; kmessages[kmsg_counter++ % KMSG_SIZE] = str[i];
#ifdef USE_VGA #ifdef USE_VGA
return vga_puts(str); i = vga_puts(str);
#else
return i;
#endif #endif
spinlock_unlock(&kio_lock);
return i;
} }
static void kprintu(unsigned int val, int* count) static void kprintu(unsigned int val, int* count)