Remove confusing and incorrect comment inherited from patchkit days.
[unix-history] / sys / kern / tty.c
index 6a7988e..1a79702 100644 (file)
@@ -32,7 +32,7 @@
  * SUCH DAMAGE.
  *
  *     from: @(#)tty.c 7.44 (Berkeley) 5/28/91
  * SUCH DAMAGE.
  *
  *     from: @(#)tty.c 7.44 (Berkeley) 5/28/91
- *     $Id: tty.c,v 1.10 1993/12/13 01:10:13 ache Exp $
+ *     $Id: tty.c,v 1.14 1994/01/11 18:09:36 ache Exp $
  */
 
 #include "param.h"
  */
 
 #include "param.h"
@@ -194,9 +194,14 @@ ttywait(tp)
            (tp->t_state&TS_CARR_ON || tp->t_cflag&CLOCAL) && 
            tp->t_oproc) {
                (*tp->t_oproc)(tp);
            (tp->t_state&TS_CARR_ON || tp->t_cflag&CLOCAL) && 
            tp->t_oproc) {
                (*tp->t_oproc)(tp);
-               tp->t_state |= TS_ASLEEP;
-               if (error = ttysleep(tp, (caddr_t)&tp->t_out, 
-                   TTOPRI | PCATCH, ttyout, 0))
+               if ((RB_LEN(&tp->t_out) || tp->t_state&TS_BUSY) &&
+                   (tp->t_state&TS_CARR_ON || tp->t_cflag&CLOCAL)) {
+                       tp->t_state |= TS_ASLEEP;
+                       if (error = ttysleep(tp, (caddr_t)&tp->t_out,
+                           TTOPRI | PCATCH, ttyout, 0))
+                               break;
+               }
+               else
                        break;
        }
        splx(s);
                        break;
        }
        splx(s);
@@ -1286,7 +1291,7 @@ ttread(tp, uio, flag)
        register long lflag;
        register u_char *cc = tp->t_cc;
        register struct proc *p = curproc;
        register long lflag;
        register u_char *cc = tp->t_cc;
        register struct proc *p = curproc;
-       int s, first, error = 0, not_enough;
+       int s, first, error = 0, not_enough, rblen;
 
 loop:
        lflag = tp->t_lflag;
 
 loop:
        lflag = tp->t_lflag;
@@ -1294,14 +1299,17 @@ loop:
        /*
         * take pending input first 
         */
        /*
         * take pending input first 
         */
-       if (lflag&PENDIN)
+       if (lflag&PENDIN) {
                ttypend(tp);
                ttypend(tp);
-       splx(s);
+               splx(s);        /* reduce latency */
+               s = spltty();
+       }
 
        /*
         * Hang process if it's in the background.
         */
        if (isbackground(p, tp)) {
 
        /*
         * Hang process if it's in the background.
         */
        if (isbackground(p, tp)) {
+               splx(s);
                if ((p->p_sigignore & sigmask(SIGTTIN)) ||
                   (p->p_sigmask & sigmask(SIGTTIN)) ||
                    p->p_flag&SPPWAIT || p->p_pgrp->pg_jobc == 0)
                if ((p->p_sigignore & sigmask(SIGTTIN)) ||
                   (p->p_sigmask & sigmask(SIGTTIN)) ||
                    p->p_flag&SPPWAIT || p->p_pgrp->pg_jobc == 0)
@@ -1319,14 +1327,14 @@ loop:
         */
        qp = lflag&ICANON ? &tp->t_can : &tp->t_raw;
        not_enough = lflag&ICANON ? 0 : (int) cc[VMIN] - 1;
         */
        qp = lflag&ICANON ? &tp->t_can : &tp->t_raw;
        not_enough = lflag&ICANON ? 0 : (int) cc[VMIN] - 1;
+       rblen = RB_LEN(qp);
 
        /*
         * If there is no input, sleep on rawq
         * awaiting hardware receipt and notification.
         * If we have data, we don't need to check for carrier.
         */
 
        /*
         * If there is no input, sleep on rawq
         * awaiting hardware receipt and notification.
         * If we have data, we don't need to check for carrier.
         */
-       s = spltty();
-       if (RB_LEN(qp) <= not_enough) {
+       if (rblen == 0 || rblen <= not_enough) {
                int carrier;
 
                carrier = (tp->t_state&TS_CARR_ON) || (tp->t_cflag&CLOCAL);
                int carrier;
 
                carrier = (tp->t_state&TS_CARR_ON) || (tp->t_cflag&CLOCAL);
@@ -1334,9 +1342,7 @@ loop:
                        splx(s);
                        return (0);     /* EOF */
                }
                        splx(s);
                        return (0);     /* EOF */
                }
-               if (   (flag&IO_NDELAY)
-                   || !(lflag&ICANON) && cc[VMIN] == 0
-                  ) {
+               if ((flag&IO_NDELAY) || not_enough < 0) {
                        splx(s);
                        return (EWOULDBLOCK);
                }
                        splx(s);
                        return (EWOULDBLOCK);
                }
@@ -1351,13 +1357,45 @@ loop:
                        return (error);
                goto loop;
        }
                        return (error);
                goto loop;
        }
-       splx(s);
 
        /*
         * Input present, check for input mapping and processing.
         */
        first = 1;
 
        /*
         * Input present, check for input mapping and processing.
         */
        first = 1;
-       while ((c = getc(qp)) >= 0) {
+       if (lflag & (ICANON | ISIG))
+               goto slowcase;
+       for (;;) {
+               int rcc;
+
+               rcc = RB_CONTIGGET(qp);
+               if (rcc > uio->uio_resid)
+                       rcc = uio->uio_resid;
+               if (rcc <= 0) {
+                       if (first) {
+                               /* queue got flushed (can't happen) */
+                               splx(s);
+                               goto loop;
+                       }
+                       break;
+               }
+               error = uiomove(qp->rb_hd, rcc, uio);
+               if (error)
+                       splx(s);
+               qp->rb_hd = RB_ROLLOVER(qp, qp->rb_hd + rcc);
+               splx(s);
+               s = spltty();
+               first = 0;
+       }
+       goto out;
+slowcase:
+       for (;;) {
+               c = getc(qp);
+               splx(s);
+               if (c < 0) {
+                       if (first)
+                               goto loop;
+                       break;
+               }
                /*
                 * delayed suspend (^Y)
                 */
                /*
                 * delayed suspend (^Y)
                 */
@@ -1390,16 +1428,21 @@ loop:
                 */
                if (lflag&ICANON && ttbreakc(c))
                        break;
                 */
                if (lflag&ICANON && ttbreakc(c))
                        break;
+               s = spltty();
                first = 0;
        }
                first = 0;
        }
+       s = spltty();
+
        /*
         * Look to unblock input now that (presumably)
         * the input queue has gone down.
         */
        /*
         * Look to unblock input now that (presumably)
         * the input queue has gone down.
         */
+out:
        if (tp->t_state & (TS_TBLOCK | TS_HW_IFLOW)
            && INPUT_LEN(tp) <= I_LOW_WATER)
                ttyunblock(tp);
 
        if (tp->t_state & (TS_TBLOCK | TS_HW_IFLOW)
            && INPUT_LEN(tp) <= I_LOW_WATER)
                ttyunblock(tp);
 
+       splx(s);
        return (error);
 }
 
        return (error);
 }
 
@@ -1934,7 +1977,7 @@ ttyinfo(tp)
                /* Print percentage cpu, resident set size. */
                tmp = pick->p_pctcpu * 10000 + FSCALE / 2 >> FSHIFT;
                ttyprintf(tp, "%d%% %dk\n",
                /* Print percentage cpu, resident set size. */
                tmp = pick->p_pctcpu * 10000 + FSCALE / 2 >> FSHIFT;
                ttyprintf(tp, "%d%% %dk\n",
-                  tmp / 100, pgtok(pick->p_vmspace->vm_rssize));
+                  tmp / 100, pgtok(pick->p_vmspace->vm_pmap.pm_stats.resident_count));
        }
        tp->t_rocount = 0;      /* so pending input will be retyped if BS */
 }
        }
        tp->t_rocount = 0;      /* so pending input will be retyped if BS */
 }