Lines Matching full:stack
8 * @brief fixed-size stack object
27 void k_stack_init(struct k_stack *stack, stack_data_t *buffer,
30 z_waitq_init(&stack->wait_q);
31 stack->lock = (struct k_spinlock) {};
32 stack->next = buffer;
33 stack->base = buffer;
34 stack->top = stack->base + num_entries;
36 SYS_PORT_TRACING_OBJ_INIT(k_stack, stack);
37 k_object_init(stack);
40 k_obj_core_init_and_link(K_OBJ_CORE(stack), &obj_type_stack);
44 int32_t z_impl_k_stack_alloc_init(struct k_stack *stack, uint32_t num_entries)
49 SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_stack, alloc_init, stack);
53 k_stack_init(stack, buffer, num_entries);
54 stack->flags = K_STACK_FLAG_ALLOC;
60 SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_stack, alloc_init, stack, ret);
66 static inline int32_t z_vrfy_k_stack_alloc_init(struct k_stack *stack,
71 K_OOPS(K_SYSCALL_OBJ_NEVER_INIT(stack, K_OBJ_STACK));
75 return z_impl_k_stack_alloc_init(stack, num_entries);
80 int k_stack_cleanup(struct k_stack *stack)
82 SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_stack, cleanup, stack);
84 CHECKIF(z_waitq_head(&stack->wait_q) != NULL) {
85 SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_stack, cleanup, stack, -EAGAIN);
90 if ((stack->flags & K_STACK_FLAG_ALLOC) != (uint8_t)0) {
91 k_free(stack->base);
92 stack->base = NULL;
93 stack->flags &= ~K_STACK_FLAG_ALLOC;
96 SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_stack, cleanup, stack, 0);
101 int z_impl_k_stack_push(struct k_stack *stack, stack_data_t data)
105 k_spinlock_key_t key = k_spin_lock(&stack->lock);
107 SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_stack, push, stack);
109 CHECKIF(stack->next == stack->top) {
114 first_pending_thread = z_unpend_first_thread(&stack->wait_q);
121 z_reschedule(&stack->lock, key);
124 *(stack->next) = data;
125 stack->next++;
130 k_spin_unlock(&stack->lock, key);
133 SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_stack, push, stack, ret);
139 static inline int z_vrfy_k_stack_push(struct k_stack *stack, stack_data_t data)
141 K_OOPS(K_SYSCALL_OBJ(stack, K_OBJ_STACK));
143 return z_impl_k_stack_push(stack, data);
148 int z_impl_k_stack_pop(struct k_stack *stack, stack_data_t *data,
154 key = k_spin_lock(&stack->lock);
156 SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_stack, pop, stack, timeout);
158 if (likely(stack->next > stack->base)) {
159 stack->next--;
160 *data = *(stack->next);
161 k_spin_unlock(&stack->lock, key);
163 SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_stack, pop, stack, timeout, 0);
168 SYS_PORT_TRACING_OBJ_FUNC_BLOCKING(k_stack, pop, stack, timeout);
171 k_spin_unlock(&stack->lock, key);
173 SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_stack, pop, stack, timeout, -EBUSY);
178 result = z_pend_curr(&stack->lock, key, &stack->wait_q, timeout);
180 SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_stack, pop, stack, timeout, -EAGAIN);
187 SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_stack, pop, stack, timeout, 0);
193 static inline int z_vrfy_k_stack_pop(struct k_stack *stack,
196 K_OOPS(K_SYSCALL_OBJ(stack, K_OBJ_STACK));
198 return z_impl_k_stack_pop(stack, data, timeout);
206 /* Initialize stack object type */
213 STRUCT_SECTION_FOREACH(k_stack, stack) {
214 k_obj_core_init_and_link(K_OBJ_CORE(stack), &obj_type_stack);