annotate TaskManager/kernel/memory/MemList.cc @ 370:4748fd7dcd89 draft

change TaskManger & memory/* & Random
author aaa
date Wed, 29 Jul 2009 15:09:36 +0900
parents 93b33cecba37
children 801d57ae1e29
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
368
1a80a2aa696c change TaskManager
aaa
parents: 367
diff changeset
1 /*!
1a80a2aa696c change TaskManager
aaa
parents: 367
diff changeset
2 MemList は空にならない。最低1個は要素が入っていて
1a80a2aa696c change TaskManager
aaa
parents: 367
diff changeset
3 1個目は特別扱いする。getFirst すると first->next を返す
1a80a2aa696c change TaskManager
aaa
parents: 367
diff changeset
4 */
369
93b33cecba37 change TaskManager.cc
aaa
parents: 368
diff changeset
5 #include <stdio.h>
93b33cecba37 change TaskManager.cc
aaa
parents: 368
diff changeset
6 #include "MemList.h"
368
1a80a2aa696c change TaskManager
aaa
parents: 367
diff changeset
7
1a80a2aa696c change TaskManager
aaa
parents: 367
diff changeset
8 /*!
1a80a2aa696c change TaskManager
aaa
parents: 367
diff changeset
9 最初の1個は特別扱いなので、それの後に追加していく
1a80a2aa696c change TaskManager
aaa
parents: 367
diff changeset
10 */
366
0251d06467de rename include/TaskManager/* and add memory
aaa
parents:
diff changeset
11 void
369
93b33cecba37 change TaskManager.cc
aaa
parents: 368
diff changeset
12 MemList::addFirst(MemorySegment* e)
366
0251d06467de rename include/TaskManager/* and add memory
aaa
parents:
diff changeset
13 {
368
1a80a2aa696c change TaskManager
aaa
parents: 367
diff changeset
14 e->prev = first;
1a80a2aa696c change TaskManager
aaa
parents: 367
diff changeset
15 e->next = first->next;
1a80a2aa696c change TaskManager
aaa
parents: 367
diff changeset
16 first->next->prev = e;
1a80a2aa696c change TaskManager
aaa
parents: 367
diff changeset
17 first->next = e;
366
0251d06467de rename include/TaskManager/* and add memory
aaa
parents:
diff changeset
18 }
0251d06467de rename include/TaskManager/* and add memory
aaa
parents:
diff changeset
19
0251d06467de rename include/TaskManager/* and add memory
aaa
parents:
diff changeset
20 void
369
93b33cecba37 change TaskManager.cc
aaa
parents: 368
diff changeset
21 MemList::addLast(MemorySegment* e)
366
0251d06467de rename include/TaskManager/* and add memory
aaa
parents:
diff changeset
22 {
368
1a80a2aa696c change TaskManager
aaa
parents: 367
diff changeset
23 e->next = first;
1a80a2aa696c change TaskManager
aaa
parents: 367
diff changeset
24 e->prev = last;
1a80a2aa696c change TaskManager
aaa
parents: 367
diff changeset
25 last->next = e;
366
0251d06467de rename include/TaskManager/* and add memory
aaa
parents:
diff changeset
26 last = e;
0251d06467de rename include/TaskManager/* and add memory
aaa
parents:
diff changeset
27 }
0251d06467de rename include/TaskManager/* and add memory
aaa
parents:
diff changeset
28
369
93b33cecba37 change TaskManager.cc
aaa
parents: 368
diff changeset
29 MemorySegment*
93b33cecba37 change TaskManager.cc
aaa
parents: 368
diff changeset
30 MemList::getFirst()
366
0251d06467de rename include/TaskManager/* and add memory
aaa
parents:
diff changeset
31 {
368
1a80a2aa696c change TaskManager
aaa
parents: 367
diff changeset
32 return first->next;
366
0251d06467de rename include/TaskManager/* and add memory
aaa
parents:
diff changeset
33 }
0251d06467de rename include/TaskManager/* and add memory
aaa
parents:
diff changeset
34
369
93b33cecba37 change TaskManager.cc
aaa
parents: 368
diff changeset
35 MemorySegment*
93b33cecba37 change TaskManager.cc
aaa
parents: 368
diff changeset
36 MemList::getLast()
366
0251d06467de rename include/TaskManager/* and add memory
aaa
parents:
diff changeset
37 {
368
1a80a2aa696c change TaskManager
aaa
parents: 367
diff changeset
38 return last;
366
0251d06467de rename include/TaskManager/* and add memory
aaa
parents:
diff changeset
39 }
0251d06467de rename include/TaskManager/* and add memory
aaa
parents:
diff changeset
40
368
1a80a2aa696c change TaskManager
aaa
parents: 367
diff changeset
41 int
369
93b33cecba37 change TaskManager.cc
aaa
parents: 368
diff changeset
42 MemList::remove(MemorySegment* e)
366
0251d06467de rename include/TaskManager/* and add memory
aaa
parents:
diff changeset
43 {
368
1a80a2aa696c change TaskManager
aaa
parents: 367
diff changeset
44 e->prev->next = e->next;
370
4748fd7dcd89 change TaskManger & memory/* & Random
aaa
parents: 369
diff changeset
45 e->next->prev = e->prev;
4748fd7dcd89 change TaskManger & memory/* & Random
aaa
parents: 369
diff changeset
46
4748fd7dcd89 change TaskManger & memory/* & Random
aaa
parents: 369
diff changeset
47 if (first->next == e) {
4748fd7dcd89 change TaskManger & memory/* & Random
aaa
parents: 369
diff changeset
48 first->next = e->next;
368
1a80a2aa696c change TaskManager
aaa
parents: 367
diff changeset
49 }
370
4748fd7dcd89 change TaskManger & memory/* & Random
aaa
parents: 369
diff changeset
50 if (last == e) {
4748fd7dcd89 change TaskManger & memory/* & Random
aaa
parents: 369
diff changeset
51 last = e->prev;
4748fd7dcd89 change TaskManger & memory/* & Random
aaa
parents: 369
diff changeset
52 }
4748fd7dcd89 change TaskManger & memory/* & Random
aaa
parents: 369
diff changeset
53
368
1a80a2aa696c change TaskManager
aaa
parents: 367
diff changeset
54 e->prev = NULL;
1a80a2aa696c change TaskManager
aaa
parents: 367
diff changeset
55 e->next = NULL;
1a80a2aa696c change TaskManager
aaa
parents: 367
diff changeset
56
1a80a2aa696c change TaskManager
aaa
parents: 367
diff changeset
57 return 1;
366
0251d06467de rename include/TaskManager/* and add memory
aaa
parents:
diff changeset
58 }
0251d06467de rename include/TaskManager/* and add memory
aaa
parents:
diff changeset
59
370
4748fd7dcd89 change TaskManger & memory/* & Random
aaa
parents: 369
diff changeset
60 /*!
4748fd7dcd89 change TaskManger & memory/* & Random
aaa
parents: 369
diff changeset
61 リストの先頭を取得および削除する。リストが空の場合は NULL を返す。
4748fd7dcd89 change TaskManger & memory/* & Random
aaa
parents: 369
diff changeset
62 */
4748fd7dcd89 change TaskManger & memory/* & Random
aaa
parents: 369
diff changeset
63
4748fd7dcd89 change TaskManger & memory/* & Random
aaa
parents: 369
diff changeset
64 MemorySegment*
4748fd7dcd89 change TaskManger & memory/* & Random
aaa
parents: 369
diff changeset
65 MemList::poll()
4748fd7dcd89 change TaskManger & memory/* & Random
aaa
parents: 369
diff changeset
66 {
4748fd7dcd89 change TaskManger & memory/* & Random
aaa
parents: 369
diff changeset
67 MemorySegment* e = first->next;
4748fd7dcd89 change TaskManger & memory/* & Random
aaa
parents: 369
diff changeset
68 if (e == this) {
4748fd7dcd89 change TaskManger & memory/* & Random
aaa
parents: 369
diff changeset
69 return NULL;
4748fd7dcd89 change TaskManger & memory/* & Random
aaa
parents: 369
diff changeset
70 }
4748fd7dcd89 change TaskManger & memory/* & Random
aaa
parents: 369
diff changeset
71 remove(e);
4748fd7dcd89 change TaskManger & memory/* & Random
aaa
parents: 369
diff changeset
72 return e;
4748fd7dcd89 change TaskManger & memory/* & Random
aaa
parents: 369
diff changeset
73 }
4748fd7dcd89 change TaskManger & memory/* & Random
aaa
parents: 369
diff changeset
74
366
0251d06467de rename include/TaskManager/* and add memory
aaa
parents:
diff changeset
75 void
369
93b33cecba37 change TaskManager.cc
aaa
parents: 368
diff changeset
76 MemList::moveToFirst(MemorySegment* e)
366
0251d06467de rename include/TaskManager/* and add memory
aaa
parents:
diff changeset
77 {
0251d06467de rename include/TaskManager/* and add memory
aaa
parents:
diff changeset
78 remove(e);
0251d06467de rename include/TaskManager/* and add memory
aaa
parents:
diff changeset
79 addFirst(e);
0251d06467de rename include/TaskManager/* and add memory
aaa
parents:
diff changeset
80 }
370
4748fd7dcd89 change TaskManger & memory/* & Random
aaa
parents: 369
diff changeset
81
4748fd7dcd89 change TaskManger & memory/* & Random
aaa
parents: 369
diff changeset
82 /*!
4748fd7dcd89 change TaskManger & memory/* & Random
aaa
parents: 369
diff changeset
83 リスト内の指定された位置にある要素を返す。
4748fd7dcd89 change TaskManger & memory/* & Random
aaa
parents: 369
diff changeset
84 要素数を超えた位置を指定した場合 NULL を返す。
4748fd7dcd89 change TaskManger & memory/* & Random
aaa
parents: 369
diff changeset
85 */
4748fd7dcd89 change TaskManger & memory/* & Random
aaa
parents: 369
diff changeset
86
4748fd7dcd89 change TaskManger & memory/* & Random
aaa
parents: 369
diff changeset
87 MemorySegment*
4748fd7dcd89 change TaskManger & memory/* & Random
aaa
parents: 369
diff changeset
88 MemList::get(int index)
4748fd7dcd89 change TaskManger & memory/* & Random
aaa
parents: 369
diff changeset
89 {
4748fd7dcd89 change TaskManger & memory/* & Random
aaa
parents: 369
diff changeset
90 MemorySegment* e = first->next;
4748fd7dcd89 change TaskManger & memory/* & Random
aaa
parents: 369
diff changeset
91 for (int i = 0; i < index; i++) {
4748fd7dcd89 change TaskManger & memory/* & Random
aaa
parents: 369
diff changeset
92 if (e == this) return NULL;
4748fd7dcd89 change TaskManger & memory/* & Random
aaa
parents: 369
diff changeset
93 e = e->next;
4748fd7dcd89 change TaskManger & memory/* & Random
aaa
parents: 369
diff changeset
94 }
4748fd7dcd89 change TaskManger & memory/* & Random
aaa
parents: 369
diff changeset
95 return e;
4748fd7dcd89 change TaskManger & memory/* & Random
aaa
parents: 369
diff changeset
96 }