1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 #ifndef BASE_POOL_PVT_H
35 #define BASE_POOL_PVT_H
36
37 #ifndef BASE_POOL_H
38 #include "pool.h"
39 #include <inttypes.h>
40 #endif
41
42
43
44
45
46
47
48
49
50
51
52 #ifdef DEBUG
53 #define PER_POOL_STATISTICS
54 #endif
55
56
57
58
59
60
61
62
63 #ifdef DEBUG
64 #define POOL_ZERO_DEBUG 0xa
65 #endif
66
67
68
69
70
71
72
73 #define DEFAULT_BLOCK_SIZE (
32 *
1024)
74
75
76
77
78
79
80
81
82
83 #define DEFAULT_RETENTION_SIZE (
DEFAULT_BLOCK_SIZE *
2)
84 #define DEFAULT_RETENTION_NUM 2
85
86
87 #define WORD_SIZE 8
88 #undef ALIGN
89 #define ALIGN(x) ( (x +
WORD_SIZE-
1) & (~(
WORD_SIZE-
1)) )
90
91
92
93
94
95
96
97 #ifdef PER_POOL_STATISTICS
98 typedef struct pool_stats_t pool_stats_t;
99 struct pool_stats_t {
100 PRUint32 poolId;
101 PRUint32 maxAlloc;
102 PRUint32 allocCnt;
103 PRUint32 freeCnt;
104 PRUint32 blkAlloc;
105 PRUint32 blkFree;
106 PRThread *thread;
107 PRTime created;
108 };
109 #endif
110
111 typedef struct pool_config_t pool_config_t;
112 struct pool_config_t {
113 int32_t block_size;
114 int32_t retain_size;
115 int32_t retain_num;
116 };
117
118 #define POOL_CONFIG_INIT { \
119 DEFAULT_BLOCK_SIZE, \
120 DEFAULT_RETENTION_SIZE, \
121 DEFAULT_RETENTION_NUM, \
122 }
123
124
125
126
127
128
129
130 typedef struct block_t block_t;
131 struct block_t {
132 char *data;
133 char *start;
134 char *end;
135 block_t *next;
136 };
137
138 #define POOL_PTR_IN_BLOCK(blk, ptr) \
139 (((
char *)(ptr) < (blk)->end) && ((
char *)(ptr) >= (blk)->data))
140
141
142
143
144
145
146
147
148 typedef struct pool_t pool_t;
149 struct pool_t {
150 block_t *curr_block;
151 block_t *used_blocks;
152 block_t *free_blocks;
153 int32_t free_size;
154 int32_t free_num;
155 size_t size;
156 pool_t *next;
157 #ifdef PER_POOL_STATISTICS
158 pool_stats_t stats;
159 #endif
160 };
161
162 typedef struct pool_global_stats_t pool_global_stats_t;
163 struct pool_global_stats_t {
164
165 pool_t *poolList;
166 int32_t createCnt;
167 int32_t destroyCnt;
168 #ifdef POOL_GLOBAL_STATISTICS
169 PRUint32 blkAlloc;
170 PRUint32 blkFree;
171 #endif
172 };
173
174
175
176 NSAPI_PUBLIC pool_config_t *pool_getConfig(
void);
177
178 NSAPI_PUBLIC pool_global_stats_t *pool_getGlobalStats(
void);
179
180 #ifdef PER_POOL_STATISTICS
181 NSAPI_PUBLIC pool_stats_t *pool_getPoolStats(
pool_handle_t *pool_handle);
182 #endif
183
184 #endif
185