Mercurial > hg > Members > kono > Cerium
annotate TaskManager/kernel/ppe/TaskQueueInfo.cc @ 495:17319af4ee39
fix wakeup_task
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Sat, 10 Oct 2009 19:16:09 +0900 |
parents | ec7b6d89b4e4 |
children | 9d225ba0c34f |
rev | line source |
---|---|
46 | 1 #include <stdio.h> |
2 #include <stdlib.h> | |
3 #include "TaskQueueInfo.h" | |
4 | |
494
ec7b6d89b4e4
Singleton TaskQueue pool
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
493
diff
changeset
|
5 // Singleton TaskQueue Pool |
ec7b6d89b4e4
Singleton TaskQueue pool
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
493
diff
changeset
|
6 TaskQueueInfo TaskQueueInfo::taskQueuePool; |
46 | 7 |
494
ec7b6d89b4e4
Singleton TaskQueue pool
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
493
diff
changeset
|
8 TaskQueueInfo::TaskQueueInfo() { |
479
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
9 // 最初の一つは自分 |
480
46464727d825
TaskQueueInfo initiaization...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
479
diff
changeset
|
10 first = last = this; |
479
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
11 next = prev = this; |
481
4896dffad67c
Double linked list modification done (tested on Mac OS X)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
480
diff
changeset
|
12 waiter = NULL; |
494
ec7b6d89b4e4
Singleton TaskQueue pool
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
493
diff
changeset
|
13 } |
ec7b6d89b4e4
Singleton TaskQueue pool
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
493
diff
changeset
|
14 |
ec7b6d89b4e4
Singleton TaskQueue pool
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
493
diff
changeset
|
15 void |
ec7b6d89b4e4
Singleton TaskQueue pool
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
493
diff
changeset
|
16 TaskQueueInfo::freePool() { |
ec7b6d89b4e4
Singleton TaskQueue pool
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
493
diff
changeset
|
17 for(TaskQueuePtr p = taskQueuePool.waiter; p; ) { |
ec7b6d89b4e4
Singleton TaskQueue pool
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
493
diff
changeset
|
18 TaskQueuePtr next = p->waiter; |
ec7b6d89b4e4
Singleton TaskQueue pool
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
493
diff
changeset
|
19 p->waiter = NULL; |
ec7b6d89b4e4
Singleton TaskQueue pool
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
493
diff
changeset
|
20 free(p); |
ec7b6d89b4e4
Singleton TaskQueue pool
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
493
diff
changeset
|
21 p = next; |
ec7b6d89b4e4
Singleton TaskQueue pool
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
493
diff
changeset
|
22 } |
46 | 23 } |
24 | |
25 int | |
26 TaskQueueInfo::extend_pool(int num) | |
27 { | |
494
ec7b6d89b4e4
Singleton TaskQueue pool
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
493
diff
changeset
|
28 TaskQueuePtr q = (TaskQueuePtr)malloc(sizeof(TaskQueue)*(num+1)); |
46 | 29 |
494
ec7b6d89b4e4
Singleton TaskQueue pool
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
493
diff
changeset
|
30 // First Queue is previous pool |
ec7b6d89b4e4
Singleton TaskQueue pool
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
493
diff
changeset
|
31 q->waiter = waiter; waiter = q; |
ec7b6d89b4e4
Singleton TaskQueue pool
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
493
diff
changeset
|
32 q++; |
46 | 33 |
34 /* Connect all free queue in the pool */ | |
494
ec7b6d89b4e4
Singleton TaskQueue pool
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
493
diff
changeset
|
35 TaskQueuePtr p = q; |
ec7b6d89b4e4
Singleton TaskQueue pool
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
493
diff
changeset
|
36 for (; --num > 0; p++) { |
ec7b6d89b4e4
Singleton TaskQueue pool
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
493
diff
changeset
|
37 p->task = NULL; |
ec7b6d89b4e4
Singleton TaskQueue pool
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
493
diff
changeset
|
38 p->waiter = NULL; |
ec7b6d89b4e4
Singleton TaskQueue pool
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
493
diff
changeset
|
39 addLast(p); |
46 | 40 } |
41 | |
42 return 0; | |
43 } | |
44 | |
45 TaskQueuePtr | |
109 | 46 TaskQueueInfo::create(TaskPtr task) |
46 | 47 { |
494
ec7b6d89b4e4
Singleton TaskQueue pool
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
493
diff
changeset
|
48 TaskQueuePtr q = taskQueuePool.poll(); |
ec7b6d89b4e4
Singleton TaskQueue pool
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
493
diff
changeset
|
49 if (! q) { |
ec7b6d89b4e4
Singleton TaskQueue pool
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
493
diff
changeset
|
50 taskQueuePool.extend_pool(64); |
ec7b6d89b4e4
Singleton TaskQueue pool
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
493
diff
changeset
|
51 q = taskQueuePool.poll(); |
46 | 52 } |
479
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
53 q->next = q->prev = NULL; |
481
4896dffad67c
Double linked list modification done (tested on Mac OS X)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
480
diff
changeset
|
54 q->waiter = NULL; |
494
ec7b6d89b4e4
Singleton TaskQueue pool
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
493
diff
changeset
|
55 q->task = task; |
46 | 56 |
57 return q; | |
58 } | |
59 | |
60 | |
61 void | |
493 | 62 TaskQueueInfo::free_(TaskQueuePtr q) |
46 | 63 { |
494
ec7b6d89b4e4
Singleton TaskQueue pool
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
493
diff
changeset
|
64 q->waiter = NULL; |
ec7b6d89b4e4
Singleton TaskQueue pool
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
493
diff
changeset
|
65 q->task = NULL; |
ec7b6d89b4e4
Singleton TaskQueue pool
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
493
diff
changeset
|
66 taskQueuePool.addLast(q); |
46 | 67 } |
479
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
68 |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
69 |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
70 /*! |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
71 TaskQueueInfo は空にならない。最低1個は要素が入っていて |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
72 1個目は特別扱いする。getFirst すると first->next を返す |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
73 */ |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
74 |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
75 /*! |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
76 最初の1個は特別扱いなので、それの後に追加していく |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
77 */ |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
78 void |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
79 TaskQueueInfo::addFirst(TaskQueue* e) |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
80 { |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
81 e->prev = first; |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
82 e->next = first->next; |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
83 first->next->prev = e; |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
84 first->next = e; |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
85 } |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
86 |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
87 void |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
88 TaskQueueInfo::addLast(TaskQueue* e) |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
89 { |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
90 e->next = first; |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
91 e->prev = last; |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
92 last->next = e; |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
93 last = e; |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
94 } |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
95 |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
96 TaskQueue* |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
97 TaskQueueInfo::getFirst() |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
98 { |
480
46464727d825
TaskQueueInfo initiaization...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
479
diff
changeset
|
99 if (empty()) return NULL; |
479
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
100 return first->next; |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
101 } |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
102 |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
103 TaskQueue* |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
104 TaskQueueInfo::getLast() |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
105 { |
480
46464727d825
TaskQueueInfo initiaization...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
479
diff
changeset
|
106 if (empty()) return NULL; |
479
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
107 return last; |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
108 } |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
109 |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
110 int |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
111 TaskQueueInfo::remove(TaskQueue* e) |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
112 { |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
113 e->prev->next = e->next; |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
114 e->next->prev = e->prev; |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
115 |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
116 if (first->next == e) { |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
117 first->next = e->next; |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
118 } |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
119 if (last == e) { |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
120 last = e->prev; |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
121 } |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
122 |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
123 e->prev = NULL; |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
124 e->next = NULL; |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
125 |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
126 return 1; |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
127 } |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
128 |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
129 /*! |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
130 リストの先頭を取得および削除する。リストが空の場合は NULL を返す。 |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
131 */ |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
132 |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
133 TaskQueue* |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
134 TaskQueueInfo::poll() |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
135 { |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
136 TaskQueue* e = first->next; |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
137 if (e == this) { |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
138 return NULL; |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
139 } |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
140 remove(e); |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
141 return e; |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
142 } |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
143 |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
144 void |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
145 TaskQueueInfo::moveToFirst(TaskQueue* e) |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
146 { |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
147 remove(e); |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
148 addFirst(e); |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
149 } |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
150 |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
151 /*! |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
152 リスト内の指定された位置にある要素を返す。 |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
153 要素数を超えた位置を指定した場合 NULL を返す。 |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
154 */ |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
155 |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
156 TaskQueue* |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
157 TaskQueueInfo::get(int index) |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
158 { |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
159 TaskQueue* e = first->next; |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
160 for (int i = 0; i < index; i++) { |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
161 if (e == this) return NULL; |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
162 e = e->next; |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
163 } |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
164 return e; |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
165 } |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
166 |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
167 TaskQueue* |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
168 TaskQueueInfo::find(Task* task) |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
169 { |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
170 TaskQueue* e = first->next; |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
171 for(;;) { |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
172 if (e == this) return NULL; |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
173 if (e->task == task) return e; |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
174 e = e->next; |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
175 } |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
176 return e; |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
177 } |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
178 |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
179 int |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
180 TaskQueueInfo::empty() |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
181 { |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
182 return next == this; |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
183 } |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
184 |
495 | 185 TaskQueue* |
186 TaskQueueInfo::getNext(TaskQueue* q) | |
187 { | |
188 if (q->next==this) return NULL; | |
189 return q->next; | |
190 } | |
191 | |
192 | |
479
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
193 |
5bda98b0b56d
Double Linked List base TaskQueue
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
109
diff
changeset
|
194 /* end */ |