Lines Matching +full:fixed +full:- +full:top
2 * Copyright (c) 2010-2016 Wind River Systems, Inc.
4 * SPDX-License-Identifier: Apache-2.0
8 * @brief fixed-size stack object
30 z_waitq_init(&stack->wait_q); in k_stack_init()
31 stack->lock = (struct k_spinlock) {}; in k_stack_init()
32 stack->next = buffer; in k_stack_init()
33 stack->base = buffer; in k_stack_init()
34 stack->top = stack->base + num_entries; in k_stack_init()
54 stack->flags = K_STACK_FLAG_ALLOC; in z_impl_k_stack_alloc_init()
57 ret = -ENOMEM; in z_impl_k_stack_alloc_init()
84 CHECKIF(z_waitq_head(&stack->wait_q) != NULL) { in k_stack_cleanup()
85 SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_stack, cleanup, stack, -EAGAIN); in k_stack_cleanup()
87 return -EAGAIN; in k_stack_cleanup()
90 if ((stack->flags & K_STACK_FLAG_ALLOC) != (uint8_t)0) { in k_stack_cleanup()
91 k_free(stack->base); in k_stack_cleanup()
92 stack->base = NULL; in k_stack_cleanup()
93 stack->flags &= ~K_STACK_FLAG_ALLOC; in k_stack_cleanup()
105 k_spinlock_key_t key = k_spin_lock(&stack->lock); in z_impl_k_stack_push()
109 CHECKIF(stack->next == stack->top) { in z_impl_k_stack_push()
110 ret = -ENOMEM; in z_impl_k_stack_push()
114 first_pending_thread = z_unpend_first_thread(&stack->wait_q); in z_impl_k_stack_push()
121 z_reschedule(&stack->lock, key); in z_impl_k_stack_push()
124 *(stack->next) = data; in z_impl_k_stack_push()
125 stack->next++; in z_impl_k_stack_push()
130 k_spin_unlock(&stack->lock, key); in z_impl_k_stack_push()
154 key = k_spin_lock(&stack->lock); in z_impl_k_stack_pop()
158 if (likely(stack->next > stack->base)) { in z_impl_k_stack_pop()
159 stack->next--; in z_impl_k_stack_pop()
160 *data = *(stack->next); in z_impl_k_stack_pop()
161 k_spin_unlock(&stack->lock, key); in z_impl_k_stack_pop()
171 k_spin_unlock(&stack->lock, key); in z_impl_k_stack_pop()
173 SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_stack, pop, stack, timeout, -EBUSY); in z_impl_k_stack_pop()
175 return -EBUSY; in z_impl_k_stack_pop()
178 result = z_pend_curr(&stack->lock, key, &stack->wait_q, timeout); in z_impl_k_stack_pop()
179 if (result == -EAGAIN) { in z_impl_k_stack_pop()
180 SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_stack, pop, stack, timeout, -EAGAIN); in z_impl_k_stack_pop()
182 return -EAGAIN; in z_impl_k_stack_pop()
185 *data = (stack_data_t)_current->base.swap_data; in z_impl_k_stack_pop()