MOS Source Code
Loading...
Searching...
No Matches
stack.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-3.0-or-later
2
3#pragma once
4
5#include <mos/moslib_global.h>
6#include <mos/types.h>
7
14typedef struct _downwards_stack_t
15{
18 size_t capacity;
20
21MOSAPI void stack_init(downwards_stack_t *stack, void *mem_region_bottom, size_t size);
23
24MOSAPI void *stack_grow(downwards_stack_t *stack, size_t size);
25MOSAPI void *stack_push(downwards_stack_t *stack, const void *data, size_t size);
26#define stack_push_val(stack, val) \
27 do \
28 { \
29 typeof(val) _val = (val); \
30 stack_push(stack, &_val, sizeof(_val)); \
31 } while (0)
32
33// ! WARN: Caller must ensure the data is at least size bytes long
34MOSAPI void stack_pop(downwards_stack_t *stack, size_t size, void *data);
35#define stack_pop_val(stack, val) \
36 do \
37 { \
38 typeof(val) _val; \
39 stack_pop(stack, sizeof(_val), &_val); \
40 (val) = _val; \
41 } while (0)
MOSAPI void stack_deinit(downwards_stack_t *stack)
Definition stack.c:17
MOSAPI void stack_init(downwards_stack_t *stack, void *mem_region_bottom, size_t size)
Definition stack.c:8
MOSAPI void * stack_grow(downwards_stack_t *stack, size_t size)
Definition stack.c:22
MOSAPI void stack_pop(downwards_stack_t *stack, size_t size, void *data)
Definition stack.c:43
MOSAPI void * stack_push(downwards_stack_t *stack, const void *data, size_t size)
Definition stack.c:32
#define MOSAPI
Definition mos_global.h:102
size_t size
Definition slab.c:30
size_t capacity
Definition stack.h:18
unsigned long ptr_t
Definition types.h:25