Mercurial > hg > Members > nobuyasu > CbC
changeset 8:5dc0fa7caa57 draft
add ABP
author | Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 01 May 2012 13:48:30 +0900 |
parents | afa536eef659 |
children | 18d2a590bc10 |
files | ABP/Makefile ABP/queue.c ABP/queue.h ABP/receiver.c ABP/receiver2.c ABP/receiver3.c ABP/scheduler.c ABP/scheduler2.c ABP/sender.c ABP/sender2.c ABP/sender3.c automaton/fautomaton1.cbc |
diffstat | 12 files changed, 605 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ABP/Makefile Tue May 01 13:48:30 2012 +0900 @@ -0,0 +1,32 @@ +CC=gcc +MCC=mcc +TARGET=abp abp2 sender2 sender3 receiver2 +MCCFLAGS=-s +CFLAGS=-g -Wall + +.SUFFIXES: .c .o + +.c.o: + $(MCC) $(MCCFLAGS) $< + $(CC) $(CFLAGS) -o $@ -c $(<:.c=.s) + +all: $(TARGET) + +abp: sender.o receiver.o scheduler.o + $(CC) -o $@ $^ + +abp2: queue.o sender3.o receiver3.o scheduler2.o + $(CC) -o $@ $^ + +sender2: sender2.o + $(CC) -o $@ $^ + +sender3: sender3.o + $(CC) -o $@ $^ + +receiver2: receiver2.o + $(CC) -o $@ $^ + +clean: + $(RM) $(TARGET) + $(RM) *.s *.o
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ABP/queue.c Tue May 01 13:48:30 2012 +0900 @@ -0,0 +1,81 @@ +/* + OS Scheduler Simulator + +** 連絡先: 琉球大学情報工学科 河野 真治 +** (E-Mail Address: kono@ie.u-ryukyu.ac.jp) +** +** このソースのいかなる複写,改変,修正も許諾します。ただし、 +** その際には、誰が貢献したを示すこの部分を残すこと。 +** 再配布や雑誌の付録などの問い合わせも必要ありません。 +** 営利利用も上記に反しない範囲で許可します。 +** バイナリの配布の際にはversion messageを保存することを条件とします。 +** このプログラムについては特に何の保証もしない、悪しからず。 +** +** Everyone is permitted to do anything on this program +** including copying, modifying, improving, +** as long as you don't try to pretend that you wrote it. +** i.e., the above copyright notice has to appear in all copies. +** Binary distribution requires original version messages. +** You don't have to ask before copying, redistribution or publishing. +** THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE. + + Task Queue Manager + +** modify: Atsuki Shimoji(atsuki@cr.ie.u-ryukyu.ac.jp) + + */ +#include "queue.h" + +QueuePtr +new_queue(code (*address)(), struct packet *pkt) +{ + QueuePtr q; + q = (QueuePtr)malloc(sizeof(Queue)); + if (!q) return q; + q->next = NULL; + q->address = address; + q->pkt = pkt; + return q; +} + +void +free_queue(QueuePtr q) +{ + free(q); +} + +code lastSearch(QueuePtr list, QueuePtr p, QueuePtr q) +{ + if (p->next) { + p = p->next; + goto lastSearch(list, p, q); + } else { + p->next = q; + goto ret(list); + } +} + +QueuePtr +enqueue(QueuePtr list, QueuePtr q) +{ + QueuePtr p = list; + if (!p) return q; + if (p->next) { + goto lastSearch(list, p, q); + } else { + p->next = q; + return list; + } +} + +QueuePtr +dequeue(QueuePtr list, QueuePtr *q) +{ + QueuePtr p = list; + if (p) { + *q = list; + p = list->next; + list->next = 0; + } + return p; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ABP/queue.h Tue May 01 13:48:30 2012 +0900 @@ -0,0 +1,40 @@ +/* + OS Scheduler Simulator + +** 連絡先: 琉球大学情報工学科 河野 真治 +** (E-Mail Address: kono@ie.u-ryukyu.ac.jp) +** +** このソースのいかなる複写,改変,修正も許諾します。ただし、 +** その際には、誰が貢献したを示すこの部分を残すこと。 +** 再配布や雑誌の付録などの問い合わせも必要ありません。 +** 営利利用も上記に反しない範囲で許可します。 +** バイナリの配布の際にはversion messageを保存することを条件とします。 +** このプログラムについては特に何の保証もしない、悪しからず。 +** +** Everyone is permitted to do anything on this program +** including copying, modifying, improving, +** as long as you don't try to pretend that you wrote it. +** i.e., the above copyright notice has to appear in all copies. +** Binary distribution requires original version messages. +** You don't have to ask before copying, redistribution or publishing. +** THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE. + + Task Queue Manager + +** modify: Atsuki Shimoji(atsuki@cr.ie.u-ryukyu.ac.jp) + + */ +#define NULL ((void*)0) + +typedef struct queue { + struct queue *next; + code (*address)(); + struct packet *pkt; +} Queue, *QueuePtr; + +extern code (*ret)(); +extern void *env; +extern QueuePtr new_queue(code (*address)(), struct packet *pkt); +extern void free_queue(QueuePtr q); +extern QueuePtr enqueue(QueuePtr list, QueuePtr q); +extern QueuePtr dequeue(QueuePtr list, QueuePtr *q);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ABP/receiver.c Tue May 01 13:48:30 2012 +0900 @@ -0,0 +1,36 @@ +extern int comm_bit_s; /* communication bit for sender */ +extern int comm_bit_r; /* communication bit for receiver */ +extern char *comm_msg; /* communication message */ + +code r_receiveState(struct packet, int); +code r_sendState(struct packet, int); + +struct packet { + int bit; /*alternating bit */ + char **msg; /* message */ + code (*next)(); /* next code segment */ +}; + +code r_sendState(struct packet pkt, int i) +{ + comm_bit_r = pkt.bit; + pkt.next = r_receiveState; + goto schedule(pkt, i); +} + +code r_receiveState(struct packet pkt, int i) +{ + /* correct bit */ + if (pkt.bit == !comm_bit_s) { + printf("bit: %d\n", comm_bit_s); + printf("message: %s\n", comm_msg); + pkt.bit = !pkt.bit; + pkt.next = r_sendState; + goto schedule(pkt, i); + /* wrong bit */ + } else { + printf("nack\n"); + pkt.next = r_sendState; + goto schedule(pkt, i); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ABP/receiver2.c Tue May 01 13:48:30 2012 +0900 @@ -0,0 +1,67 @@ +int comm_bit; /* communication bit */ +char *comm_msg; /* communication message */ + +code (*ret)(int); +void *env; +code receiveState(struct packet, int); +code sendState(struct packet, int); + +struct packet { + int bit; /*alternating bit */ + char **msg; /* message */ + code (*next)(); /* next code segment */ +}; + +char *msgs[6] = { "hoge1", "hoge2", "hoge3", "hoge4", "hoge5", 0 }; + +code sendState(struct packet pkt, int i) +{ + printf("ack\n"); + comm_bit = pkt.bit; // ack + comm_bit = !pkt.bit; // sender's task + i++; // sender's task + comm_msg = pkt.msg[i]; // sender's task + + pkt.next = receiveState; + goto pkt.next(pkt, i); +} + +code receiveState(struct packet pkt, int i) +{ + if (pkt.msg[i] == 0) goto ret(0), env; + + /* correct bit */ + if (pkt.bit != comm_bit) { + printf("bit: %d\n", comm_bit); + printf("message: %s\n", comm_msg); + pkt.bit = !pkt.bit; + + pkt.next = sendState; + goto pkt.next(pkt, i); + /* wrong bit */ + } else { + printf("nack\n"); + comm_bit = !pkt.bit; // sender's task + + pkt.next = receiveState; + goto pkt.next(pkt, i); + } +} + +code initReceiver(struct packet pkt, int init_bit) +{ + pkt.bit = 1; + pkt.msg = msgs; + comm_bit = init_bit; // sender's task + comm_msg = pkt.msg[0]; // sender's task + pkt.next = receiveState; + goto pkt.next(pkt, 0); +} + +int main(void) +{ + struct packet pkt; + ret = return; + env = environment; + goto initReceiver(pkt, 0); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ABP/receiver3.c Tue May 01 13:48:30 2012 +0900 @@ -0,0 +1,38 @@ +extern int comm_bit_s; /* communication bit for sender */ +extern int comm_bit_r; /* communication bit for receiver */ +extern char *comm_msg; /* communication message */ + +extern struct queue *list; + +code r_receiveState(struct packet*, int); +code r_sendState(struct packet*, int); + +struct packet { + int bit; /*alternating bit */ + char **msg; /* message */ + code (*next)(); /* next code segment */ +}; + +code r_sendState(struct packet *pkt, int i) +{ + comm_bit_r = pkt->bit; + pkt->next = r_receiveState; + goto schedule(list, i); +} + +code r_receiveState(struct packet *pkt, int i) +{ + /* correct bit */ + if (pkt->bit == !comm_bit_s) { + printf("bit: %d\n", comm_bit_s); + printf("message: %s\n", comm_msg); + pkt->bit = !pkt->bit; + pkt->next = r_sendState; + goto schedule(list, i); + /* wrong bit */ + } else { + printf("nack\n"); + pkt->next = r_sendState; + goto schedule(list, i); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ABP/scheduler.c Tue May 01 13:48:30 2012 +0900 @@ -0,0 +1,57 @@ +int comm_bit_s; /* communication bit for sender */ +int comm_bit_r; /* communication bit for receiver */ +char *comm_msg; /* communication message */ + +code (*ret)(int); +void *env; + +struct packet { + int bit; /* alternating bit */ + char **msg; /* messages */ + code (*next)(); /* next code segment */ +}; + +struct packet spkt; /* sender packet */ +struct packet rpkt; /* receiver packet */ + +/* sender.c */ +extern code s_sendState(struct packet, int); +extern code s_receiveState(struct packet, int); +/* receiver.c */ +extern code r_receiveState(struct packet, int); +extern code r_sendState(struct packet, int); + +char *msgs[8] = { "hoge1", "hoge2", "hoge3", "hoge4", "hoge5", 0 }; + +/* Round-Robin */ +code schedule(struct packet pkt, int i) +{ + if (pkt.next == s_sendState || pkt.next == s_receiveState) { + spkt = pkt; + if (msgs[i] == 0) goto ret(0), env; + goto rpkt.next(rpkt, i); + } + if (pkt.next == r_sendState || pkt.next == r_receiveState) { + rpkt = pkt; + goto spkt.next(spkt, i); + } + goto ret(0), env; +} + +int main(void) +{ + /* initialize */ + comm_bit_s = -1; + comm_bit_r = -1; + spkt.bit = 0; + rpkt.bit = 1; + spkt.msg = msgs; + rpkt.msg = msgs; + spkt.next = s_sendState; + rpkt.next = r_receiveState; + ret = return; + env = environment; + + goto s_sendState(spkt, 0); + // goto r_receiveState(rpkt, 0); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ABP/scheduler2.c Tue May 01 13:48:30 2012 +0900 @@ -0,0 +1,118 @@ +#include "queue.h" + +int comm_bit_s; /* communication bit for sender */ +int comm_bit_r; /* communication bit for receiver */ +char *comm_msg; /* communication message */ + +code (*ret)(int); +void *env; +code schedule1(int); +code schedule2(int); +code schedule3(int); +code schedule4(int); + +struct packet { + int bit; /* alternating bit */ + char **msg; /* messages */ + code (*next)(); /* next code segment */ +}; + +QueuePtr list; /* save local task_list */ +struct packet spkt; /* sender packet */ +struct packet rpkt; /* receiver packet */ + +/* sender.c */ +extern code s_sendState(struct packet*, int); +extern code s_receiveState(struct packet*, int); +/* receiver.c */ +extern code r_receiveState(struct packet*, int); +extern code r_sendState(struct packet*, int); + +// char *adrs[5] = { schedule1, schedule2, schedule3, schedule4, 0 }; +char *adrs[7] = { schedule2, schedule1, schedule2, schedule4, schedule3, schedule4, 0 }; +char *pkts[5] = { &spkt, &rpkt, &rpkt, &spkt, 0 }; +char *msgs[8] = { "hoge1", "hoge2", "hoge3", "hoge4", "hoge5", 0 }; + +code schedule4(int i) +{ + printf("schdule4\n"); + goto s_receiveState(&spkt, i); +} + +code schedule3(int i) +{ + printf("schdule3\n"); + goto r_sendState(&rpkt, i); +} + +code schedule2(int i) +{ + printf("schdule2\n"); + goto r_receiveState(&rpkt, i); +} + +code schedule1(int i) +{ + printf("schdule1\n", i); + goto s_sendState(&spkt, i); +} + +code schedule(QueuePtr task_list, int i) +{ + QueuePtr q; + if (!task_list) goto ret(0), env; + task_list = dequeue(task_list, &q); + list = task_list; + goto q->address(i); +} + +code task_entry(QueuePtr task_list, int i) +{ + QueuePtr q; + if (adrs[i] != 0) { + printf("entry%d\n", i); + q = new_queue(adrs[i], pkts[i]); + if (!q) { + printf("error!\n"); + goto ret(0), env; + } + task_list = enqueue(task_list, q); + i++; + goto task_entry(task_list, i); + } else { + goto schedule(task_list, 0); + } +} + +int main(void) +{ + /* initialize */ + // int k; + QueuePtr task_list = NULL; + comm_bit_s = -1; + comm_bit_r = -1; + spkt.bit = 0; + rpkt.bit = 1; + spkt.msg = msgs; + rpkt.msg = msgs; + spkt.next = s_sendState; + rpkt.next = r_receiveState; + ret = return; + env = environment; + /* + printf("schdule1: %lx\n", (unsigned long)schedule1); + printf("schdule2: %lx\n", (unsigned long)schedule2); + printf("schdule3: %lx\n", (unsigned long)schedule3); + printf("schdule4: %lx\n", (unsigned long)schedule4); + for (k = 0; adrs[k] != 0; k++) { + printf("adrs[%d]: %lx\n", k, (unsigned long)adrs[k]); + } + printf("spkt: %lx\n", (unsigned long)&spkt); + printf("rpkt: %lx\n", (unsigned long)&rpkt); + for (k = 0; pkts[k] != 0; k++) { + printf("pkts[%d]: %lx\n", k, (unsigned long)pkts[k]); + } + */ + + goto task_entry(task_list, 0); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ABP/sender.c Tue May 01 13:48:30 2012 +0900 @@ -0,0 +1,37 @@ +extern int comm_bit_s; /* communication bit for sender */ +extern int comm_bit_r; /* communication bit for receiver */ +extern char *comm_msg; /* communication message */ + +code s_sendState(struct packet, int); +code s_receiveState(struct packet, int); + +struct packet { + int bit; /* alternating bit */ + char **msg; /* messages */ + code (*next)(); /* next code segment */ +}; + +code s_receiveState(struct packet pkt, int i) +{ + /* correct bit */ + if (pkt.bit == comm_bit_r) { + printf("sender: success\n"); + pkt.bit = !pkt.bit; + i++; // for message increment + pkt.next = s_sendState; + goto schedule(pkt, i); + /* wrong bit */ + } else { + printf("sender: failure\n"); + pkt.next = s_sendState; + goto schedule(pkt, i); + } +} + +code s_sendState(struct packet pkt, int i) +{ + comm_bit_s = pkt.bit; + comm_msg = pkt.msg[i]; + pkt.next = s_receiveState; + goto schedule(pkt, i); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ABP/sender2.c Tue May 01 13:48:30 2012 +0900 @@ -0,0 +1,58 @@ +int comm_bit; /* communication bit */ +char *comm_msg; /* communication message */ + +code (*ret)(int); +void *env; +code sendState(struct packet, int); +code receiveState(struct packet, int); + +struct packet { + int bit; /* alternating bit */ + char **msg; /* messages */ + code (*next)(); /* next code segment */ +}; + +char *msgs[6] = { "hoge1", "hoge2", "hoge3", "hoge4", "hoge5", 0 }; + +code receiveState(struct packet pkt, int i) +{ + if (pkt.bit == comm_bit) { + pkt.bit = !pkt.bit; + printf("bit: %d\n", comm_bit); + printf("message: %s\n", comm_msg); + i++; + pkt.next = sendState; + goto pkt.next(pkt, i); + } else { + printf("wrong bit!\n"); + comm_bit = pkt.bit; + pkt.next = sendState; + goto pkt.next(pkt, i); + } +} + +code sendState(struct packet pkt, int i) +{ + if (pkt.msg[i] == 0) goto ret(0), env; + comm_bit = pkt.bit; + comm_msg = pkt.msg[i]; + pkt.next = receiveState; + goto pkt.next(pkt, i); +} + +code initSender(struct packet pkt, int init_bit) +{ + pkt.bit = 0; + pkt.msg = msgs; + comm_bit = init_bit; + pkt.next = sendState; + goto pkt.next(pkt, 0); +} + +int main(void) +{ + struct packet pkt; + ret = return; + env = environment; + goto initSender(pkt, 0); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ABP/sender3.c Tue May 01 13:48:30 2012 +0900 @@ -0,0 +1,39 @@ +extern int comm_bit_s; /* communication bit for sender */ +extern int comm_bit_r; /* communication bit for receiver */ +extern char *comm_msg; /* communication message */ + +extern struct queue *list; + +code s_sendState(struct packet *, int i); +code s_receiveState(struct packet *, int i); + +struct packet { + int bit; /* alternating bit */ + char **msg; /* messages */ + code (*next)(); /* next code segment */ +}; + +code s_receiveState(struct packet *pkt, int i) +{ + /* correct bit */ + if (pkt->bit == comm_bit_r) { + printf("sender: success\n"); + pkt->bit = !pkt->bit; + i++; // for message increment + pkt->next = s_sendState; + goto schedule(list, i); + /* wrong bit */ + } else { + printf("sender: failure\n"); + pkt->next = s_sendState; + goto schedule(list, i); + } +} + +code s_sendState(struct packet *pkt, int i) +{ + comm_bit_s = pkt->bit; + comm_msg = pkt->msg[i]; + pkt->next = s_receiveState; + goto schedule(list, i); +}