version 1.1.2.7, 2012/02/28 10:34:43
|
version 1.1.2.8, 2012/02/28 12:01:12
|
Line 168 void *
|
Line 168 void *
|
mpool_malloc(mpool_t * __restrict mp, u_int size, const char *memname) |
mpool_malloc(mpool_t * __restrict mp, u_int size, const char *memname) |
{ |
{ |
struct tagAlloc *m; |
struct tagAlloc *m; |
int idx, align; | int idx; |
| u_int align; |
|
|
if (!mp) { |
if (!mp) { |
sess_SetErr(EINVAL, "Pool not specified"); |
sess_SetErr(EINVAL, "Pool not specified"); |
Line 243 void *
|
Line 244 void *
|
mpool_realloc(mpool_t * __restrict mp, void * __restrict data, u_int newsize, const char *memname) |
mpool_realloc(mpool_t * __restrict mp, void * __restrict data, u_int newsize, const char *memname) |
{ |
{ |
struct tagAlloc *m, *tmp; |
struct tagAlloc *m, *tmp; |
int idx, align, oidx, osize; | int idx, oidx; |
void *p; |
void *p; |
|
u_int align, osize; |
|
|
/* if !data execute mpool_malloc() */ |
/* if !data execute mpool_malloc() */ |
if (!data) |
if (!data) |
Line 282 mpool_realloc(mpool_t * __restrict mp, void * __restri
|
Line 284 mpool_realloc(mpool_t * __restrict mp, void * __restri
|
} |
} |
|
|
/* find old memory block */ |
/* find old memory block */ |
TAILQ_FOREACH_SAFE(m, &mp->pool_active[oidx], alloc_node, tmp) | TAILQ_FOREACH_SAFE(m, &mp->pool_active[oidx], alloc_node, tmp) { |
if (mem_data(m, void*) == data && mem_size(m) == osize) { |
if (mem_data(m, void*) == data && mem_size(m) == osize) { |
TAILQ_REMOVE(&mp->pool_active[oidx], m, alloc_node); | /* case in different buckets */ |
/* statistics */ | if (oidx != idx) { |
mp->pool_calls.alloc--; | TAILQ_REMOVE(&mp->pool_active[oidx], m, alloc_node); |
| /* statistics */ |
| mp->pool_calls.alloc--; |
| } |
mp->pool_bytes.alloc -= osize; |
mp->pool_bytes.alloc -= osize; |
|
break; |
} |
} |
|
} |
/* memory block not found! */ |
/* memory block not found! */ |
if (!m) { |
if (!m) { |
mpool_unlock(mp); |
mpool_unlock(mp); |
Line 297 mpool_realloc(mpool_t * __restrict mp, void * __restri
|
Line 304 mpool_realloc(mpool_t * __restrict mp, void * __restri
|
} |
} |
|
|
/* try to reallocate memory block to new bucket */ |
/* try to reallocate memory block to new bucket */ |
align = 1 << (idx + MEM_MIN_BUCKET); | if (oidx != idx) { |
p = realloc(m->alloc_mem, align + 12); | align = 1 << (idx + MEM_MIN_BUCKET); |
if (!p) { | p = realloc(m->alloc_mem, align + 12); |
LOGERR; | if (!p) { |
| LOGERR; |
|
|
/* restore to old bucket pulled memory block for reallocation */ | /* restore to old bucket pulled memory block for reallocation */ |
TAILQ_INSERT_HEAD(&mp->pool_active[oidx], m, alloc_node); | TAILQ_INSERT_HEAD(&mp->pool_active[oidx], m, alloc_node); |
/* statistics */ | /* statistics */ |
mp->pool_calls.alloc++; | mp->pool_calls.alloc++; |
mp->pool_bytes.alloc += osize; | mp->pool_bytes.alloc += osize; |
|
|
mpool_unlock(mp); | mpool_unlock(mp); |
return NULL; | return NULL; |
} else /* quota */ | } |
mp->pool_quota.curr += (newsize - osize); | } |
| /* quota */ |
| mp->pool_quota.curr += (newsize - osize); |
|
|
m->alloc_mem[0] = newsize / sizeof(u_int); |
m->alloc_mem[0] = newsize / sizeof(u_int); |
m->alloc_mem[1] = MEM_MAGIC_START; |
m->alloc_mem[1] = MEM_MAGIC_START; |
m->alloc_mem[2 + newsize / sizeof(u_int)] = MEM_MAGIC_STOP; |
m->alloc_mem[2 + newsize / sizeof(u_int)] = MEM_MAGIC_STOP; |
TAILQ_INSERT_HEAD(&mp->pool_active[idx], m, alloc_node); | |
/* statistics */ | if (oidx != idx) { |
mp->pool_calls.alloc++; | TAILQ_INSERT_HEAD(&mp->pool_active[idx], m, alloc_node); |
| /* statistics */ |
| mp->pool_calls.alloc++; |
| } |
mp->pool_bytes.alloc += newsize; |
mp->pool_bytes.alloc += newsize; |
|
|
if (memname) |
if (memname) |