annotate TaskManager/kernel/ppe/QueueInfo.h @ 1546:61164c687b29 draft

fix GpuScheduler flip
author Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
date Tue, 05 Feb 2013 13:15:46 +0900
parents c0dc96c6f209
children 99f8130793b4 b49aaf88eae6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
806
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 #ifndef INCLUDED_QUEUE_INFO
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 #define INCLUDED_QUEUE_INFO
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 #include "base.h"
821
4691b6ae44ec queueInfoTest 90% done
game@zeus.cr.ie.u-ryukyu.ac.jp
parents: 820
diff changeset
5 #include "types.h"
806
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6
818
5d48fa762a24 too few template-parameter-lists
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 806
diff changeset
7 #if 0
5d48fa762a24 too few template-parameter-lists
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 806
diff changeset
8 template <typename T> class Queue : T {
806
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 public:
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10
818
5d48fa762a24 too few template-parameter-lists
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 806
diff changeset
11 T();
806
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 T *waiter;
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 T *next;
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 T *prev;
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
16
958
338523ff6986 add freeOnce()
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 956
diff changeset
17 void initOnce(); // to initialize object in pool
338523ff6986 add freeOnce()
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 956
diff changeset
18 void freeOnce(); // to destroy object in pool
338523ff6986 add freeOnce()
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 956
diff changeset
19
818
5d48fa762a24 too few template-parameter-lists
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 806
diff changeset
20 // virual void init();
806
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 };
818
5d48fa762a24 too few template-parameter-lists
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 806
diff changeset
22 #endif
806
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
23
818
5d48fa762a24 too few template-parameter-lists
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 806
diff changeset
24 template <typename T> class QueueInfo : public T {
806
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
25
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 public:
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 /* constructor */
958
338523ff6986 add freeOnce()
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 956
diff changeset
28
338523ff6986 add freeOnce()
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 956
diff changeset
29 /**
962
8d6f7a42d134 QueueInfo fix
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 961
diff changeset
30 singleton queuePool constructor
8d6f7a42d134 QueueInfo fix
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 961
diff changeset
31 Do not use this as a Queue
958
338523ff6986 add freeOnce()
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 956
diff changeset
32 */
821
4691b6ae44ec queueInfoTest 90% done
game@zeus.cr.ie.u-ryukyu.ac.jp
parents: 820
diff changeset
33 QueueInfo<T>(){
4691b6ae44ec queueInfoTest 90% done
game@zeus.cr.ie.u-ryukyu.ac.jp
parents: 820
diff changeset
34 queueInfoInit();
4691b6ae44ec queueInfoTest 90% done
game@zeus.cr.ie.u-ryukyu.ac.jp
parents: 820
diff changeset
35 }
958
338523ff6986 add freeOnce()
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 956
diff changeset
36 /**
338523ff6986 add freeOnce()
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 956
diff changeset
37 normal constructor requires
338523ff6986 add freeOnce()
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 956
diff changeset
38 */
820
3c508c837ad8 give up singleton pattern.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 818
diff changeset
39 QueueInfo<T>(QueueInfo<T> *p) {
821
4691b6ae44ec queueInfoTest 90% done
game@zeus.cr.ie.u-ryukyu.ac.jp
parents: 820
diff changeset
40 queueInfoInit();
820
3c508c837ad8 give up singleton pattern.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 818
diff changeset
41 queuePool = p;
3c508c837ad8 give up singleton pattern.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 818
diff changeset
42 }
806
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
43
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
44 BASE_NEW_DELETE(QueueInfo);
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
45
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 /* functions */
818
5d48fa762a24 too few template-parameter-lists
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 806
diff changeset
47 T *create();
806
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
48
818
5d48fa762a24 too few template-parameter-lists
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 806
diff changeset
49 void free_(T *queue);
806
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
50
818
5d48fa762a24 too few template-parameter-lists
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 806
diff changeset
51 void addFirst(T* e);
5d48fa762a24 too few template-parameter-lists
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 806
diff changeset
52 void addLast(T* e);
5d48fa762a24 too few template-parameter-lists
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 806
diff changeset
53 T* getFirst();
5d48fa762a24 too few template-parameter-lists
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 806
diff changeset
54 T* getLast();
5d48fa762a24 too few template-parameter-lists
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 806
diff changeset
55 int remove(T* e);
5d48fa762a24 too few template-parameter-lists
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 806
diff changeset
56 T* poll();
5d48fa762a24 too few template-parameter-lists
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 806
diff changeset
57 void moveToFirst(T* e); // or use();
5d48fa762a24 too few template-parameter-lists
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 806
diff changeset
58 T* get(int index);
5d48fa762a24 too few template-parameter-lists
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 806
diff changeset
59 T* find(T *task);
806
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 int empty();
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 void freePool() ;
955
6ffeb543e8d4 unify all QueueInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 899
diff changeset
62 void freeAll();
806
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
63
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
64 // Iterator
818
5d48fa762a24 too few template-parameter-lists
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 806
diff changeset
65 T* getNext(T* q) ;
806
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
66 int length();
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
67
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
68 private:
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
69 /* variables */
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
70
958
338523ff6986 add freeOnce()
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 956
diff changeset
71 /* we cannot use static in template */
820
3c508c837ad8 give up singleton pattern.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 818
diff changeset
72 /* static */ QueueInfo<T> *queuePool;
818
5d48fa762a24 too few template-parameter-lists
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 806
diff changeset
73 T* first;
5d48fa762a24 too few template-parameter-lists
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 806
diff changeset
74 T* last;
806
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
75
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
76 /* functions */
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
77 int extend_pool(int num);
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
78 void destroy();
821
4691b6ae44ec queueInfoTest 90% done
game@zeus.cr.ie.u-ryukyu.ac.jp
parents: 820
diff changeset
79 void queueInfoInit();
899
1b9418af3127 minor fix..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 895
diff changeset
80 } ;
806
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
81
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
82
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
83
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
84 #ifdef CHECK
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
85 #include <stdio.h>
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
86 #endif
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
87 #include <stdlib.h>
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
88
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
89
958
338523ff6986 add freeOnce()
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 956
diff changeset
90 /**
962
8d6f7a42d134 QueueInfo fix
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 961
diff changeset
91 Use singleton queuePool constructor
958
338523ff6986 add freeOnce()
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 956
diff changeset
92 all queueInfo should share this as a pool.
338523ff6986 add freeOnce()
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 956
diff changeset
93
338523ff6986 add freeOnce()
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 956
diff changeset
94 exteren QueueInfo<H> pool;
338523ff6986 add freeOnce()
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 956
diff changeset
95 QueueInfo<H> pool = new QueueInfo<H>();
338523ff6986 add freeOnce()
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 956
diff changeset
96
338523ff6986 add freeOnce()
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 956
diff changeset
97 use this in non initialize envrionment is wrong.
338523ff6986 add freeOnce()
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 956
diff changeset
98 */
806
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
99
821
4691b6ae44ec queueInfoTest 90% done
game@zeus.cr.ie.u-ryukyu.ac.jp
parents: 820
diff changeset
100 template<typename T>void QueueInfo<T>::queueInfoInit() {
806
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
101 // 最初の一つは自分
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
102 first = last = this;
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
103 this->next = this->prev = this;
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
104 this->waiter = NULL;
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
105 }
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
106
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
107 template<typename T>void
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
108 QueueInfo<T>::freePool() {
820
3c508c837ad8 give up singleton pattern.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 818
diff changeset
109 for(T * p = queuePool->waiter; p; ) {
818
5d48fa762a24 too few template-parameter-lists
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 806
diff changeset
110 T * next = p->waiter;
806
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
111 p->waiter = NULL;
958
338523ff6986 add freeOnce()
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 956
diff changeset
112 p->freeOnce();
806
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
113 free(p);
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
114 p = next;
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
115 }
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
116 }
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
117
958
338523ff6986 add freeOnce()
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 956
diff changeset
118 /**
338523ff6986 add freeOnce()
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 956
diff changeset
119 all pools are shared among QueueInfo (separated by size and type).
338523ff6986 add freeOnce()
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 956
diff changeset
120 it automatically extended by 64.
338523ff6986 add freeOnce()
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 956
diff changeset
121 */
806
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
122 template<typename T>int
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
123 QueueInfo<T>::extend_pool(int num)
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
124 {
962
8d6f7a42d134 QueueInfo fix
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 961
diff changeset
125 #ifdef CHECK
8d6f7a42d134 QueueInfo fix
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 961
diff changeset
126 if (queuePool) fprintf(stderr, "don't use queuePool directly");
8d6f7a42d134 QueueInfo fix
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 961
diff changeset
127 #endif
8d6f7a42d134 QueueInfo fix
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 961
diff changeset
128
821
4691b6ae44ec queueInfoTest 90% done
game@zeus.cr.ie.u-ryukyu.ac.jp
parents: 820
diff changeset
129 T* q = (T*)malloc(sizeof(T)*(num+1)+DEFAULT_ALIGNMENT);
806
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
130
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
131 // First Queue is previous pool
1089
c0dc96c6f209 htask->init fix.
tkaito
parents: 962
diff changeset
132 q->waiter = this->waiter;
c0dc96c6f209 htask->init fix.
tkaito
parents: 962
diff changeset
133 this->waiter = q;
821
4691b6ae44ec queueInfoTest 90% done
game@zeus.cr.ie.u-ryukyu.ac.jp
parents: 820
diff changeset
134 q = (T*)ROUND_UP_ALIGN((long)q, DEFAULT_ALIGNMENT);
806
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
135 q++;
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
136
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
137 /* Connect all free queue in the pool */
821
4691b6ae44ec queueInfoTest 90% done
game@zeus.cr.ie.u-ryukyu.ac.jp
parents: 820
diff changeset
138 T* p = q;
4691b6ae44ec queueInfoTest 90% done
game@zeus.cr.ie.u-ryukyu.ac.jp
parents: 820
diff changeset
139 for (; num-- > 0;) {
4691b6ae44ec queueInfoTest 90% done
game@zeus.cr.ie.u-ryukyu.ac.jp
parents: 820
diff changeset
140 p->waiter = NULL;
956
197b7e19a345 unified queue worked on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 955
diff changeset
141 p->initOnce();
962
8d6f7a42d134 QueueInfo fix
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 961
diff changeset
142 addLast(p);
821
4691b6ae44ec queueInfoTest 90% done
game@zeus.cr.ie.u-ryukyu.ac.jp
parents: 820
diff changeset
143 p = (T*)ROUND_UP_ALIGN((long)(p+1),DEFAULT_ALIGNMENT);
806
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
144 }
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
145
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
146 return 0;
821
4691b6ae44ec queueInfoTest 90% done
game@zeus.cr.ie.u-ryukyu.ac.jp
parents: 820
diff changeset
147
806
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
148 }
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
149
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
150 /**
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
151 * Task をプールから取って来て返す
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
152 *
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
153 * @param [cmd] タスクコマンド
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
154 */
818
5d48fa762a24 too few template-parameter-lists
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 806
diff changeset
155 template<typename T>T *
806
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
156 QueueInfo<T>::create()
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
157 {
820
3c508c837ad8 give up singleton pattern.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 818
diff changeset
158 T * q = queuePool->poll();
806
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
159 if (! q) {
820
3c508c837ad8 give up singleton pattern.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 818
diff changeset
160 queuePool->extend_pool(64);
3c508c837ad8 give up singleton pattern.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 818
diff changeset
161 q = queuePool->poll();
806
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
162 }
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
163 q->init();
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
164 return q;
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
165 }
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
166
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
167
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
168 template<typename T>void
818
5d48fa762a24 too few template-parameter-lists
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 806
diff changeset
169 QueueInfo<T>::free_(T * q)
806
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
170 {
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
171 q->waiter = NULL;
820
3c508c837ad8 give up singleton pattern.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 818
diff changeset
172 queuePool->addLast(q);
806
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
173 }
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
174
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
175
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
176 /*!
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
177 QueueInfo<T> は空にならない。最低1個は要素が入っていて
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
178 1個目は特別扱いする。getFirst すると first->next を返す
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
179 */
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
180
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
181 /*!
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
182 最初の1個は特別扱いなので、それの後に追加していく
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
183 */
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
184 template<typename T>void
818
5d48fa762a24 too few template-parameter-lists
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 806
diff changeset
185 QueueInfo<T>::addFirst(T* e)
806
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
186 {
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
187 e->prev = first;
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
188 e->next = first->next;
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
189 first->next->prev = e;
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
190 first->next = e;
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
191 }
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
192
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
193 template<typename T>void
818
5d48fa762a24 too few template-parameter-lists
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 806
diff changeset
194 QueueInfo<T>::addLast(T* e)
806
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
195 {
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
196 #ifdef CHECK
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
197 if (find(e)) {
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
198 fprintf(stderr,"Add duplicate task %0x\n",(int)e);
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
199 return;
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
200 // ...
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
201 }
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
202 #endif
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
203 e->next = first;
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
204 e->prev = last;
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
205 last->next = e;
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
206 last = e;
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
207 }
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
208
818
5d48fa762a24 too few template-parameter-lists
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 806
diff changeset
209 template<typename T>T*
806
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
210 QueueInfo<T>::getFirst()
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
211 {
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
212 if (empty()) return NULL;
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
213 return first->next;
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
214 }
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
215
818
5d48fa762a24 too few template-parameter-lists
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 806
diff changeset
216 template<typename T>T*
806
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
217 QueueInfo<T>::getLast()
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
218 {
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
219 if (empty()) return NULL;
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
220 return last;
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
221 }
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
222
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
223 template<typename T>int
818
5d48fa762a24 too few template-parameter-lists
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 806
diff changeset
224 QueueInfo<T>::remove(T* e)
806
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
225 {
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
226 #ifdef CHECK
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
227 if (!find(e)) {
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
228 fprintf(stderr,"Remove non existing task %0x\n",(int)e);
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
229 return 0;
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
230 // ...
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
231 }
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
232 #endif
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
233 e->prev->next = e->next;
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
234 e->next->prev = e->prev;
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
235
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
236 if (first->next == e) {
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
237 first->next = e->next;
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
238 }
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
239 if (last == e) {
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
240 last = e->prev;
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
241 }
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
242
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
243 e->prev = NULL;
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
244 e->next = NULL;
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
245
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
246 return 1;
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
247 }
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
248
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
249 /*!
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
250 リストの先頭を取得および削除する。リストが空の場合は NULL を返す。
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
251 */
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
252
818
5d48fa762a24 too few template-parameter-lists
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 806
diff changeset
253 template<typename T>T*
806
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
254 QueueInfo<T>::poll()
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
255 {
818
5d48fa762a24 too few template-parameter-lists
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 806
diff changeset
256 T* e = first->next;
806
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
257 if (e == this) {
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
258 return NULL;
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
259 }
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
260 remove(e);
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
261 return e;
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
262 }
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
263
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
264 template<typename T>void
818
5d48fa762a24 too few template-parameter-lists
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 806
diff changeset
265 QueueInfo<T>::moveToFirst(T* e)
806
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
266 {
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
267 remove(e);
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
268 addFirst(e);
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
269 }
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
270
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
271 /*!
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
272 リスト内の指定された位置にある要素を返す。
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
273 要素数を超えた位置を指定した場合 NULL を返す。
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
274 */
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
275
818
5d48fa762a24 too few template-parameter-lists
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 806
diff changeset
276 template<typename T>T*
806
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
277 QueueInfo<T>::get(int index)
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
278 {
818
5d48fa762a24 too few template-parameter-lists
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 806
diff changeset
279 T* e = first->next;
806
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
280 for (int i = 0; i < index; i++) {
822
d0361d459338 testQueueInfo 100% passed
game@zeus.cr.ie.u-ryukyu.ac.jp
parents: 821
diff changeset
281 if (e->next == this) return NULL;
806
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
282 e = e->next;
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
283 }
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
284 return e;
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
285 }
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
286
818
5d48fa762a24 too few template-parameter-lists
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 806
diff changeset
287 template<typename T>T*
5d48fa762a24 too few template-parameter-lists
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 806
diff changeset
288 QueueInfo<T>::find(T* task)
806
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
289 {
818
5d48fa762a24 too few template-parameter-lists
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 806
diff changeset
290 T* e = first->next;
806
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
291 for(;;) {
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
292 if (e == this) return NULL;
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
293 if (e == task) break;
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
294 e = e->next;
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
295 }
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
296 return e;
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
297 }
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
298
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
299 template<typename T>int
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
300 QueueInfo<T>::empty()
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
301 {
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
302 return this->next == this;
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
303 }
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
304
818
5d48fa762a24 too few template-parameter-lists
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 806
diff changeset
305 template<typename T>T*
5d48fa762a24 too few template-parameter-lists
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 806
diff changeset
306 QueueInfo<T>::getNext(T* q)
806
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
307 {
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
308 if (q->next==this) return NULL;
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
309 return q->next;
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
310 }
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
311
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
312 template<typename T>int
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
313 QueueInfo<T>::length()
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
314 {
822
d0361d459338 testQueueInfo 100% passed
game@zeus.cr.ie.u-ryukyu.ac.jp
parents: 821
diff changeset
315 int i = 0;
806
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
316 if (empty()) return 0;
818
5d48fa762a24 too few template-parameter-lists
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 806
diff changeset
317 T* e = first;
806
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
318 while((e = e->next) != this ) i++;
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
319 return i;
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
320 }
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
321
955
6ffeb543e8d4 unify all QueueInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 899
diff changeset
322 template<typename T>void
6ffeb543e8d4 unify all QueueInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 899
diff changeset
323 QueueInfo<T>::freeAll()
6ffeb543e8d4 unify all QueueInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 899
diff changeset
324 {
6ffeb543e8d4 unify all QueueInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 899
diff changeset
325 T* t;
6ffeb543e8d4 unify all QueueInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 899
diff changeset
326 while((t=poll())) free_(t);
6ffeb543e8d4 unify all QueueInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 899
diff changeset
327 }
806
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
328
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
329
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
330
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
331 /* end */
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
332
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
333
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
334
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
335 #endif