code:ttwrite - ikarishinjieva/unixV6-code-analyze-chs GitHub Wiki
8547 /* Called from the device's write routine after it has
8548 * calculated the tty-structure given as argument.
8549 */
8551 struct tty *atp;
8553 register struct tty *tp;
8554 register int c;
8555 tp = atp;
8556 if ((tp->t_state&CARR_ON)==0)
8557 return;
8558 while ((c=cpass())>=0) {
- 若当前设备在逻辑上不存在,则直接返回
8559 spl5();
8560 while (tp->t_outq.c_cc > TTHIWAT) {
- 处理机优先级设为5,防止在该过程中有其他字符进入输出队列
8561 ttstart(tp);
8562 tp->t_state =| ASLEEP;
8563 sleep(&tp->t_outq, TTOPRI);
- 置ASLEEP标记,此语句无作用(源自LIONS源代码分析),参见遗留问题
8564 }
8565 spl0();
8566 ttyoutput(c, tp);
8567 }
8568 ttstart(tp);
- 8558 - 8567
- 从指定的内存地址空间读入字符
- 对于每个读入的字符
- 若输出队列过长
- 清输出队列直至缩短至一定长度为止,在此期间进程睡眠
- 否则
- 将读入的字符放入输出队列
- 继续读入下一个字符,直到读完为止
8569 }
- 最后启动tty输出
8570 /* ------------------------- */