comparison 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
comparison
equal deleted inserted replaced
9:44c5e4cacaae 10:7b4fed4aefb1
1 __code cbc_consoleread2 ()
2 {
3 struct inode *ip = proc->cbc_arg.cbc_console_arg.ip;
4 __code(*next)(int ret) = proc->cbc_arg.cbc_console_arg.next;
5 if (input.r == input.w) {
6 if (proc->killed) {
7 release(&input.lock);
8 ilock(ip);
9 goto next(-1);
10 }
11 goto cbc_sleep(&input.r, &input.lock, cbc_consoleread2);
12 }
13 goto cbc_consoleread1();
14 }
15
16 __code cbc_consoleread1 ()
17 {
18 int cont = 1;
19 int n = proc->cbc_arg.cbc_console_arg.n;
20 int target = proc->cbc_arg.cbc_console_arg.target;
21 char* dst = proc->cbc_arg.cbc_console_arg.dst;
22 struct inode *ip = proc->cbc_arg.cbc_console_arg.ip;
23 __code(*next)(int ret) = proc->cbc_arg.cbc_console_arg.next;
24
25 int c = input.buf[input.r++ % INPUT_BUF];
26
27 if (c == C('D')) { // EOF
28 if (n < target) {
29 // Save ^D for next time, to make sure
30 // caller gets a 0-byte result.
31 input.r--;
32 }
33 cont = 0;
34 }
35
36 *dst++ = c;
37 --n;
38
39 if (c == '\n') {
40 cont = 0;
41 }
42
43 if (cont == 1) {
44 if (n > 0) {
45 proc->cbc_arg.cbc_console_arg.n = n;
46 proc->cbc_arg.cbc_console_arg.target = target;
47 proc->cbc_arg.cbc_console_arg.dst = dst;
48 proc->cbc_arg.cbc_console_arg.ip = ip;
49 proc->cbc_arg.cbc_console_arg.next = next;
50 goto cbc_sleep(&input.r, &input.lock, cbc_consoleread2);
51 }
52 }
53
54 release(&input.lock);
55 ilock(ip);
56
57 goto next(target - n);
58 }
59
60 __code cbc_consoleread (struct inode *ip, char *dst, int n, __code(*next)(int ret))
61 {
62 uint target;
63
64 iunlock(ip);
65
66 target = n;
67 acquire(&input.lock);
68
69 if (n > 0) {
70 proc->cbc_arg.cbc_console_arg.n = n;
71 proc->cbc_arg.cbc_console_arg.target = target;
72 proc->cbc_arg.cbc_console_arg.dst = dst;
73 proc->cbc_arg.cbc_console_arg.ip = ip;
74 proc->cbc_arg.cbc_console_arg.next = next;
75 goto cbc_consoleread2();
76 }
77 goto cbc_consoleread1();
78 }
79