diff options
| author | Kimplul <kimi.h.kuparinen@gmail.com> | 2022-05-29 21:48:00 +0300 |
|---|---|---|
| committer | Kimplul <kimi.h.kuparinen@gmail.com> | 2022-05-29 21:48:00 +0300 |
| commit | 6295648f04d1d5d7e8b99d3fdaa8d497406eadf9 (patch) | |
| tree | d2bbe97ae40213356f9e2611285a78f7bac04bca /include/apos/nodes.h | |
| parent | 1f7f2251faaef84cd441088f02a66440fa7b59cc (diff) | |
| download | kmi-6295648f04d1d5d7e8b99d3fdaa8d497406eadf9.tar.gz kmi-6295648f04d1d5d7e8b99d3fdaa8d497406eadf9.zip | |
continue documentation
Diffstat (limited to 'include/apos/nodes.h')
| -rw-r--r-- | include/apos/nodes.h | 53 |
1 files changed, 52 insertions, 1 deletions
diff --git a/include/apos/nodes.h b/include/apos/nodes.h index 3fefc4c..6cec21c 100644 --- a/include/apos/nodes.h +++ b/include/apos/nodes.h @@ -9,32 +9,83 @@ #include <apos/types.h> -enum node_status { FREE = 0, USED = 1 }; +/** Node slot status. */ +enum node_status { + /** Free. */ + FREE = 0, + + /** Used. */ + USED = 1 +}; + +/** Header for a region in memory with node slots. */ struct node_region { + /** Number of used slots in this region. + * \note Total number of slots is calculated on an instance basis. */ size_t used_nodes; + /** Next node region in free list. */ struct node_region *av_next; + + /** Previous node region in free list. */ struct node_region *av_prev; + /** Next node slot region. */ struct node_region *next; + + /** Previous slot node region. */ struct node_region *prev; }; +/** Node subsystem instance. */ struct node_root { + /** Size of each node. */ size_t node_size; + /** Maximum number of node slots in one region. */ size_t max_nodes; + /** Offset of node slot state bitmap from start of region. */ ptrdiff_t bitmap; + + /** Offset of first node from start of region. */ ptrdiff_t first_node; + /** List of all node regions. */ struct node_region *head; + + /** List of node regions with free slots. */ struct node_region *av_head; }; +/** + * Initialize node subsystem instance. + * + * @param r Node region root. + * @param node_size Size of one node. + */ void init_nodes(struct node_root *r, size_t node_size); + +/** + * Destroy node subsystem instance. + * + * @param r Node region root. + */ void destroy_nodes(struct node_root *r); +/** + * Allocate a new node. + * + * @param r Node region root. + * @return Pointer to allocated node when succesful, \c 0 otherwise. + */ void *get_node(struct node_root *r); + +/** + * Free a node. + * + * @param r Node region root. + * @param p Pointer to node to free. + */ void free_node(struct node_root *r, void *p); #endif /* APOS_NODES_H */ |
