mempool/multiple_mempool: add private member delta in multiple-mempool

This delta describes the relationship between the block size of each
mempool in multiple mempool by user initialized. It is automatically
detected by the mempool_multiple_init function. If the delta is not
equal to 0, the block size of the pool in the multiple mempool is an
arithmetic progressions, otherwise it is an increasing progressions.

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
This commit is contained in:
dongjiuzhu1 2022-10-27 21:35:40 +08:00 committed by Xiang Xiao
parent cd97134c7c
commit e5394be881
2 changed files with 38 additions and 0 deletions

View File

@ -79,6 +79,17 @@ struct mempool_multiple_s
{
FAR struct mempool_s *pools; /* The memory pool array */
size_t npools; /* The number of memory pool array elements */
/* Private data for multiple memory pool */
/* This delta describes the relationship between the block size of each
* mempool in multiple mempool by user initialized. It is automatically
* detected by the mempool_multiple_init function. If the delta is not
* equal to 0, the block size of the pool in the multiple mempool is an
* arithmetic progressions, otherwise it is an increasing progressions.
*/
size_t delta;
};
struct mempoolinfo_s
@ -225,6 +236,9 @@ void mempool_procfs_unregister(FAR struct mempool_procfs_entry_s *entry);
* interruptsize, wait. These mempool will be initialized by mempool_init.
* The name of all mempool are "name".
*
* This function will initialize the member delta by detecting the
* relationship between the each block size of mempool in multiple mempool.
*
* Input Parameters:
* name - The name of memory pool.
* mpool - The handle of the multiple memory pool to be used.

View File

@ -44,6 +44,13 @@ mempool_multiple_find(FAR struct mempool_multiple_s *mpool, size_t size)
size_t left = 0;
size_t mid;
if (mpool->delta != 0)
{
left = mpool->pools[0].blocksize;
mid = (size - left + mpool->delta - 1) / mpool->delta;
return mid < right ? &mpool->pools[mid] : NULL;
}
while (left < right)
{
mid = (left + right) >> 1;
@ -79,6 +86,9 @@ mempool_multiple_find(FAR struct mempool_multiple_s *mpool, size_t size)
* interruptsize, wait. These mempool will be initialized by mempool_init.
* The name of all mempool are "name".
*
* This function will initialize the member delta by detecting the
* relationship between the each block size of mempool in multiple mempool.
*
* Input Parameters:
* name - The name of memory pool.
* mpool - The handle of the multiple memory pool to be used.
@ -95,6 +105,20 @@ int mempool_multiple_init(FAR struct mempool_multiple_s *mpool,
DEBUGASSERT(mpool != NULL && mpool->pools != NULL);
mpool->delta = 0;
for (i = 1; i < mpool->npools; i++)
{
size_t delta = mpool->pools[i].blocksize -
mpool->pools[i - 1].blocksize;
if (mpool->delta != 0 && delta != mpool->delta)
{
mpool->delta = 0;
break;
}
mpool->delta = delta;
}
for (i = 0; i < mpool->npools; i++)
{
int ret = mempool_init(mpool->pools + i, name);