Mercurial > hg > Members > nobuyasu > CbC
view DPP/queue.cbc @ 33:3946f8d26710 draft default tip
add benchmarck/binary-trees
author | Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 09 Apr 2013 16:41:30 +0900 |
parents | 6695c97470f3 |
children |
line wrap: on
line source
/* 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" code create_queue(int count, PhilsPtr self, TaskPtr list, TaskPtr last, code (*dest)( int count,PhilsPtr self, TaskPtr list,TaskPtr last, TaskPtr q )) { TaskPtr q; q = (TaskPtr)malloc(sizeof(Task)); if (q) { q->next = NULL; q->phils = self; } goto dest(count, self, list, last, q); /* dest(TaskPtr new_queue) */ } void free_queue(TaskPtr q) { free(q); } code lastSearch(code (*dest)(), TaskPtr list, TaskPtr p, TaskPtr q) { if (p->next) { p = p->next; goto lastSearch(dest, list, p, q); } else { p->next = q; goto dest(list); /* dest(TaskPtr appended_queue) */ } } code enqueue(int count, PhilsPtr self, TaskPtr list, TaskPtr last, TaskPtr q, code (*dest)( int count, PhilsPtr self, TaskPtr list, TaskPtr last )) { q->next = list; goto dest(count,self,q, last); } //code dequeue(code (*dest)(), TaskPtr list) code dequeue(code (*dest)(), TaskPtr list, TaskPtr *q) { TaskPtr p = list; if (p) { list = list->next; p->next = 0; goto dest(p, list); /* dest(TaskPtr out, TaskPtr queue) */ } goto dest(p, list); /* dest(TaskPtr out, TaskPtr queue) */ } TaskIteratorPtr create_task_iterator(TaskPtr list,StateDB s,TaskIteratorPtr prev) { TaskIteratorPtr new = (TaskIteratorPtr)malloc(sizeof(TaskIterator)); if (!new) die_exit("can't allocate task iterlator"); new->prev = prev; new->state = s; new->list = list; new->last = list; return new; } TaskPtr next_task_iterator(TaskIteratorPtr self) { TaskPtr next; if (!self->list) { die_exit("task iterator inconsistency"); } next = self->list->next; if (!next) { die_exit("task iterator next inconsistency"); } if (next == self->last) { return 0; } self->list = next; return next; } void free_task_iterator(TaskIteratorPtr iter) { free(iter); } /* end */