132
|
1 #include "../context.h"
|
|
2 #interface "SysRead.h"
|
|
3
|
|
4 // ----
|
|
5 // typedef struct SysReadImpl <Type, Isa> impl SysRead {
|
|
6 //
|
|
7 // } SysReadImpl;
|
|
8 // ----
|
|
9
|
|
10 SysRead* createSysReadImpl(struct Context* cbc_context) {
|
|
11 struct SysRead* sys_read = new SysRead();
|
|
12 struct SysReadImpl* sys_read_impl = new SysReadImpl();
|
|
13 sys_read->sys_read = (union Data*)sys_read_impl;
|
|
14 sys_read->num = 0;
|
|
15 sys_read->addr = NULL;
|
|
16 sys_read->file = NULL;
|
135
|
17 sys_read->r = 0;
|
|
18 sys_read->pipe = NULL;
|
132
|
19 sys_read->read = C_readSysReadImpl;
|
|
20 sys_read->next = C_nextSysReadImpl;
|
135
|
21 sys_read->cbc_fileread1 = C_cbc_fileread1SysReadImpl;
|
|
22 sys_read->cbc_fileread = C_cbc_filereadSysReadImpl;
|
|
23 sys_read->cbc_piperead1 = C_cbc_piperead1SysReadImpl;
|
|
24 sys_read->cbc_piperead2 = C_cbc_piperead2SysReadImpl;
|
|
25 sys_read->cbc_piperead3 = C_cbc_piperead3SysReadImpl;
|
132
|
26 return sys_read;
|
|
27 }
|
|
28 __code readSysReadImpl(struct SysReadImpl* sys_read, __code next(...)) {
|
|
29
|
|
30 goto next(...);
|
|
31 }
|
|
32
|
|
33 __code nextSysReadImpl(...) {
|
|
34
|
|
35 }
|
|
36
|
135
|
37 __code cbc_fileread1SysReadImpl(struct SysReadImpl* sys_read, int r) {
|
|
38
|
|
39 }
|
|
40
|
|
41 __code cbc_filereadSysReadImpl(struct SysReadImpl* sys_read, struct file* file, char* addr, int n, __code (*next)(int ret)) {
|
|
42
|
|
43 goto (*next);
|
|
44 }
|
|
45
|
|
46 __code cbc_piperead1SysReadImpl(struct SysReadImpl* sys_read, struct pipe* p) {
|
|
47 __code(*next)(int ret) = proc->cbc_arg.cbc_console_arg.next;
|
|
48 if (p->nread == p->nwrite && p->writeopen){
|
|
49 if(proc->killed){
|
|
50 release(&p->lock);
|
|
51 goto next(-1);
|
|
52 }
|
|
53 proc->cbc_arg.cbc_console_arg.p = p;
|
|
54 goto cbc_sleep(&p->nread, &p->lock, cbc_piperead1);
|
|
55 }
|
|
56 goto cbc_piperead2SysReadImpl(sys_read,0,sys_read->n,sys_read->p);
|
|
57 }
|
|
58
|
|
59 __code cbc_piperead2SysReadImpl(struct SysReadImpl* sys_read, int i, int n,struct pipe* p, char* addr) {
|
|
60 if (i < n && !(p->nread == p->nwrite)) {
|
|
61 addr[i] = p->data[p->nread++ % PIPESIZE];
|
|
62 i ++;
|
|
63 goto cbc_piperead2(sys_read,i,n,p,addr);
|
|
64 }
|
|
65 goto cbc_wakeup(&p->nwrite, cbc_piperead3); //DOC: piperead-wakeup
|
|
66 }
|
|
67
|
|
68 __code cbc_piperead3SysReadImpl(struct SysReadImpl* sys_read, struct pipe* p, int i) {
|
|
69
|
|
70 }
|
|
71
|
|
72 __code cbc_pipereadSysReadImpl(struct SysReadImpl* sys_read, struct pipe* p, char* addr, int n) {
|
|
73 acquire(&p->lock);
|
|
74 goto cbc_piperead1SysReadImpl(sys_read,p);
|
|
75 }
|