projects
/
pintos-anon
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Also clean results, grade.
[pintos-anon]
/
src
/
lib
/
kernel
/
console.c
diff --git
a/src/lib/kernel/console.c
b/src/lib/kernel/console.c
index d09801d984a6f2250b18f15d819dc781c521f741..f62e7f34c246b0e64183d8a40c1621a32b348597 100644
(file)
--- a/
src/lib/kernel/console.c
+++ b/
src/lib/kernel/console.c
@@
-7,7
+7,7
@@
#include "threads/synch.h"
static void vprintf_helper (char, void *);
#include "threads/synch.h"
static void vprintf_helper (char, void *);
-static void putchar_
unlocked
(uint8_t c);
+static void putchar_
have_lock
(uint8_t c);
/* The console lock.
Both the vga and serial layers do their own locking, so it's
/* The console lock.
Both the vga and serial layers do their own locking, so it's
@@
-31,7
+31,7
@@
static struct lock console_lock;
intr_handler() - timer interrupt
intr_set_level()
serial_putc()
intr_handler() - timer interrupt
intr_set_level()
serial_putc()
- putchar_
unlocked
()
+ putchar_
have_lock
()
putbuf()
sys_write() - one process writing to the console
syscall_handler()
putbuf()
sys_write() - one process writing to the console
syscall_handler()
@@
-49,7
+49,7
@@
static int64_t write_cnt;
void
console_init (void)
{
void
console_init (void)
{
- lock_init (&console_lock
, "console"
);
+ lock_init (&console_lock);
}
/* Prints console statistics. */
}
/* Prints console statistics. */
@@
-85,6
+85,14
@@
release_console (void)
}
}
}
}
+/* Returns true if the current thread has the console lock,
+ false otherwise. */
+static bool
+console_locked_by_current_thread (void)
+{
+ return intr_context () || lock_held_by_current_thread (&console_lock);
+}
+
/* The standard vprintf() function,
which is like printf() but uses a va_list.
Writes its output to both vga display and serial port. */
/* The standard vprintf() function,
which is like printf() but uses a va_list.
Writes its output to both vga display and serial port. */
@@
-107,8
+115,8
@@
puts (const char *s)
{
acquire_console ();
while (*s != '\0')
{
acquire_console ();
while (*s != '\0')
- putchar_
unlocked
(*s++);
- putchar_
unlocked
('\n');
+ putchar_
have_lock
(*s++);
+ putchar_
have_lock
('\n');
release_console ();
return 0;
release_console ();
return 0;
@@
-120,7
+128,7
@@
putbuf (const char *buffer, size_t n)
{
acquire_console ();
while (n-- > 0)
{
acquire_console ();
while (n-- > 0)
- putchar_
unlocked
(*buffer++);
+ putchar_
have_lock
(*buffer++);
release_console ();
}
release_console ();
}
@@
-129,7
+137,7
@@
int
putchar (int c)
{
acquire_console ();
putchar (int c)
{
acquire_console ();
- putchar_
unlocked
(c);
+ putchar_
have_lock
(c);
release_console ();
return c;
release_console ();
return c;
@@
-141,15
+149,16
@@
vprintf_helper (char c, void *char_cnt_)
{
int *char_cnt = char_cnt_;
(*char_cnt)++;
{
int *char_cnt = char_cnt_;
(*char_cnt)++;
- putchar_
unlocked
(c);
+ putchar_
have_lock
(c);
}
/* Writes C to the vga display and serial port.
The caller has already acquired the console lock if
appropriate. */
static void
}
/* Writes C to the vga display and serial port.
The caller has already acquired the console lock if
appropriate. */
static void
-putchar_
unlocked
(uint8_t c)
+putchar_
have_lock
(uint8_t c)
{
{
+ ASSERT (console_locked_by_current_thread ());
write_cnt++;
serial_putc (c);
vga_putc (c);
write_cnt++;
serial_putc (c);
vga_putc (c);