mm/mempool: Merge two memory requests

Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
This commit is contained in:
wangmingrong1
2024-10-08 14:12:42 +08:00
committed by Xiang Xiao
parent 0866010101
commit 5c3025e2fb
+7 -10
View File
@@ -437,12 +437,18 @@ mempool_multiple_init(FAR const char *name,
} }
} }
mpool = alloc(arg, sizeof(uintptr_t), sizeof(struct mempool_multiple_s)); mpool = alloc(arg, sizeof(uintptr_t),
sizeof(struct mempool_multiple_s) +
npools * sizeof(struct mempool_s));
if (mpool == NULL) if (mpool == NULL)
{ {
return NULL; return NULL;
} }
pools = (FAR struct mempool_s *)
((uintptr_t)mpool + sizeof(struct mempool_multiple_s));
mpool->alloc_size = alloc_size; mpool->alloc_size = alloc_size;
mpool->expandsize = expandsize; mpool->expandsize = expandsize;
mpool->chunk_size = chunksize; mpool->chunk_size = chunksize;
@@ -451,12 +457,6 @@ mempool_multiple_init(FAR const char *name,
mpool->arg = arg; mpool->arg = arg;
mpool->alloced = alloc_size(arg, mpool); mpool->alloced = alloc_size(arg, mpool);
sq_init(&mpool->chunk_queue); sq_init(&mpool->chunk_queue);
pools = alloc(arg, sizeof(uintptr_t), npools * sizeof(struct mempool_s));
if (pools == NULL)
{
goto err_with_mpool;
}
mpool->pools = pools; mpool->pools = pools;
mpool->npools = npools; mpool->npools = npools;
mpool->minpoolsize = minpoolsize; mpool->minpoolsize = minpoolsize;
@@ -520,8 +520,6 @@ err_with_pools:
} }
mempool_multiple_free_chunk(mpool, pools); mempool_multiple_free_chunk(mpool, pools);
err_with_mpool:
free(arg, mpool);
return NULL; return NULL;
} }
@@ -900,6 +898,5 @@ void mempool_multiple_deinit(FAR struct mempool_multiple_s *mpool)
mempool_multiple_free_chunk(mpool, mpool->dict); mempool_multiple_free_chunk(mpool, mpool->dict);
nxrmutex_destroy(&mpool->lock); nxrmutex_destroy(&mpool->lock);
mpool->free(mpool->arg, mpool->pools);
mpool->free(mpool->arg, mpool); mpool->free(mpool->arg, mpool);
} }