annotate src/sys_read_impl.cbc @ 135:0c24464a66d8

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