diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/queue.cbc	Wed Dec 16 15:16:11 2015 +0900
@@ -0,0 +1,117 @@
+/*
+    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)
+{
+	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 */