annotate TaskManager/kernel/ppe/QueueInfo.h @ 961:efee36d2f84c draft

fix QueueInfo
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Wed, 04 Aug 2010 23:05:59 +0900
parents 338523ff6986
children 8d6f7a42d134
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 /**
338523ff6986 add freeOnce()
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 956
diff changeset
30 singleton constructor
338523ff6986 add freeOnce()
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 956
diff changeset
31 use this in non initialize envrionment is wrong.
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();
961
efee36d2f84c fix QueueInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 958
diff changeset
35 queuePool = this;
821
4691b6ae44ec queueInfoTest 90% done
game@zeus.cr.ie.u-ryukyu.ac.jp
parents: 820
diff changeset
36 }
958
338523ff6986 add freeOnce()
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 956
diff changeset
37 /**
338523ff6986 add freeOnce()
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 956
diff changeset
38 normal constructor requires
338523ff6986 add freeOnce()
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 956
diff changeset
39 */
820
3c508c837ad8 give up singleton pattern.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 818
diff changeset
40 QueueInfo<T>(QueueInfo<T> *p) {
821
4691b6ae44ec queueInfoTest 90% done
game@zeus.cr.ie.u-ryukyu.ac.jp
parents: 820
diff changeset
41 queueInfoInit();
820
3c508c837ad8 give up singleton pattern.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 818
diff changeset
42 queuePool = p;
3c508c837ad8 give up singleton pattern.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 818
diff changeset
43 }
806
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
44
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
45 BASE_NEW_DELETE(QueueInfo);
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
46
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 /* functions */
818
5d48fa762a24 too few template-parameter-lists
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 806
diff changeset
48 T *create();
806
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
49
818
5d48fa762a24 too few template-parameter-lists
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 806
diff changeset
50 void free_(T *queue);
806
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
51
818
5d48fa762a24 too few template-parameter-lists
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 806
diff changeset
52 void addFirst(T* e);
5d48fa762a24 too few template-parameter-lists
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 806
diff changeset
53 void addLast(T* e);
5d48fa762a24 too few template-parameter-lists
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 806
diff changeset
54 T* getFirst();
5d48fa762a24 too few template-parameter-lists
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 806
diff changeset
55 T* getLast();
5d48fa762a24 too few template-parameter-lists
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 806
diff changeset
56 int remove(T* e);
5d48fa762a24 too few template-parameter-lists
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 806
diff changeset
57 T* poll();
5d48fa762a24 too few template-parameter-lists
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 806
diff changeset
58 void moveToFirst(T* e); // or use();
5d48fa762a24 too few template-parameter-lists
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 806
diff changeset
59 T* get(int index);
5d48fa762a24 too few template-parameter-lists
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 806
diff changeset
60 T* find(T *task);
806
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 int empty();
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
62 void freePool() ;
955
6ffeb543e8d4 unify all QueueInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 899
diff changeset
63 void freeAll();
806
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
64
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
65 // Iterator
818
5d48fa762a24 too few template-parameter-lists
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 806
diff changeset
66 T* getNext(T* q) ;
806
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
67 int length();
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
68
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
69 private:
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
70 /* variables */
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
71
958
338523ff6986 add freeOnce()
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 956
diff changeset
72 /* we cannot use static in template */
820
3c508c837ad8 give up singleton pattern.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 818
diff changeset
73 /* static */ QueueInfo<T> *queuePool;
818
5d48fa762a24 too few template-parameter-lists
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 806
diff changeset
74 T* first;
5d48fa762a24 too few template-parameter-lists
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 806
diff changeset
75 T* last;
806
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
76
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
77 /* functions */
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
78 int extend_pool(int num);
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
79 void destroy();
821
4691b6ae44ec queueInfoTest 90% done
game@zeus.cr.ie.u-ryukyu.ac.jp
parents: 820
diff changeset
80 void queueInfoInit();
899
1b9418af3127 minor fix..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 895
diff changeset
81 } ;
806
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
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
85 #ifdef CHECK
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
86 #include <stdio.h>
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
87 #endif
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
88 #include <stdlib.h>
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
89
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
90
958
338523ff6986 add freeOnce()
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 956
diff changeset
91 /**
338523ff6986 add freeOnce()
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 956
diff changeset
92 singleton constructor
338523ff6986 add freeOnce()
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 956
diff changeset
93 all queueInfo should share this as a pool.
338523ff6986 add freeOnce()
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 956
diff changeset
94
338523ff6986 add freeOnce()
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 956
diff changeset
95 exteren QueueInfo<H> pool;
338523ff6986 add freeOnce()
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 956
diff changeset
96 QueueInfo<H> pool = new QueueInfo<H>();
338523ff6986 add freeOnce()
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 956
diff changeset
97
338523ff6986 add freeOnce()
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 956
diff changeset
98 use this in non initialize envrionment is wrong.
338523ff6986 add freeOnce()
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 956
diff changeset
99 */
806
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
100
821
4691b6ae44ec queueInfoTest 90% done
game@zeus.cr.ie.u-ryukyu.ac.jp
parents: 820
diff changeset
101 template<typename T>void QueueInfo<T>::queueInfoInit() {
806
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
102 // 最初の一つは自分
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
103 first = last = this;
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
104 this->next = this->prev = this;
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
105 this->waiter = NULL;
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
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
108 template<typename T>void
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
109 QueueInfo<T>::freePool() {
820
3c508c837ad8 give up singleton pattern.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 818
diff changeset
110 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
111 T * next = p->waiter;
806
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
112 p->waiter = NULL;
958
338523ff6986 add freeOnce()
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 956
diff changeset
113 p->freeOnce();
806
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
114 free(p);
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
115 p = next;
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 }
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
118
958
338523ff6986 add freeOnce()
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 956
diff changeset
119 /**
338523ff6986 add freeOnce()
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 956
diff changeset
120 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
121 it automatically extended by 64.
338523ff6986 add freeOnce()
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 956
diff changeset
122 */
806
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
123 template<typename T>int
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
124 QueueInfo<T>::extend_pool(int num)
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
125 {
821
4691b6ae44ec queueInfoTest 90% done
game@zeus.cr.ie.u-ryukyu.ac.jp
parents: 820
diff changeset
126 T* q = (T*)malloc(sizeof(T)*(num+1)+DEFAULT_ALIGNMENT);
806
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
127
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
128 // First Queue is previous pool
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
129 q->waiter = this->waiter; this->waiter = q;
821
4691b6ae44ec queueInfoTest 90% done
game@zeus.cr.ie.u-ryukyu.ac.jp
parents: 820
diff changeset
130 q = (T*)ROUND_UP_ALIGN((long)q, DEFAULT_ALIGNMENT);
806
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
131 q++;
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
132
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
133 /* Connect all free queue in the pool */
821
4691b6ae44ec queueInfoTest 90% done
game@zeus.cr.ie.u-ryukyu.ac.jp
parents: 820
diff changeset
134 T* p = q;
4691b6ae44ec queueInfoTest 90% done
game@zeus.cr.ie.u-ryukyu.ac.jp
parents: 820
diff changeset
135 for (; num-- > 0;) {
4691b6ae44ec queueInfoTest 90% done
game@zeus.cr.ie.u-ryukyu.ac.jp
parents: 820
diff changeset
136 p->waiter = NULL;
956
197b7e19a345 unified queue worked on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 955
diff changeset
137 p->initOnce();
821
4691b6ae44ec queueInfoTest 90% done
game@zeus.cr.ie.u-ryukyu.ac.jp
parents: 820
diff changeset
138 queuePool->addLast(p);
4691b6ae44ec queueInfoTest 90% done
game@zeus.cr.ie.u-ryukyu.ac.jp
parents: 820
diff changeset
139 p = (T*)ROUND_UP_ALIGN((long)(p+1),DEFAULT_ALIGNMENT);
806
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
140 }
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
141
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
142 return 0;
821
4691b6ae44ec queueInfoTest 90% done
game@zeus.cr.ie.u-ryukyu.ac.jp
parents: 820
diff changeset
143
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 /**
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
147 * Task をプールから取って来て返す
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 * @param [cmd] タスクコマンド
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
150 */
818
5d48fa762a24 too few template-parameter-lists
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 806
diff changeset
151 template<typename T>T *
806
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
152 QueueInfo<T>::create()
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
153 {
820
3c508c837ad8 give up singleton pattern.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 818
diff changeset
154 T * q = queuePool->poll();
806
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
155 if (! q) {
820
3c508c837ad8 give up singleton pattern.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 818
diff changeset
156 queuePool->extend_pool(64);
3c508c837ad8 give up singleton pattern.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 818
diff changeset
157 q = queuePool->poll();
806
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
158 }
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
159 q->init();
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
160 return q;
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
161 }
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
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
164 template<typename T>void
818
5d48fa762a24 too few template-parameter-lists
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 806
diff changeset
165 QueueInfo<T>::free_(T * q)
806
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 q->waiter = NULL;
820
3c508c837ad8 give up singleton pattern.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 818
diff changeset
168 queuePool->addLast(q);
806
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
169 }
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
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
172 /*!
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
173 QueueInfo<T> は空にならない。最低1個は要素が入っていて
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
174 1個目は特別扱いする。getFirst すると first->next を返す
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 /*!
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
178 最初の1個は特別扱いなので、それの後に追加していく
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 template<typename T>void
818
5d48fa762a24 too few template-parameter-lists
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 806
diff changeset
181 QueueInfo<T>::addFirst(T* e)
806
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
182 {
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
183 e->prev = first;
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
184 e->next = first->next;
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
185 first->next->prev = e;
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
186 first->next = e;
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
187 }
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
188
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
189 template<typename T>void
818
5d48fa762a24 too few template-parameter-lists
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 806
diff changeset
190 QueueInfo<T>::addLast(T* e)
806
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 #ifdef CHECK
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
193 if (find(e)) {
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
194 fprintf(stderr,"Add duplicate task %0x\n",(int)e);
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
195 return;
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
196 // ...
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
197 }
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
198 #endif
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
199 e->next = first;
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
200 e->prev = last;
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
201 last->next = e;
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
202 last = e;
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
203 }
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
204
818
5d48fa762a24 too few template-parameter-lists
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 806
diff changeset
205 template<typename T>T*
806
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
206 QueueInfo<T>::getFirst()
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 if (empty()) return NULL;
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
209 return first->next;
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
210 }
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
211
818
5d48fa762a24 too few template-parameter-lists
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 806
diff changeset
212 template<typename T>T*
806
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
213 QueueInfo<T>::getLast()
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 if (empty()) return NULL;
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
216 return last;
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
217 }
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 template<typename T>int
818
5d48fa762a24 too few template-parameter-lists
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 806
diff changeset
220 QueueInfo<T>::remove(T* e)
806
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 #ifdef CHECK
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
223 if (!find(e)) {
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
224 fprintf(stderr,"Remove non existing task %0x\n",(int)e);
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
225 return 0;
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
226 // ...
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
227 }
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
228 #endif
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
229 e->prev->next = e->next;
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
230 e->next->prev = e->prev;
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 if (first->next == e) {
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
233 first->next = e->next;
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
234 }
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
235 if (last == e) {
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
236 last = e->prev;
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
237 }
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 e->prev = NULL;
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
240 e->next = NULL;
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 return 1;
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
243 }
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
244
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 リストの先頭を取得および削除する。リストが空の場合は NULL を返す。
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
818
5d48fa762a24 too few template-parameter-lists
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 806
diff changeset
249 template<typename T>T*
806
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
250 QueueInfo<T>::poll()
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
251 {
818
5d48fa762a24 too few template-parameter-lists
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 806
diff changeset
252 T* e = first->next;
806
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
253 if (e == this) {
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
254 return NULL;
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
255 }
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
256 remove(e);
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
257 return e;
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
258 }
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 template<typename T>void
818
5d48fa762a24 too few template-parameter-lists
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 806
diff changeset
261 QueueInfo<T>::moveToFirst(T* e)
806
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 remove(e);
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
264 addFirst(e);
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
265 }
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 /*!
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
268 リスト内の指定された位置にある要素を返す。
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
269 要素数を超えた位置を指定した場合 NULL を返す。
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
818
5d48fa762a24 too few template-parameter-lists
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 806
diff changeset
272 template<typename T>T*
806
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
273 QueueInfo<T>::get(int index)
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
274 {
818
5d48fa762a24 too few template-parameter-lists
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 806
diff changeset
275 T* e = first->next;
806
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
276 for (int i = 0; i < index; i++) {
822
d0361d459338 testQueueInfo 100% passed
game@zeus.cr.ie.u-ryukyu.ac.jp
parents: 821
diff changeset
277 if (e->next == this) return NULL;
806
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
278 e = e->next;
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
279 }
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
280 return e;
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
281 }
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
282
818
5d48fa762a24 too few template-parameter-lists
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 806
diff changeset
283 template<typename T>T*
5d48fa762a24 too few template-parameter-lists
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 806
diff changeset
284 QueueInfo<T>::find(T* task)
806
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
285 {
818
5d48fa762a24 too few template-parameter-lists
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 806
diff changeset
286 T* e = first->next;
806
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
287 for(;;) {
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
288 if (e == this) return NULL;
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
289 if (e == task) break;
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
290 e = e->next;
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
291 }
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
292 return e;
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
293 }
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
294
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
295 template<typename T>int
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
296 QueueInfo<T>::empty()
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 return this->next == this;
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
299 }
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
300
818
5d48fa762a24 too few template-parameter-lists
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 806
diff changeset
301 template<typename T>T*
5d48fa762a24 too few template-parameter-lists
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 806
diff changeset
302 QueueInfo<T>::getNext(T* q)
806
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 if (q->next==this) return NULL;
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
305 return q->next;
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
306 }
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 template<typename T>int
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
309 QueueInfo<T>::length()
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
310 {
822
d0361d459338 testQueueInfo 100% passed
game@zeus.cr.ie.u-ryukyu.ac.jp
parents: 821
diff changeset
311 int i = 0;
806
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
312 if (empty()) return 0;
818
5d48fa762a24 too few template-parameter-lists
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 806
diff changeset
313 T* e = first;
806
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
314 while((e = e->next) != this ) i++;
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
315 return i;
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
316 }
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
317
955
6ffeb543e8d4 unify all QueueInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 899
diff changeset
318 template<typename T>void
6ffeb543e8d4 unify all QueueInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 899
diff changeset
319 QueueInfo<T>::freeAll()
6ffeb543e8d4 unify all QueueInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 899
diff changeset
320 {
6ffeb543e8d4 unify all QueueInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 899
diff changeset
321 T* t;
6ffeb543e8d4 unify all QueueInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 899
diff changeset
322 while((t=poll())) free_(t);
6ffeb543e8d4 unify all QueueInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 899
diff changeset
323 }
806
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
324
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
325
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
326
fb49e881f2ed TaslListInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
327 /* end */
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 #endif