kernel: heap: Add support for CONFIG_MULTITHREADING=n
Ensure that k_heap is not attempt to block the thread when timeout is set and space cannot be allocated. Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
This commit is contained in:
parent
3b4b7c3a37
commit
c482a572d4
2 changed files with 6 additions and 3 deletions
|
@ -4841,7 +4841,7 @@ extern int k_mem_slab_init(struct k_mem_slab *slab, void *buffer,
|
|||
* This routine allocates a memory block from a memory slab.
|
||||
*
|
||||
* @note @a timeout must be set to K_NO_WAIT if called from ISR.
|
||||
* @note When CONFIG_MULTITHREADING=n any @timeout is treated as K_NO_WAIT.
|
||||
* @note When CONFIG_MULTITHREADING=n any @a timeout is treated as K_NO_WAIT.
|
||||
*
|
||||
* @funcprops \isr_ok
|
||||
*
|
||||
|
@ -4962,6 +4962,7 @@ void k_heap_init(struct k_heap *h, void *mem, size_t bytes);
|
|||
* k_heap_free().
|
||||
*
|
||||
* @note @a timeout must be set to K_NO_WAIT if called from ISR.
|
||||
* @note When CONFIG_MULTITHREADING=n any @a timeout is treated as K_NO_WAIT.
|
||||
*
|
||||
* @funcprops \isr_ok
|
||||
*
|
||||
|
@ -4985,6 +4986,7 @@ void *k_heap_aligned_alloc(struct k_heap *h, size_t align, size_t bytes,
|
|||
* the timeout, NULL will be returned.
|
||||
*
|
||||
* @note @a timeout must be set to K_NO_WAIT if called from ISR.
|
||||
* @note When CONFIG_MULTITHREADING=n any @a timeout is treated as K_NO_WAIT.
|
||||
*
|
||||
* @funcprops \isr_ok
|
||||
*
|
||||
|
|
|
@ -39,7 +39,8 @@ void *k_heap_aligned_alloc(struct k_heap *h, size_t align, size_t bytes,
|
|||
ret = sys_heap_aligned_alloc(&h->heap, align, bytes);
|
||||
|
||||
now = sys_clock_tick_get();
|
||||
if ((ret != NULL) || ((end - now) <= 0)) {
|
||||
if (!IS_ENABLED(CONFIG_MULTITHREADING) ||
|
||||
(ret != NULL) || ((end - now) <= 0)) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -58,7 +59,7 @@ void k_heap_free(struct k_heap *h, void *mem)
|
|||
|
||||
sys_heap_free(&h->heap, mem);
|
||||
|
||||
if (z_unpend_all(&h->wait_q) != 0) {
|
||||
if (IS_ENABLED(CONFIG_MULTITHREADING) && z_unpend_all(&h->wait_q) != 0) {
|
||||
z_reschedule(&h->lock, key);
|
||||
} else {
|
||||
k_spin_unlock(&h->lock, key);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue