annotate TaskManager.cbc @ 0:5b089096921f

first commit.
author kent <kent@cr.ie.u-ryukyu.ac.jp>
date Fri, 18 Dec 2009 21:57:05 +0900
parents
children aef83aed7a07
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 #include "TaskManager.h"
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 TaskQueue waitingQueue;
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 TaskQueue activeQueue;
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
5
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 /*
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 * TaskManager's main loop.
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 *
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 * while (1) {
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 * checkFinishedTask(); // to scheduler.
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 * wait2active();
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 * while (actQisnotempty) {
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 * task = pollFirst(actQ);
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 * executeTask(task); // to scheduler.
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 * }
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 * }
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 */
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 __code TManagerStart()
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 /* active, waitngタスクリストを整理 */
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 {
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 list = activeQueue;
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 goto executeTasklist(list);
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 }
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
24
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 __code executeTasklist()
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 /* */
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 {
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 if (0 < activeQueue->length) {
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 goto TManagerLoop();
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 }
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 task = pollFirst(activeQueue);
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
32
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 /*
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 * rbuff, wbuffの用意
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 */
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 goto task->run(TManagerReturnEntry, rbuff, wbuff);
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 /* Taskへ */
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 }
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
39
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
40 __code TManagerReturnEntry()
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 /* Taskから戻ってくるコードセグメント */
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
42 {
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 /*
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
44 * 依存していたtaskに通知?
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
45 */
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 goto executeTasklist(list->cdr);
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 }
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
48
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
49 __code TManagerLoop()
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
50 {
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 /*
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
52 * waitingTaskからactiveTaskへ
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 */
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
54
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
55 goto TManagerStart();
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
56 }
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
57
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
58
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 __code sched()
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 {
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 TaskList *t = waiter;
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
62 Task *t;
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
63 for (; t!=;);
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
64 }
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
65
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
66
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
67 /* belows is Interfaces for Users. */
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
68 /* it may be replace to code segment. but how? */
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
69
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
70 Task *newTask(int task_id)
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
71 {
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
72 static int id=0; // 今は使ってない… 使う?
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
73 task = allocate(sizeof(Task));
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
74
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
75 task->taskclass = taskclasses[task_id];
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
76 task->id = id;
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
77 task->waiter = NULL;
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
78 task->waitee = NULL;
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
79
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
80 return task;
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
81 }
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
82
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
83 void setData(Task *task, void *rbuff, size_t rs, void *wbuff, size_t ws)
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
84 {
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
85 task->rbuff = rbuff;
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
86 task->wbuff = wbuff;
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
87 task->rsize = rsize;
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
88 task->wsize = wsize;
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
89 }
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
90
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
91 void spawn(Task *task)
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
92 {
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
93 }
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
94
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
95