From: Ben Pfaff Date: Sat, 11 Sep 2004 23:16:03 +0000 (+0000) Subject: Only poll on output if the txq is full and interrupts are off, and X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f8c3387bc9d7f7280c3b6f3626826e21ca584af0;p=pintos-anon Only poll on output if the txq is full and interrupts are off, and only one byte's worth. --- diff --git a/src/devices/serial.c b/src/devices/serial.c index 230a320..d1a4eca 100644 --- a/src/devices/serial.c +++ b/src/devices/serial.c @@ -52,18 +52,26 @@ serial_putc (uint8_t byte) { enum intr_level old_level = intr_disable (); - if (mode == POLL || old_level == INTR_OFF) + if (mode == POLL) { /* If we're not set up for interrupt-driven I/O yet, - or if interrupts are off, - use dumb polling for serial I/O. */ - serial_flush (); + use dumb polling to transmit a byte. */ putc_poll (byte); } - else + else { /* Otherwise, queue a byte and update the interrupt enable register. */ + if (old_level == INTR_OFF && intq_full (&txq)) + { + /* Interrupts are off and the transmit queue is full. + If we wanted to wait for the queue to empty, + we'd have to reenable interrupts. + That's impolite, so we'll send a character via + polling instead. */ + putc_poll (intq_getc (&txq)); + } + intq_putc (&txq, byte); write_ier (); }