Mercurial > hg > CbC > old > DPP
comparison queue.cbc @ 0:d4bc23cb728b
Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
author | Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 16 Dec 2015 15:16:11 +0900 |
parents | |
children | b15128ab0324 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:d4bc23cb728b |
---|---|
1 /* | |
2 OS Scheduler Simulator | |
3 | |
4 ** 連絡先: 琉球大学情報工学科 河野 真治 | |
5 ** (E-Mail Address: kono@ie.u-ryukyu.ac.jp) | |
6 ** | |
7 ** このソースのいかなる複写,改変,修正も許諾します。ただし、 | |
8 ** その際には、誰が貢献したを示すこの部分を残すこと。 | |
9 ** 再配布や雑誌の付録などの問い合わせも必要ありません。 | |
10 ** 営利利用も上記に反しない範囲で許可します。 | |
11 ** バイナリの配布の際にはversion messageを保存することを条件とします。 | |
12 ** このプログラムについては特に何の保証もしない、悪しからず。 | |
13 ** | |
14 ** Everyone is permitted to do anything on this program | |
15 ** including copying, modifying, improving, | |
16 ** as long as you don't try to pretend that you wrote it. | |
17 ** i.e., the above copyright notice has to appear in all copies. | |
18 ** Binary distribution requires original version messages. | |
19 ** You don't have to ask before copying, redistribution or publishing. | |
20 ** THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE. | |
21 | |
22 Task Queue Manager | |
23 | |
24 ** modify: Atsuki Shimoji(atsuki@cr.ie.u-ryukyu.ac.jp) | |
25 | |
26 */ | |
27 #include "queue.h" | |
28 | |
29 code create_queue(int count, PhilsPtr self, TaskPtr list, TaskPtr last, | |
30 code (*dest)( | |
31 int count,PhilsPtr self, TaskPtr list,TaskPtr last, TaskPtr q | |
32 )) | |
33 { | |
34 TaskPtr q; | |
35 q = (TaskPtr)malloc(sizeof(Task)); | |
36 if (q) { | |
37 q->next = NULL; | |
38 q->phils = self; | |
39 } | |
40 goto dest(count, self, list, last, q); /* dest(TaskPtr new_queue) */ | |
41 } | |
42 | |
43 void | |
44 free_queue(TaskPtr q) | |
45 { | |
46 free(q); | |
47 } | |
48 | |
49 code lastSearch(code (*dest)(), TaskPtr list, TaskPtr p, TaskPtr q) | |
50 { | |
51 if (p->next) { | |
52 p = p->next; | |
53 goto lastSearch(dest, list, p, q); | |
54 } else { | |
55 p->next = q; | |
56 goto dest(list); /* dest(TaskPtr appended_queue) */ | |
57 } | |
58 } | |
59 | |
60 code enqueue(int count, PhilsPtr self, TaskPtr list, TaskPtr last, TaskPtr q, | |
61 code (*dest)( | |
62 int count, PhilsPtr self, TaskPtr list, TaskPtr last | |
63 )) | |
64 { | |
65 q->next = list; | |
66 goto dest(count,self,q, last); | |
67 } | |
68 | |
69 code dequeue(code (*dest)(), TaskPtr list) | |
70 { | |
71 TaskPtr p = list; | |
72 if (p) { | |
73 list = list->next; | |
74 p->next = 0; | |
75 goto dest(p, list); /* dest(TaskPtr out, TaskPtr queue) */ | |
76 } | |
77 goto dest(p, list); /* dest(TaskPtr out, TaskPtr queue) */ | |
78 } | |
79 | |
80 TaskIteratorPtr | |
81 create_task_iterator(TaskPtr list,StateDB s,TaskIteratorPtr prev) | |
82 { | |
83 TaskIteratorPtr new = (TaskIteratorPtr)malloc(sizeof(TaskIterator)); | |
84 if (!new) die_exit("can't allocate task iterlator"); | |
85 | |
86 new->prev = prev; | |
87 new->state = s; | |
88 new->list = list; | |
89 new->last = list; | |
90 return new; | |
91 } | |
92 | |
93 TaskPtr | |
94 next_task_iterator(TaskIteratorPtr self) | |
95 { | |
96 TaskPtr next; | |
97 if (!self->list) { | |
98 die_exit("task iterator inconsistency"); | |
99 } | |
100 next = self->list->next; | |
101 if (!next) { | |
102 die_exit("task iterator next inconsistency"); | |
103 } | |
104 if (next == self->last) { | |
105 return 0; | |
106 } | |
107 self->list = next; | |
108 return next; | |
109 } | |
110 | |
111 void | |
112 free_task_iterator(TaskIteratorPtr iter) | |
113 { | |
114 free(iter); | |
115 } | |
116 | |
117 /* end */ |