annotate Paper/src/console.cbc @ 10:7b4fed4aefb1

add figures
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Wed, 08 May 2019 18:23:07 +0900
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10
7b4fed4aefb1 add figures
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 __code cbc_consoleread2 ()
7b4fed4aefb1 add figures
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 {
7b4fed4aefb1 add figures
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 struct inode *ip = proc->cbc_arg.cbc_console_arg.ip;
7b4fed4aefb1 add figures
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 __code(*next)(int ret) = proc->cbc_arg.cbc_console_arg.next;
7b4fed4aefb1 add figures
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 if (input.r == input.w) {
7b4fed4aefb1 add figures
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 if (proc->killed) {
7b4fed4aefb1 add figures
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 release(&input.lock);
7b4fed4aefb1 add figures
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 ilock(ip);
7b4fed4aefb1 add figures
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 goto next(-1);
7b4fed4aefb1 add figures
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 }
7b4fed4aefb1 add figures
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 goto cbc_sleep(&input.r, &input.lock, cbc_consoleread2);
7b4fed4aefb1 add figures
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 }
7b4fed4aefb1 add figures
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 goto cbc_consoleread1();
7b4fed4aefb1 add figures
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 }
7b4fed4aefb1 add figures
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15
7b4fed4aefb1 add figures
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 __code cbc_consoleread1 ()
7b4fed4aefb1 add figures
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 {
7b4fed4aefb1 add figures
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 int cont = 1;
7b4fed4aefb1 add figures
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 int n = proc->cbc_arg.cbc_console_arg.n;
7b4fed4aefb1 add figures
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 int target = proc->cbc_arg.cbc_console_arg.target;
7b4fed4aefb1 add figures
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 char* dst = proc->cbc_arg.cbc_console_arg.dst;
7b4fed4aefb1 add figures
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 struct inode *ip = proc->cbc_arg.cbc_console_arg.ip;
7b4fed4aefb1 add figures
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 __code(*next)(int ret) = proc->cbc_arg.cbc_console_arg.next;
7b4fed4aefb1 add figures
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
24
7b4fed4aefb1 add figures
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 int c = input.buf[input.r++ % INPUT_BUF];
7b4fed4aefb1 add figures
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
26
7b4fed4aefb1 add figures
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 if (c == C('D')) { // EOF
7b4fed4aefb1 add figures
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 if (n < target) {
7b4fed4aefb1 add figures
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 // Save ^D for next time, to make sure
7b4fed4aefb1 add figures
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 // caller gets a 0-byte result.
7b4fed4aefb1 add figures
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 input.r--;
7b4fed4aefb1 add figures
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 }
7b4fed4aefb1 add figures
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 cont = 0;
7b4fed4aefb1 add figures
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 }
7b4fed4aefb1 add figures
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
35
7b4fed4aefb1 add figures
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 *dst++ = c;
7b4fed4aefb1 add figures
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 --n;
7b4fed4aefb1 add figures
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
38
7b4fed4aefb1 add figures
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 if (c == '\n') {
7b4fed4aefb1 add figures
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
40 cont = 0;
7b4fed4aefb1 add figures
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 }
7b4fed4aefb1 add figures
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
42
7b4fed4aefb1 add figures
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 if (cont == 1) {
7b4fed4aefb1 add figures
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
44 if (n > 0) {
7b4fed4aefb1 add figures
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
45 proc->cbc_arg.cbc_console_arg.n = n;
7b4fed4aefb1 add figures
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 proc->cbc_arg.cbc_console_arg.target = target;
7b4fed4aefb1 add figures
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 proc->cbc_arg.cbc_console_arg.dst = dst;
7b4fed4aefb1 add figures
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 proc->cbc_arg.cbc_console_arg.ip = ip;
7b4fed4aefb1 add figures
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
49 proc->cbc_arg.cbc_console_arg.next = next;
7b4fed4aefb1 add figures
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
50 goto cbc_sleep(&input.r, &input.lock, cbc_consoleread2);
7b4fed4aefb1 add figures
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 }
7b4fed4aefb1 add figures
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
52 }
7b4fed4aefb1 add figures
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
53
7b4fed4aefb1 add figures
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
54 release(&input.lock);
7b4fed4aefb1 add figures
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
55 ilock(ip);
7b4fed4aefb1 add figures
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
56
7b4fed4aefb1 add figures
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 goto next(target - n);
7b4fed4aefb1 add figures
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
58 }
7b4fed4aefb1 add figures
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
59
7b4fed4aefb1 add figures
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 __code cbc_consoleread (struct inode *ip, char *dst, int n, __code(*next)(int ret))
7b4fed4aefb1 add figures
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 {
7b4fed4aefb1 add figures
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
62 uint target;
7b4fed4aefb1 add figures
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
63
7b4fed4aefb1 add figures
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
64 iunlock(ip);
7b4fed4aefb1 add figures
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
65
7b4fed4aefb1 add figures
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
66 target = n;
7b4fed4aefb1 add figures
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
67 acquire(&input.lock);
7b4fed4aefb1 add figures
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
68
7b4fed4aefb1 add figures
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
69 if (n > 0) {
7b4fed4aefb1 add figures
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
70 proc->cbc_arg.cbc_console_arg.n = n;
7b4fed4aefb1 add figures
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
71 proc->cbc_arg.cbc_console_arg.target = target;
7b4fed4aefb1 add figures
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
72 proc->cbc_arg.cbc_console_arg.dst = dst;
7b4fed4aefb1 add figures
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
73 proc->cbc_arg.cbc_console_arg.ip = ip;
7b4fed4aefb1 add figures
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
74 proc->cbc_arg.cbc_console_arg.next = next;
7b4fed4aefb1 add figures
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
75 goto cbc_consoleread2();
7b4fed4aefb1 add figures
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
76 }
7b4fed4aefb1 add figures
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
77 goto cbc_consoleread1();
7b4fed4aefb1 add figures
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
78 }
7b4fed4aefb1 add figures
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
79