mem_pool: Simplify task_mem_pool_alloc() API family
Changes the mem_pool API so that the timeout parameter must be specified when invoking task_mem_pool_alloc() thereby obsoleting the following APIs: task_mem_pool_alloc_wait() task_mem_pool_alloc_wait_alloc() _task_mem_pool_alloc() Change-Id: Ifa88f13bca98ca3c7d0e1a3b64b40a00068619e0 Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
This commit is contained in:
parent
e2cb5f5bdd
commit
9cc9bdcd53
9 changed files with 59 additions and 103 deletions
|
@ -556,7 +556,8 @@ to keep up.
|
|||
|
||||
while (1) {
|
||||
/* allocate memory block that will hold message data */
|
||||
task_mem_pool_alloc_wait(&send_msg.tx_block, TXPOOL, 4096);
|
||||
task_mem_pool_alloc(&send_msg.tx_block, TXPOOL,
|
||||
4096, TICKS_UNLIMITED);
|
||||
|
||||
/* keep saving hardware-generated data in the memory block */
|
||||
/* until the previous message has been received by the consumer */
|
||||
|
|
|
@ -125,7 +125,7 @@ available, then fills it with zeroes.
|
|||
|
||||
struct k_block block;
|
||||
|
||||
task_mem_pool_alloc_wait(&block, MYPOOL, 80);
|
||||
task_mem_pool_alloc(&block, MYPOOL, 80, TICKS_UNLIMITED);
|
||||
|
||||
memset(block.pointer_to_data, 0, 80);
|
||||
|
||||
|
@ -140,7 +140,7 @@ in that time.
|
|||
|
||||
struct k_block block;
|
||||
|
||||
if (task_mem_pool_alloc_wait_timeout(&block, MYPOOL, 80, 5) == RC_OK) {
|
||||
if (task_mem_pool_alloc(&block, MYPOOL, 80, 5) == RC_OK) {
|
||||
/* use memory block */
|
||||
} else {
|
||||
printf('Memory allocation timeout');
|
||||
|
@ -156,7 +156,7 @@ a memory block of 80 bytes.
|
|||
|
||||
struct k_block block;
|
||||
|
||||
if (task_mem_pool_alloc (&block, MYPOOL, 80) == RC_OK) {
|
||||
if (task_mem_pool_alloc (&block, MYPOOL, 80, TICKS_NONE) == RC_OK) {
|
||||
/* use memory block */
|
||||
} else {
|
||||
printf('Memory allocation timeout');
|
||||
|
@ -171,7 +171,7 @@ This code releases a memory block back to a pool when it is no longer needed.
|
|||
|
||||
struct k_block block;
|
||||
|
||||
task_mem_pool_alloc(&block, MYPOOL, size);
|
||||
task_mem_pool_alloc(&block, MYPOOL, size, TICKS_NONE);
|
||||
/* use memory block */
|
||||
task_mem_pool_free(&block);
|
||||
|
||||
|
@ -194,12 +194,6 @@ APIs
|
|||
The following Memory Pools APIs are provided by :file:`microkernel.h`:
|
||||
|
||||
:c:func:`task_mem_pool_alloc()`
|
||||
Allocates a block from a memory pool.
|
||||
|
||||
:c:func:`task_mem_pool_alloc_wait()`
|
||||
Waits for a block of memory until it is available.
|
||||
|
||||
:c:func:`task_mem_pool_alloc_wait_timeout()`
|
||||
Waits for a block of memory for the time period defined by the time-out
|
||||
parameter.
|
||||
|
||||
|
@ -207,4 +201,4 @@ The following Memory Pools APIs are provided by :file:`microkernel.h`:
|
|||
Returns a block of memory to a memory pool.
|
||||
|
||||
:c:func:`task_mem_pool_defragment()`
|
||||
Defragments a memory pool.
|
||||
Defragments a memory pool.
|
||||
|
|
|
@ -33,17 +33,6 @@ extern "C" {
|
|||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @cond internal
|
||||
*/
|
||||
|
||||
extern int _task_mem_pool_alloc(struct k_block *b, kmemory_pool_t p,
|
||||
int size, int32_t ticks);
|
||||
|
||||
/**
|
||||
* @endcond
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Return memory pool block
|
||||
*
|
||||
|
@ -73,56 +62,28 @@ extern void task_mem_pool_defragment(kmemory_pool_t p);
|
|||
|
||||
|
||||
/**
|
||||
* @brief Allocate memory pool block or fail
|
||||
* @brief Allocate memory pool block
|
||||
*
|
||||
* This routine allocates a block of at least @a s bytes from memory pool
|
||||
* @a p, and saves its information in block descriptor @a b. If no such
|
||||
* block is available the routine immediately returns a failure indication.
|
||||
* This routine allocates a block of at least @a reqsize bytes from memory pool
|
||||
* @a pool_id, and saves its information in block descriptor @a blockptr. If no
|
||||
* such block is available the routine either waits until one can be allocated,
|
||||
* or until the specified time limit is reached.
|
||||
*
|
||||
* @param b Pointer to block descriptor.
|
||||
* @param p Memory pool name.
|
||||
* @param s Requested block size, in bytes.
|
||||
* @param blockptr Pointer to block descriptor.
|
||||
* @param pool_id Memory pool name.
|
||||
* @param reqsize Requested block size, in bytes.
|
||||
* @param timeout Affects the action taken should the memory pool be exhausted.
|
||||
* If TICKS_NONE, then return immediately. If TICKS_UNLIMITED, then wait as
|
||||
* long as necessary. Otherwise wait up to the specified number of ticks before
|
||||
* timing out.
|
||||
*
|
||||
* @return RC_OK on success, or RC_FAIL on failure.
|
||||
* @retval RC_OK Successfully allocated memory block
|
||||
* @retval RC_TIME Timed out while waiting for memory block
|
||||
* @retval RC_FAIL Failed to immediately allocate memory block when
|
||||
* @a timeout = TICKS_NONE
|
||||
*/
|
||||
#define task_mem_pool_alloc(b, p, s) \
|
||||
_task_mem_pool_alloc(b, p, s, TICKS_NONE)
|
||||
|
||||
/**
|
||||
* @brief Allocate memory pool block or wait
|
||||
*
|
||||
* This routine allocates a block of at least @a s bytes from memory pool
|
||||
* @a p, and saves its information in block descriptor @a b. If no such block
|
||||
* is available the routine waits until one can be allocated.
|
||||
*
|
||||
* @param b Pointer to block descriptor.
|
||||
* @param p Memory pool name.
|
||||
* @param s Requested block size, in bytes.
|
||||
*
|
||||
* @return RC_OK.
|
||||
*/
|
||||
#define task_mem_pool_alloc_wait(b, p, s) \
|
||||
_task_mem_pool_alloc(b, p, s, TICKS_UNLIMITED)
|
||||
|
||||
#ifdef CONFIG_SYS_CLOCK_EXISTS
|
||||
/**
|
||||
* @brief Allocate memory pool block or timeout
|
||||
*
|
||||
* This routine allocates a block of at least @a s bytes from memory pool
|
||||
* @a p, and saves its information in block descriptor @a b. If no such block
|
||||
* is available the routine waits until one can be allocated, or until
|
||||
* the specified time limit is reached.
|
||||
*
|
||||
* @param b Pointer to block descriptor.
|
||||
* @param p Memory pool name.
|
||||
* @param s Requested block size, in bytes.
|
||||
* @param t Maximum number of ticks to wait.
|
||||
*
|
||||
* @return RC_OK on success, or RC_TIME on timeout.
|
||||
*/
|
||||
#define task_mem_pool_alloc_wait_timeout(b, p, s, t) \
|
||||
_task_mem_pool_alloc(b, p, s, t)
|
||||
#endif
|
||||
extern int task_mem_pool_alloc(struct k_block *blockptr, kmemory_pool_t pool_id,
|
||||
int reqsize, int32_t timeout);
|
||||
|
||||
/**
|
||||
* @}
|
||||
|
|
|
@ -835,7 +835,7 @@ int task_mbox_data_block_get(struct k_msg *M, struct k_block *block,
|
|||
/* 'normal' flow of task_mbox_data_block_get(): */
|
||||
|
||||
if (M->size != 0) {
|
||||
retval = _task_mem_pool_alloc(block, pool_id,
|
||||
retval = task_mem_pool_alloc(block, pool_id,
|
||||
M->size, timeout);
|
||||
if (retval != RC_OK) {
|
||||
return retval;
|
||||
|
|
|
@ -541,13 +541,13 @@ void _k_mem_pool_block_get(struct k_args *A)
|
|||
*
|
||||
* @return RC_OK, RC_FAIL, RC_TIME on success, failure, timeout respectively
|
||||
*/
|
||||
int _task_mem_pool_alloc(struct k_block *blockptr, kmemory_pool_t pool_id,
|
||||
int reqsize, int32_t time)
|
||||
int task_mem_pool_alloc(struct k_block *blockptr, kmemory_pool_t pool_id,
|
||||
int reqsize, int32_t timeout)
|
||||
{
|
||||
struct k_args A;
|
||||
|
||||
A.Comm = _K_SVC_MEM_POOL_BLOCK_GET;
|
||||
A.Time.ticks = time;
|
||||
A.Time.ticks = timeout;
|
||||
A.args.p1.pool_id = pool_id;
|
||||
A.args.p1.req_size = reqsize;
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ void mempool_test(void)
|
|||
PRINT_STRING(dashline, output_file);
|
||||
et = BENCH_START();
|
||||
for (i = 0; i < NR_OF_POOL_RUNS; i++) {
|
||||
task_mem_pool_alloc_wait(&block, DEMOPOOL, 16);
|
||||
task_mem_pool_alloc(&block, DEMOPOOL, 16, TICKS_UNLIMITED);
|
||||
task_mem_pool_free(&block);
|
||||
}
|
||||
et = TIME_STAMP_DELTA_GET(et);
|
||||
|
|
|
@ -99,7 +99,7 @@ static pfunc func_array[] = {
|
|||
(pfunc)_task_mbox_data_get,
|
||||
(pfunc)task_mbox_data_block_get,
|
||||
/* memory pool functions */
|
||||
(pfunc)_task_mem_pool_alloc,
|
||||
(pfunc)task_mem_pool_alloc,
|
||||
(pfunc)task_mem_pool_free,
|
||||
(pfunc)task_mem_pool_defragment,
|
||||
/* task functions */
|
||||
|
|
|
@ -31,9 +31,9 @@ or
|
|||
Sample Output:
|
||||
|
||||
tc_start() - Test Microkernel Memory Pools
|
||||
Testing task_mem_pool_alloc() ...
|
||||
Testing task_mem_pool_alloc_wait_timeout() ...
|
||||
Testing task_mem_pool_alloc_wait() ...
|
||||
Testing task_mem_pool_alloc(TICKS_NONE) ...
|
||||
Testing task_mem_pool_alloc(timeout) ...
|
||||
Testing task_mem_pool_alloc(TICKS_UNLIMITED) ...
|
||||
Testing task_mem_pool_defragment() ...
|
||||
===================================================================
|
||||
PASS - RegressionTask.
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
DESCRIPTION
|
||||
This modules tests the following memory pool routines:
|
||||
|
||||
task_mem_pool_alloc(), task_mem_pool_alloc_wait(), task_mem_pool_alloc_wait_timeout(),
|
||||
task_mem_pool_alloc(),
|
||||
task_mem_pool_free()
|
||||
*/
|
||||
|
||||
|
@ -129,14 +129,14 @@ int poolBlockGetFunc(struct k_block *block, kmemory_pool_t pool, int size,
|
|||
{
|
||||
ARG_UNUSED(unused);
|
||||
|
||||
return task_mem_pool_alloc(block, pool, size);
|
||||
return task_mem_pool_alloc(block, pool, size, TICKS_NONE);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @brief Wrapper for task_mem_pool_alloc_wait()
|
||||
* @brief Wrapper for task_mem_pool_alloc(TICKS_UNLIMITED)
|
||||
*
|
||||
* @return task_mem_pool_alloc_wait() return value
|
||||
* @return task_mem_pool_alloc() return value
|
||||
*/
|
||||
|
||||
int poolBlockGetWFunc(struct k_block *block, kmemory_pool_t pool, int size,
|
||||
|
@ -144,20 +144,20 @@ int poolBlockGetWFunc(struct k_block *block, kmemory_pool_t pool, int size,
|
|||
{
|
||||
ARG_UNUSED(unused);
|
||||
|
||||
return task_mem_pool_alloc_wait(block, pool, size);
|
||||
return task_mem_pool_alloc(block, pool, size, TICKS_UNLIMITED);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @brief Wrapper for task_mem_pool_alloc_wait_timeout()
|
||||
* @brief Wrapper for task_mem_pool_alloc(timeout)
|
||||
*
|
||||
* @return task_mem_pool_alloc_wait_timeout() return value
|
||||
* @return task_mem_pool_alloc(timeout) return value
|
||||
*/
|
||||
|
||||
int poolBlockGetWTFunc(struct k_block *block, kmemory_pool_t pool,
|
||||
int size, int32_t timeout)
|
||||
{
|
||||
return task_mem_pool_alloc_wait_timeout(block, pool, size, timeout);
|
||||
return task_mem_pool_alloc(block, pool, size, timeout);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -207,7 +207,7 @@ int poolBlockGetWork(char *string, poolBlockGetFunc_t func,
|
|||
|
||||
/**
|
||||
*
|
||||
* @brief Test the task_mem_pool_alloc() API
|
||||
* @brief Test the task_mem_pool_alloc(TICKS_NONE) API
|
||||
*
|
||||
* The pool is 4 kB in size.
|
||||
*
|
||||
|
@ -257,7 +257,7 @@ void HelperTask(void)
|
|||
|
||||
/**
|
||||
*
|
||||
* @brief Test task_mem_pool_alloc_wait_timeout()
|
||||
* @brief Test task_mem_pool_alloc(timeout)
|
||||
*
|
||||
* @return TC_PASS on success, TC_FAIL on failure
|
||||
*/
|
||||
|
@ -265,11 +265,11 @@ void HelperTask(void)
|
|||
int poolBlockGetTimeoutTest(void)
|
||||
{
|
||||
struct k_block block;
|
||||
int rv; /* return value from task_mem_pool_alloc_wait_timeout() */
|
||||
int rv; /* return value from task_mem_pool_alloc() */
|
||||
int j; /* loop counter */
|
||||
|
||||
for (j = 0; j < 8; j++) {
|
||||
rv = poolBlockGetWork("task_mem_pool_alloc_wait_timeout", poolBlockGetWTFunc,
|
||||
rv = poolBlockGetWork("task_mem_pool_alloc", poolBlockGetWTFunc,
|
||||
getwtSet, ARRAY_SIZE(getwtSet));
|
||||
if (rv != TC_PASS) {
|
||||
return TC_FAIL;
|
||||
|
@ -278,20 +278,20 @@ int poolBlockGetTimeoutTest(void)
|
|||
freeBlocks(getwtSet, ARRAY_SIZE(getwtSet));
|
||||
}
|
||||
|
||||
rv = task_mem_pool_alloc_wait_timeout(&helperBlock, POOL_ID, 3148, 5);
|
||||
rv = task_mem_pool_alloc(&helperBlock, POOL_ID, 3148, 5);
|
||||
if (rv != RC_OK) {
|
||||
TC_ERROR("Failed to get size 3148 byte block from POOL_ID\n");
|
||||
return TC_FAIL;
|
||||
}
|
||||
|
||||
rv = task_mem_pool_alloc(&block, POOL_ID, 3148);
|
||||
rv = task_mem_pool_alloc(&block, POOL_ID, 3148, TICKS_NONE);
|
||||
if (rv != RC_FAIL) {
|
||||
TC_ERROR("Unexpectedly got size 3148 byte block from POOL_ID\n");
|
||||
return TC_FAIL;
|
||||
}
|
||||
|
||||
task_sem_give(HELPER_SEM); /* Activate HelperTask */
|
||||
rv = task_mem_pool_alloc_wait_timeout(&block, POOL_ID, 3148, 20);
|
||||
rv = task_mem_pool_alloc(&block, POOL_ID, 3148, 20);
|
||||
if (rv != RC_OK) {
|
||||
TC_ERROR("Failed to get size 3148 byte block from POOL_ID\n");
|
||||
return TC_FAIL;
|
||||
|
@ -319,23 +319,23 @@ int poolBlockGetWaitTest(void)
|
|||
{
|
||||
int rv;
|
||||
|
||||
rv = task_mem_pool_alloc_wait(&blockList[0], POOL_ID, 3000);
|
||||
rv = task_mem_pool_alloc(&blockList[0], POOL_ID, 3000, TICKS_UNLIMITED);
|
||||
if (rv != RC_OK) {
|
||||
TC_ERROR("task_mem_pool_alloc_wait(3000) expected %d, got %d\n", RC_OK, rv);
|
||||
TC_ERROR("task_mem_pool_alloc(3000) expected %d, got %d\n", RC_OK, rv);
|
||||
return TC_FAIL;
|
||||
}
|
||||
|
||||
task_sem_give(ALTERNATE_SEM); /* Wake AlternateTask */
|
||||
evidence = 0;
|
||||
rv = task_mem_pool_alloc_wait(&blockList[1], POOL_ID, 128);
|
||||
rv = task_mem_pool_alloc(&blockList[1], POOL_ID, 128, TICKS_UNLIMITED);
|
||||
if (rv != RC_OK) {
|
||||
TC_ERROR("task_mem_pool_alloc_wait (128) expected %d, got %d\n", RC_OK, rv);
|
||||
TC_ERROR("task_mem_pool_alloc(128) expected %d, got %d\n", RC_OK, rv);
|
||||
return TC_FAIL;
|
||||
}
|
||||
|
||||
switch (evidence) {
|
||||
case 0:
|
||||
TC_ERROR("task_mem_pool_alloc_wait(128) did not block!\n");
|
||||
TC_ERROR("task_mem_pool_alloc(128) did not block!\n");
|
||||
return TC_FAIL;
|
||||
case 1:
|
||||
break;
|
||||
|
@ -396,9 +396,9 @@ int poolDefragTest(void)
|
|||
* time for DefragTask to finish.
|
||||
*/
|
||||
|
||||
rv = task_mem_pool_alloc_wait_timeout(&newBlock, POOL_ID, DEFRAG_BLK_TEST, 50);
|
||||
rv = task_mem_pool_alloc(&newBlock, POOL_ID, DEFRAG_BLK_TEST, 50);
|
||||
if (rv != RC_TIME) {
|
||||
TC_ERROR("task_mem_pool_alloc_wait_timeout() returned %d, not %d\n", rv, RC_TIME);
|
||||
TC_ERROR("task_mem_pool_alloc() returned %d, not %d\n", rv, RC_TIME);
|
||||
return TC_FAIL;
|
||||
}
|
||||
|
||||
|
@ -450,19 +450,19 @@ void RegressionTask(void)
|
|||
|
||||
TC_START("Test Microkernel Memory Pools");
|
||||
|
||||
TC_PRINT("Testing task_mem_pool_alloc() ...\n");
|
||||
TC_PRINT("Testing task_mem_pool_alloc(TICKS_NONE) ...\n");
|
||||
tcRC = poolBlockGetTest();
|
||||
if (tcRC != TC_PASS) {
|
||||
goto doneTests;
|
||||
}
|
||||
|
||||
TC_PRINT("Testing task_mem_pool_alloc_wait_timeout() ...\n");
|
||||
TC_PRINT("Testing task_mem_pool_alloc(timeout) ...\n");
|
||||
tcRC = poolBlockGetTimeoutTest();
|
||||
if (tcRC != TC_PASS) {
|
||||
goto doneTests;
|
||||
}
|
||||
|
||||
TC_PRINT("Testing task_mem_pool_alloc_wait() ...\n");
|
||||
TC_PRINT("Testing task_mem_pool_alloc(TICKS_UNLIMITED) ...\n");
|
||||
tcRC = poolBlockGetWaitTest();
|
||||
if (tcRC != TC_PASS) {
|
||||
goto doneTests;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue