28 #ifndef _util_group_pool_h
29 #define _util_group_pool_h
35 #include <util/misc/exenv.h>
41 const int pool_data_alignment_bit = 3;
43 const size_t pool_data_alignment = 1<<pool_data_alignment_bit;
45 align_pool_data(
size_t size)
47 return (size + pool_data_alignment - 1)
48 & (~ (pool_data_alignment - 1));
51 align_pool_data(
void* ptr)
53 return (
void*)( (
unsigned long) ((
char*)ptr + pool_data_alignment - 1)
54 & (~ (pool_data_alignment - 1)));
57 align_pool_data_downward(
size_t size)
59 return size & (~ (pool_data_alignment - 1));
62 align_pool_data_downward(
void* ptr)
64 return (
void*) ( (
unsigned long) ptr & (~ (pool_data_alignment - 1)));
79 unsigned int held_:16;
81 unsigned int fixed_:1;
88 enum {magic = 0x1f1d1e1c};
92 unsigned int flags_:15;
119 void set_magic(
int = magic);
125 void check(
void*lower=(
void*)0x0,
void*upper=(
void*)0x7fffffffL);
128 const int PoolData_aligned_size = (
sizeof(
PoolData) + pool_data_alignment - 1)
129 & (~ (pool_data_alignment - 1));
130 inline void* PoolData::data()
132 return (
void*)(((
char*)
this) + PoolData_aligned_size);
148 PoolData::next(PoolData*p)
152 if (next_ && prev_ && (next_ < prev_)) {
153 ExEnv::errn() <<
"PoolData::next(PoolData*): next < prev" << endl;
160 PoolData::prev(PoolData*p)
164 if (next_ && prev_ && (next_ < prev_)) {
165 ExEnv::errn() <<
"PoolData::prev(PoolData*): next < prev" << endl;
172 PoolData::prev_next(PoolData*p,PoolData*n)
177 if (next_ && prev_ && (next_ < prev_)) {
178 ExEnv::errn() <<
"PoolData::prev_next: next < prev" << endl;
187 PoolData::next_free()
191 ExEnv::errn() <<
"PoolData::next_free(): datum is not free" << endl;
199 PoolData::prev_free()
203 ExEnv::errn() <<
"PoolData::prev_free(): datum is not free" << endl;
211 PoolData::next_free(PoolData*p)
215 ExEnv::errn() <<
"PoolData::next_free(PoolData*): datum is not free" << endl;
223 PoolData::prev_free(PoolData*p)
227 ExEnv::errn() <<
"PoolData::prev_free(PoolData*): datum is not free" << endl;
235 PoolData::prev_next_free(PoolData*p,PoolData*n)
239 ExEnv::errn() <<
"PoolData::prev_next_free: datum is not free" << endl;
248 PoolData::PoolData(
size_t size):
250 size_(size-PoolData_aligned_size)
255 PoolData::set_magic(
int magic_a)
264 enum { freelist_size =
sizeof(size_t)*8 };
272 int freelist_find_slot(
size_t);
284 size_t size() {
return size_; }
286 void* allocate(
size_t size);
287 void release(
void*d);
288 double* allocate_double(
size_t n);
289 void release(
double*d);
290 int* allocate_int(
size_t n);
297 Pool::voidptr_to_pd(
void*d)
299 return (
PoolData*)((
char*)d - PoolData_aligned_size);
303 Pool::allocate_double(
size_t n)
305 return (
double*) allocate(n*
sizeof(
double));
309 Pool::release(
double*d)
314 Pool::allocate_int(
size_t n)
316 return (
int*) allocate(n*
sizeof(
int));