forked from zephyrproject-rtos/zephyr
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
kernel: Add k_mem_pool compatibility layer on top of k_heap
Add a shim layer implementing the legacy k_mem_pool APIs backed by a k_heap instead of the original implementation. Signed-off-by: Andy Ross <[email protected]>
- Loading branch information
1 parent
0dd83b8
commit 8f0959c
Showing
6 changed files
with
115 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright (c) 2020 Intel Corporation | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
#ifndef ZEPHYR_INCLUDE_MEMPOOL_HEAP_H_ | ||
|
||
/* Compatibility implementation of a k_mem_pool backend in terms of a | ||
* k_heap | ||
*/ | ||
|
||
/* The "ID" of a k_heap-based mempool is just the tuple of the data | ||
* block pointer and the heap that allocated it | ||
*/ | ||
struct k_mem_block_id { | ||
void *data; | ||
struct k_heap *heap; | ||
}; | ||
|
||
/* Note the data pointer gets unioned with the same value stored in | ||
* the ID field to save space. | ||
*/ | ||
struct k_mem_block { | ||
union { | ||
void *data; | ||
struct k_mem_block_id id; | ||
}; | ||
}; | ||
|
||
struct k_mem_pool { | ||
struct k_heap *heap; | ||
}; | ||
|
||
/* Sizing is a heuristic, as k_mem_pool made promises about layout | ||
* that k_heap does not. We make space for the number of maximum | ||
* objects defined, and include extra so there's enough metadata space | ||
* available for the maximum number of minimum-sized objects to be | ||
* stored: 8 bytes for each desired chunk header, and a 24 word block | ||
* to reserve room for a "typical" set of bucket list heads (this size | ||
* was picked more to conform with existing test expectations than any | ||
* rigorous theory -- we have tests that rely on being able to | ||
* allocate the blocks promised and ones that make assumptions about | ||
* when memory will run out). | ||
*/ | ||
#define Z_MEM_POOL_DEFINE(name, minsz, maxsz, nmax, align) \ | ||
K_HEAP_DEFINE(poolheap_##name, \ | ||
((maxsz) * (nmax)) \ | ||
+ 8 * ((maxsz) * (nmax) / (minsz)) \ | ||
+ 24 * sizeof(void *)); \ | ||
struct k_mem_pool name = { \ | ||
.heap = &poolheap_##name \ | ||
} | ||
|
||
|
||
#endif /* ZEPHYR_INCLUDE_MEMPOOL_HEAP_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters