mirror of
https://git.savannah.nongnu.org/git/lwip.git
synced 2025-08-06 22:44:38 +08:00
mem: Simplify the code for try bigger pool in mem_malloc
Signed-off-by: Axel Lin <axel.lin@ingics.com> Signed-off-by: sg <goldsimon@gmx.de>
This commit is contained in:
parent
21c99b6ebb
commit
40f2bed5c4
@ -167,12 +167,21 @@ mem_malloc(mem_size_t size)
|
|||||||
mem_size_t required_size = size + LWIP_MEM_ALIGN_SIZE(sizeof(struct memp_malloc_helper));
|
mem_size_t required_size = size + LWIP_MEM_ALIGN_SIZE(sizeof(struct memp_malloc_helper));
|
||||||
|
|
||||||
for (poolnr = MEMP_POOL_FIRST; poolnr <= MEMP_POOL_LAST; poolnr = (memp_t)(poolnr + 1)) {
|
for (poolnr = MEMP_POOL_FIRST; poolnr <= MEMP_POOL_LAST; poolnr = (memp_t)(poolnr + 1)) {
|
||||||
#if MEM_USE_POOLS_TRY_BIGGER_POOL
|
|
||||||
again:
|
|
||||||
#endif /* MEM_USE_POOLS_TRY_BIGGER_POOL */
|
|
||||||
/* is this pool big enough to hold an element of the required size
|
/* is this pool big enough to hold an element of the required size
|
||||||
plus a struct memp_malloc_helper that saves the pool this element came from? */
|
plus a struct memp_malloc_helper that saves the pool this element came from? */
|
||||||
if (required_size <= memp_pools[poolnr]->size) {
|
if (required_size <= memp_pools[poolnr]->size) {
|
||||||
|
element = (struct memp_malloc_helper*)memp_malloc(poolnr);
|
||||||
|
if (element == NULL) {
|
||||||
|
/* No need to DEBUGF or ASSERT: This error is already taken care of in memp.c */
|
||||||
|
#if MEM_USE_POOLS_TRY_BIGGER_POOL
|
||||||
|
/** Try a bigger pool if this one is empty! */
|
||||||
|
if (poolnr < MEMP_POOL_LAST) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
#endif /* MEM_USE_POOLS_TRY_BIGGER_POOL */
|
||||||
|
MEM_STATS_INC(err);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -181,20 +190,6 @@ again:
|
|||||||
MEM_STATS_INC(err);
|
MEM_STATS_INC(err);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
element = (struct memp_malloc_helper*)memp_malloc(poolnr);
|
|
||||||
if (element == NULL) {
|
|
||||||
/* No need to DEBUGF or ASSERT: This error is already
|
|
||||||
taken care of in memp.c */
|
|
||||||
#if MEM_USE_POOLS_TRY_BIGGER_POOL
|
|
||||||
/** Try a bigger pool if this one is empty! */
|
|
||||||
if (poolnr < MEMP_POOL_LAST) {
|
|
||||||
poolnr++;
|
|
||||||
goto again;
|
|
||||||
}
|
|
||||||
#endif /* MEM_USE_POOLS_TRY_BIGGER_POOL */
|
|
||||||
MEM_STATS_INC(err);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* save the pool number this element came from */
|
/* save the pool number this element came from */
|
||||||
element->poolnr = poolnr;
|
element->poolnr = poolnr;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user