annotate TaskManager/kernel/ppe/TaskQueueInfo.cc @ 46:f154d9d07a42

*** empty log message ***
author gongo
date Fri, 15 Feb 2008 13:09:43 +0900
parents
children dd33ec2e51b9
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
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
24 q = (TaskQueuePtr)malloc(sizeof(TaskQueue)*(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 q->next = taskQueuePool;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
30 taskQueuePool = q;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
31
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
32 /* Connect all free queue in the pool */
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
33 for (q = taskQueuePool + 1; --num > 0; q++) {
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
34 q->next = q + 1;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
35 }
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
36 q->next = freeTaskQueue;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
37 freeTaskQueue = taskQueuePool + 1;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
38
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
39 return 0;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
40 }
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
41
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
42 TaskQueuePtr
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
43 TaskQueueInfo::create(HTaskPtr task)
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
44 {
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
45 TaskQueuePtr q;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
46
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
47 if (freeTaskQueue == NULL) {
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
48 extend_pool(100);
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
49 }
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
50 q = freeTaskQueue;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
51 freeTaskQueue = freeTaskQueue->next;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
52
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
53 q->task = task;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
54 q->next = NULL;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
55
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
56 return q;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
57 }
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 TaskQueueInfo::free(TaskQueuePtr q)
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
62 {
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
63 q->next = freeTaskQueue;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
64 freeTaskQueue = 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
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
68 void
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
69 TaskQueueInfo::destroy(void)
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
70 {
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
71 TaskQueuePtr q;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
72
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
73 for (q = taskQueuePool; q; q = q->next) {
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
74 free(q);
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
75 }
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
76 freeTaskQueue = taskQueuePool = NULL;
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 TaskQueuePtr
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
81 TaskQueueInfo::append(TaskQueuePtr list, TaskQueuePtr q)
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
82 {
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
83 TaskQueuePtr p = list;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
84
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
85 if (!p) {
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
86 return q;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
87 } else {
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
88 while(p->next) p = p->next;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
89 p->next = q;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
90 return list;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
91 }
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
92 }