annotate TaskManager/kernel/ppe/TaskListInfo.cc @ 47:8266445bdac2

*** empty log message ***
author gongo
date Fri, 15 Feb 2008 13:09:58 +0900
parents f154d9d07a42
children 5c194c71eca8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
46
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
1 #include <stdio.h>
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
2 #include <stdlib.h>
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
3 #include "TaskListInfo.h"
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
4
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
5 TaskListInfo::TaskListInfo(void)
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
6 :taskListPool(NULL), freeTaskList(NULL) {}
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
7
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
8 TaskListInfo::~TaskListInfo(void) { destroy(); }
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
9
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
10 int
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
11 TaskListInfo::init(int num)
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
12 {
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
13 if (taskListPool == NULL) {
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
14 return extend_pool(num);
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
15 }
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
16 return 0;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
17 }
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
18
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
19 int
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
20 TaskListInfo::extend_pool(int num)
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
21 {
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
22 TaskListPtr q = NULL;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
23
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
24 q = (TaskListPtr)malloc(sizeof(TaskList)*(num+1));
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
25
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
26 if (q == NULL) {
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
27 return -1;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
28 }
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
29
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
30 q->next = taskListPool;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
31 taskListPool = q;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
32
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
33 /* Connect all free pack_list in the pool */
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
34 for (q = taskListPool + 1; --num > 0; q++) {
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
35 q->next = q + 1;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
36 }
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
37 q->next = freeTaskList;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
38 freeTaskList = taskListPool + 1;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
39
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
40 return 0;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
41 }
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
42
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
43 TaskListPtr
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
44 TaskListInfo::create(void)
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
45 {
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
46 TaskListPtr q;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
47
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
48 if (freeTaskList == NULL) {
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
49 extend_pool(10);
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
50 }
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
51 q = freeTaskList;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
52 freeTaskList = freeTaskList->next;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
53
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
54 q->length = 0;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
55 q->next = 0;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
56
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
57 return q;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
58 }
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
59
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
60 void
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
61 TaskListInfo::free(TaskListPtr q)
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
62 {
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
63 q->next = freeTaskList;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
64 freeTaskList = q;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
65 }
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
66
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
67 void
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
68 TaskListInfo::destroy(void)
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
69 {
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
70 TaskListPtr q;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
71
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
72 for (q = taskListPool; q; q = q->next) {
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
73 free(q);
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
74 }
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
75 freeTaskList = taskListPool = NULL;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
76 }
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
77
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
78 TaskListPtr
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
79 TaskListInfo::append(TaskListPtr list, TaskListPtr q)
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
80 {
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
81 TaskListPtr p = list;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
82
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
83 if (!p) {
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
84 return q;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
85 } else {
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
86 while (p->next) p = p->next;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
87 p->next = q;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
88 return list;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
89 }
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
90 }