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