32 #ifndef _util_group_pool_h
33 #define _util_group_pool_h
39 #include <util/misc/exenv.h>
45 const int pool_data_alignment_bit = 3;
47 const size_t pool_data_alignment = 1<<pool_data_alignment_bit;
49 align_pool_data(
size_t size)
51 return (size + pool_data_alignment - 1)
52 & (~ (pool_data_alignment - 1));
55 align_pool_data(
void* ptr)
57 return (
void*)( (
unsigned long) ((
char*)ptr + pool_data_alignment - 1)
58 & (~ (pool_data_alignment - 1)));
61 align_pool_data_downward(
size_t size)
63 return size & (~ (pool_data_alignment - 1));
66 align_pool_data_downward(
void* ptr)
68 return (
void*) ( (
unsigned long) ptr & (~ (pool_data_alignment - 1)));
83 unsigned int held_:16;
85 unsigned int fixed_:1;
92 enum {magic = 0x1f1d1e1c};
96 unsigned int flags_:15;
123 void set_magic(
int = magic);
129 void check(
void*lower=(
void*)0x0,
void*upper=(
void*)0x7fffffffL);
132 const int PoolData_aligned_size = (
sizeof(
PoolData) + pool_data_alignment - 1)
133 & (~ (pool_data_alignment - 1));
134 inline void* PoolData::data()
136 return (
void*)(((
char*)
this) + PoolData_aligned_size);
152 PoolData::next(PoolData*p)
156 if (next_ && prev_ && (next_ < prev_)) {
157 ExEnv::errn() <<
"PoolData::next(PoolData*): next < prev" << endl;
164 PoolData::prev(PoolData*p)
168 if (next_ && prev_ && (next_ < prev_)) {
169 ExEnv::errn() <<
"PoolData::prev(PoolData*): next < prev" << endl;
176 PoolData::prev_next(PoolData*p,PoolData*n)
181 if (next_ && prev_ && (next_ < prev_)) {
182 ExEnv::errn() <<
"PoolData::prev_next: next < prev" << endl;
191 PoolData::next_free()
195 ExEnv::errn() <<
"PoolData::next_free(): datum is not free" << endl;
203 PoolData::prev_free()
207 ExEnv::errn() <<
"PoolData::prev_free(): datum is not free" << endl;
215 PoolData::next_free(PoolData*p)
219 ExEnv::errn() <<
"PoolData::next_free(PoolData*): datum is not free" << endl;
227 PoolData::prev_free(PoolData*p)
231 ExEnv::errn() <<
"PoolData::prev_free(PoolData*): datum is not free" << endl;
239 PoolData::prev_next_free(PoolData*p,PoolData*n)
243 ExEnv::errn() <<
"PoolData::prev_next_free: datum is not free" << endl;
252 PoolData::PoolData(
size_t size):
254 size_(size-PoolData_aligned_size)
259 PoolData::set_magic(
int magic_a)
268 enum { freelist_size =
sizeof(size_t)*8 };
276 int freelist_find_slot(
size_t);
288 size_t size() {
return size_; }
290 void* allocate(
size_t size);
291 void release(
void*d);
292 double* allocate_double(
size_t n);
293 void release(
double*d);
294 int* allocate_int(
size_t n);
301 Pool::voidptr_to_pd(
void*d)
303 return (
PoolData*)((
char*)d - PoolData_aligned_size);
307 Pool::allocate_double(
size_t n)
309 return (
double*) allocate(n*
sizeof(
double));
313 Pool::release(
double*d)
318 Pool::allocate_int(
size_t n)
320 return (
int*) allocate(n*
sizeof(
int));