Lines Matching refs:stack
27 void k_stack_init(struct k_stack *stack, stack_data_t *buffer, in k_stack_init() argument
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()
36 SYS_PORT_TRACING_OBJ_INIT(k_stack, stack); in k_stack_init()
37 k_object_init(stack); in k_stack_init()
40 k_obj_core_init_and_link(K_OBJ_CORE(stack), &obj_type_stack); in k_stack_init()
44 int32_t z_impl_k_stack_alloc_init(struct k_stack *stack, uint32_t num_entries) in z_impl_k_stack_alloc_init() argument
49 SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_stack, alloc_init, stack); in z_impl_k_stack_alloc_init()
53 k_stack_init(stack, buffer, num_entries); in z_impl_k_stack_alloc_init()
54 stack->flags = K_STACK_FLAG_ALLOC; in z_impl_k_stack_alloc_init()
60 SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_stack, alloc_init, stack, ret); in z_impl_k_stack_alloc_init()
66 static inline int32_t z_vrfy_k_stack_alloc_init(struct k_stack *stack, in z_vrfy_k_stack_alloc_init() argument
71 K_OOPS(K_SYSCALL_OBJ_NEVER_INIT(stack, K_OBJ_STACK)); in z_vrfy_k_stack_alloc_init()
75 return z_impl_k_stack_alloc_init(stack, num_entries); in z_vrfy_k_stack_alloc_init()
80 int k_stack_cleanup(struct k_stack *stack) in k_stack_cleanup() argument
82 SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_stack, cleanup, stack); in k_stack_cleanup()
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()
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()
96 SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_stack, cleanup, stack, 0); in k_stack_cleanup()
101 int z_impl_k_stack_push(struct k_stack *stack, stack_data_t data) in z_impl_k_stack_push() argument
105 k_spinlock_key_t key = k_spin_lock(&stack->lock); in z_impl_k_stack_push()
107 SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_stack, push, stack); in z_impl_k_stack_push()
109 CHECKIF(stack->next == stack->top) { 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()
133 SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_stack, push, stack, ret); in z_impl_k_stack_push()
139 static inline int z_vrfy_k_stack_push(struct k_stack *stack, stack_data_t data) in z_vrfy_k_stack_push() argument
141 K_OOPS(K_SYSCALL_OBJ(stack, K_OBJ_STACK)); in z_vrfy_k_stack_push()
143 return z_impl_k_stack_push(stack, data); in z_vrfy_k_stack_push()
148 int z_impl_k_stack_pop(struct k_stack *stack, stack_data_t *data, in z_impl_k_stack_pop() argument
154 key = k_spin_lock(&stack->lock); in z_impl_k_stack_pop()
156 SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_stack, pop, stack, timeout); 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()
163 SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_stack, pop, stack, timeout, 0); in z_impl_k_stack_pop()
168 SYS_PORT_TRACING_OBJ_FUNC_BLOCKING(k_stack, pop, stack, timeout); 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()
178 result = z_pend_curr(&stack->lock, key, &stack->wait_q, timeout); 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()
187 SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_stack, pop, stack, timeout, 0); in z_impl_k_stack_pop()
193 static inline int z_vrfy_k_stack_pop(struct k_stack *stack, in z_vrfy_k_stack_pop() argument
196 K_OOPS(K_SYSCALL_OBJ(stack, K_OBJ_STACK)); in z_vrfy_k_stack_pop()
198 return z_impl_k_stack_pop(stack, data, timeout); in z_vrfy_k_stack_pop()
213 STRUCT_SECTION_FOREACH(k_stack, stack) { in init_stack_obj_core_list()
214 k_obj_core_init_and_link(K_OBJ_CORE(stack), &obj_type_stack); in init_stack_obj_core_list()