Mercurial > hg > Game > Cerium
comparison 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 |
comparison
equal
deleted
inserted
replaced
369:93b33cecba37 | 370:4748fd7dcd89 |
---|---|
40 | 40 |
41 int | 41 int |
42 MemList::remove(MemorySegment* e) | 42 MemList::remove(MemorySegment* e) |
43 { | 43 { |
44 e->prev->next = e->next; | 44 e->prev->next = e->next; |
45 if (e->next != NULL) { | 45 e->next->prev = e->prev; |
46 e->next->prev = e->prev; | 46 |
47 if (first->next == e) { | |
48 first->next = e->next; | |
47 } | 49 } |
50 if (last == e) { | |
51 last = e->prev; | |
52 } | |
53 | |
48 e->prev = NULL; | 54 e->prev = NULL; |
49 e->next = NULL; | 55 e->next = NULL; |
50 | 56 |
51 return 1; | 57 return 1; |
58 } | |
59 | |
60 /*! | |
61 リストの先頭を取得および削除する。リストが空の場合は NULL を返す。 | |
62 */ | |
63 | |
64 MemorySegment* | |
65 MemList::poll() | |
66 { | |
67 MemorySegment* e = first->next; | |
68 if (e == this) { | |
69 return NULL; | |
70 } | |
71 remove(e); | |
72 return e; | |
52 } | 73 } |
53 | 74 |
54 void | 75 void |
55 MemList::moveToFirst(MemorySegment* e) | 76 MemList::moveToFirst(MemorySegment* e) |
56 { | 77 { |
57 remove(e); | 78 remove(e); |
58 addFirst(e); | 79 addFirst(e); |
59 } | 80 } |
81 | |
82 /*! | |
83 リスト内の指定された位置にある要素を返す。 | |
84 要素数を超えた位置を指定した場合 NULL を返す。 | |
85 */ | |
86 | |
87 MemorySegment* | |
88 MemList::get(int index) | |
89 { | |
90 MemorySegment* e = first->next; | |
91 for (int i = 0; i < index; i++) { | |
92 if (e == this) return NULL; | |
93 e = e->next; | |
94 } | |
95 return e; | |
96 } |