arch/ceva: Mark the allocated stack with TCB_FLAG_FREE_STACK

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
Xiang Xiao 2022-02-17 03:02:39 +08:00 committed by Masayuki Ishikawa
parent f8df491d5d
commit 814cab1cd1
2 changed files with 8 additions and 14 deletions

View File

@ -216,6 +216,7 @@ int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype)
#endif /* CONFIG_STACK_COLORATION */
tcb->flags |= TCB_FLAG_FREE_STACK;
return OK;
}

View File

@ -83,35 +83,28 @@ void up_release_stack(FAR struct tcb_s *dtcb, uint8_t ttype)
{
/* Is there a stack allocated? */
if (dtcb->stack_alloc_ptr)
if (dtcb->stack_alloc_ptr && (dtcb->flags & TCB_FLAG_FREE_STACK))
{
#ifdef HAVE_KERNEL_HEAP
/* Use the kernel allocator if this is a kernel thread */
if (ttype == TCB_FLAG_TTYPE_KERNEL)
{
if (kmm_heapmember(dtcb->stack_alloc_ptr))
{
kmm_free(dtcb->stack_alloc_ptr);
}
kmm_free(dtcb->stack_alloc_ptr);
}
else
#endif
{
/* Use the user-space allocator if this is a task or pthread */
if (umm_heapmember(dtcb->stack_alloc_ptr))
{
kumm_free(dtcb->stack_alloc_ptr);
}
kumm_free(dtcb->stack_alloc_ptr);
}
/* Mark the stack freed */
dtcb->stack_alloc_ptr = NULL;
}
/* The size of the allocated stack is now zero */
/* Mark the stack freed */
dtcb->flags &= ~TCB_FLAG_FREE_STACK;
dtcb->stack_alloc_ptr = NULL;
dtcb->stack_base_ptr = NULL;
dtcb->adj_stack_size = 0;
}