Skip to content

Commit

Permalink
kernel: dynamic: Fix stack allocation logic
Browse files Browse the repository at this point in the history
Fix the preference allocation logic. If pool is prefered but POOL_SIZE
is 0 or pool allocation fails, it fallbacks to heap allocation if it
is enabled.

Signed-off-by: Flavio Ceolin <[email protected]>
  • Loading branch information
Flavio Ceolin committed Jun 30, 2023
1 parent 9d5ba55 commit 564bbca
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions kernel/dynamic.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,14 @@ k_thread_stack_t *z_impl_k_thread_stack_alloc(size_t size, int flags)
if (stack == NULL && CONFIG_DYNAMIC_THREAD_POOL_SIZE > 0) {
stack = z_thread_stack_alloc_pool(size);
}
} else if (IS_ENABLED(CONFIG_DYNAMIC_THREAD_PREFER_POOL) &&
CONFIG_DYNAMIC_THREAD_POOL_SIZE > 0) {
stack = z_thread_stack_alloc_pool(size);
if (stack == NULL && IS_ENABLED(CONFIG_DYNAMIC_THREAD_ALLOC)) {
} else if (IS_ENABLED(CONFIG_DYNAMIC_THREAD_PREFER_POOL)) {
if (CONFIG_DYNAMIC_THREAD_POOL_SIZE > 0) {
stack = z_thread_stack_alloc_pool(size);
}

if ((stack == NULL) && IS_ENABLED(CONFIG_DYNAMIC_THREAD_ALLOC)) {
stack = stack_alloc_dyn(size, flags);
}
} else {
return NULL;
}

return stack;
Expand Down

0 comments on commit 564bbca

Please sign in to comment.