version 1.1.2.7, 2012/02/28 10:34:43
|
version 1.2, 2012/02/28 13:00:24
|
Line 149 pullInactive(mpool_t * __restrict mp, int idx)
|
Line 149 pullInactive(mpool_t * __restrict mp, int idx)
|
|
|
/* clear name */ |
/* clear name */ |
*m->alloc_name = 0; |
*m->alloc_name = 0; |
/* clear flags */ |
|
m->alloc_flags ^= m->alloc_flags; |
|
} |
} |
|
|
return m; |
return m; |
Line 168 void *
|
Line 166 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 242 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 275 mpool_realloc(mpool_t * __restrict mp, void * __restri
|
Line 275 mpool_realloc(mpool_t * __restrict mp, void * __restri
|
|
|
/* quota */ |
/* quota */ |
if (mp->pool_quota.max && |
if (mp->pool_quota.max && |
(mp->pool_quota.curr + (newsize - osize)) > mp->pool_quota.max) { | (mp->pool_quota.curr + ((u_long) newsize - osize)) > mp->pool_quota.max) { |
sess_SetErr(ENOMEM, "Max.allocate memory quota has been reached"); |
sess_SetErr(ENOMEM, "Max.allocate memory quota has been reached"); |
mpool_unlock(mp); |
mpool_unlock(mp); |
return NULL; |
return NULL; |
} |
} |
|
|
/* 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 302 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 */ | } else |
mp->pool_quota.curr += (newsize - osize); | m->alloc_mem = (u_int*) p; |
| } |
| /* quota */ |
| mp->pool_quota.curr += (u_long) 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) |