diff --git a/include/kernel.h b/include/kernel.h index ee86c719b02..eb41e566f74 100644 --- a/include/kernel.h +++ b/include/kernel.h @@ -2708,9 +2708,11 @@ __syscall s32_t k_stack_alloc_init(struct k_stack *stack, * if the buffer wasn't dynamically allocated. * * @param stack Address of the stack. + * @retval 0 on success + * @retval -EAGAIN when object is still in use * @req K-STACK-001 */ -void k_stack_cleanup(struct k_stack *stack); +int k_stack_cleanup(struct k_stack *stack); /** * @brief Push an element onto a stack. @@ -2722,10 +2724,11 @@ void k_stack_cleanup(struct k_stack *stack); * @param stack Address of the stack. * @param data Value to push onto the stack. * - * @return N/A + * @retval 0 on success + * @retval -ENOMEM if stack is full * @req K-STACK-001 */ -__syscall void k_stack_push(struct k_stack *stack, stack_data_t data); +__syscall int k_stack_push(struct k_stack *stack, stack_data_t data); /** * @brief Pop an element from a stack. diff --git a/kernel/stack.c b/kernel/stack.c index 4a4cb4ee93c..fc737a56338 100644 --- a/kernel/stack.c +++ b/kernel/stack.c @@ -15,7 +15,7 @@ #include #include #include -#include +#include #include #include #include @@ -81,23 +81,28 @@ static inline s32_t z_vrfy_k_stack_alloc_init(struct k_stack *stack, #include #endif -void k_stack_cleanup(struct k_stack *stack) +int k_stack_cleanup(struct k_stack *stack) { - __ASSERT_NO_MSG(z_waitq_head(&stack->wait_q) == NULL); + CHECKIF(z_waitq_head(&stack->wait_q) != NULL) { + return -EAGAIN; + } if ((stack->flags & K_STACK_FLAG_ALLOC) != (u8_t)0) { k_free(stack->base); stack->base = NULL; stack->flags &= ~K_STACK_FLAG_ALLOC; } + return 0; } -void z_impl_k_stack_push(struct k_stack *stack, stack_data_t data) +int z_impl_k_stack_push(struct k_stack *stack, stack_data_t data) { struct k_thread *first_pending_thread; k_spinlock_key_t key; - __ASSERT(stack->next != stack->top, "stack is full"); + CHECKIF(stack->next == stack->top) { + return -ENOMEM; + } key = k_spin_lock(&stack->lock); @@ -109,22 +114,21 @@ void z_impl_k_stack_push(struct k_stack *stack, stack_data_t data) z_thread_return_value_set_with_data(first_pending_thread, 0, (void *)data); z_reschedule(&stack->lock, key); - return; } else { *(stack->next) = data; stack->next++; k_spin_unlock(&stack->lock, key); } + return 0; } #ifdef CONFIG_USERSPACE -static inline void z_vrfy_k_stack_push(struct k_stack *stack, stack_data_t data) +static inline int z_vrfy_k_stack_push(struct k_stack *stack, stack_data_t data) { Z_OOPS(Z_SYSCALL_OBJ(stack, K_OBJ_STACK)); - Z_OOPS(Z_SYSCALL_VERIFY_MSG(stack->next != stack->top, - "stack is full")); - z_impl_k_stack_push(stack, data); + + return z_impl_k_stack_push(stack, data); } #include #endif