annotate TaskManager/kernel/ppe/TaskQueueInfo.cc @ 93:dd33ec2e51b9

*** empty log message ***
author gongo
date Thu, 28 Feb 2008 17:32:18 +0900
parents f154d9d07a42
children 588ab5f0e659
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 "TaskQueueInfo.h"
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
4
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
5 TaskQueueInfo::TaskQueueInfo(void)
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
6 :taskQueuePool(NULL), freeTaskQueue(NULL) {}
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
7
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
8 TaskQueueInfo::~TaskQueueInfo(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 TaskQueueInfo::init(int num)
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
12 {
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
13 if (taskQueuePool == 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 TaskQueueInfo::extend_pool(int num)
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
21 {
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
22 TaskQueuePtr q = NULL;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
23
93
dd33ec2e51b9 *** empty log message ***
gongo
parents: 46
diff changeset
24 static int i = 0;
dd33ec2e51b9 *** empty log message ***
gongo
parents: 46
diff changeset
25 printf("extend %d\n", ++i);
dd33ec2e51b9 *** empty log message ***
gongo
parents: 46
diff changeset
26
46
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
27 q = (TaskQueuePtr)malloc(sizeof(TaskQueue)*(num+1));
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
28
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
29 if (q == NULL) {
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
30 return -1;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
31 }
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
32 q->next = taskQueuePool;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
33 taskQueuePool = q;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
34
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
35 /* Connect all free queue in the pool */
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
36 for (q = taskQueuePool + 1; --num > 0; q++) {
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
37 q->next = q + 1;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
38 }
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
39 q->next = freeTaskQueue;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
40 freeTaskQueue = taskQueuePool + 1;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
41
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
42 return 0;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
43 }
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
44
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
45 TaskQueuePtr
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
46 TaskQueueInfo::create(HTaskPtr task)
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
47 {
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
48 TaskQueuePtr q;
93
dd33ec2e51b9 *** empty log message ***
gongo
parents: 46
diff changeset
49
dd33ec2e51b9 *** empty log message ***
gongo
parents: 46
diff changeset
50 static int i = 0;
dd33ec2e51b9 *** empty log message ***
gongo
parents: 46
diff changeset
51
dd33ec2e51b9 *** empty log message ***
gongo
parents: 46
diff changeset
52 printf("create %d\n", ++i);
46
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
53
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
54 if (freeTaskQueue == NULL) {
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
55 extend_pool(100);
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
56 }
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
57 q = freeTaskQueue;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
58 freeTaskQueue = freeTaskQueue->next;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
59
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
60 q->task = task;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
61 q->next = NULL;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
62
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
63 return q;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
64 }
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 TaskQueueInfo::free(TaskQueuePtr q)
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
69 {
93
dd33ec2e51b9 *** empty log message ***
gongo
parents: 46
diff changeset
70 static int i = 0;
dd33ec2e51b9 *** empty log message ***
gongo
parents: 46
diff changeset
71
dd33ec2e51b9 *** empty log message ***
gongo
parents: 46
diff changeset
72 printf("free %d\n", ++i);
dd33ec2e51b9 *** empty log message ***
gongo
parents: 46
diff changeset
73 printf("## command %d ##\n", q->task->command);
dd33ec2e51b9 *** empty log message ***
gongo
parents: 46
diff changeset
74
46
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
75 q->next = freeTaskQueue;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
76 freeTaskQueue = q;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
77 }
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
78
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
79
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
80 void
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
81 TaskQueueInfo::destroy(void)
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
82 {
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
83 TaskQueuePtr q;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
84
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
85 for (q = taskQueuePool; q; q = q->next) {
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
86 free(q);
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
87 }
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
88 freeTaskQueue = taskQueuePool = NULL;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
89 }
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
90
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
91
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
92 TaskQueuePtr
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
93 TaskQueueInfo::append(TaskQueuePtr list, TaskQueuePtr q)
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
94 {
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
95 TaskQueuePtr p = list;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
96
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
97 if (!p) {
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
98 return q;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
99 } else {
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
100 while(p->next) p = p->next;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
101 p->next = q;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
102 return list;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
103 }
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
104 }