46
|
1 #include <stdio.h>
|
|
2 #include <stdlib.h>
|
|
3 #include "HTaskInfo.h"
|
|
4
|
|
5 HTaskInfo::HTaskInfo(void)
|
|
6 :htaskPool(NULL), freeHTask(NULL) {}
|
|
7
|
|
8 HTaskInfo::~HTaskInfo(void) { destroy(); }
|
|
9
|
|
10 int
|
|
11 HTaskInfo::init(int num)
|
|
12 {
|
|
13 if (htaskPool == NULL) {
|
|
14 return extend_pool(num);
|
|
15 }
|
|
16 return 0;
|
|
17 }
|
|
18
|
|
19 /**
|
|
20 * Fix me
|
|
21 * extend できる限界を設定するべき?
|
|
22 */
|
|
23 int
|
|
24 HTaskInfo::extend_pool(int num)
|
|
25 {
|
|
26 HTaskPtr q = NULL;
|
|
27
|
|
28 q = (HTaskPtr)malloc(sizeof(HTask)*(num+1));
|
|
29
|
|
30 if (q == NULL) {
|
|
31 return -1;
|
|
32 }
|
|
33 q->next = htaskPool;
|
|
34 htaskPool = q;
|
|
35
|
|
36 /* Connect all free queue in the pool */
|
|
37 for (q = htaskPool + 1; --num > 0; q++) {
|
|
38 q->next = q + 1;
|
|
39 }
|
|
40 q->next = freeHTask;
|
|
41 freeHTask = htaskPool + 1;
|
|
42
|
|
43 return 0;
|
|
44 }
|
|
45
|
|
46 HTaskPtr
|
|
47 HTaskInfo::create(int cmd, int size,
|
|
48 unsigned long long in_addr,
|
|
49 unsigned long long out_addr)
|
|
50 {
|
|
51 HTaskPtr q;
|
|
52
|
|
53 if (freeHTask == NULL) {
|
|
54 extend_pool(100);
|
|
55 }
|
|
56
|
|
57 q = freeHTask;
|
|
58 freeHTask = freeHTask->next;
|
|
59
|
|
60 q->command = cmd;
|
|
61 q->in_addr = in_addr;
|
|
62 q->out_addr = out_addr;
|
|
63 q->in_size = size;
|
|
64 q->wait_me = NULL;
|
|
65 q->wait_i = NULL;
|
|
66 q->post_func = NULL;
|
|
67
|
|
68 return q;
|
|
69 }
|
|
70
|
|
71 void
|
|
72 HTaskInfo::free(HTaskPtr q)
|
|
73 {
|
|
74 q->next = freeHTask;
|
|
75 freeHTask = q;
|
|
76 }
|
|
77
|
|
78 void
|
|
79 HTaskInfo::destroy(void)
|
|
80 {
|
|
81 HTaskPtr q;
|
|
82
|
|
83 for (q = htaskPool; q; q = q->next) {
|
|
84 free(q);
|
|
85 }
|
|
86 freeHTask = htaskPool = NULL;
|
|
87 }
|