Veritable Lasagna
An Allocator & Data Structure Library for C.
Loading...
Searching...
No Matches
vl_async_pool.h
Go to the documentation of this file.
1#ifndef VL_ASYNC_POOL_H
2#define VL_ASYNC_POOL_H
3
4#include "vl_atomic.h"
5#include "vl_atomic_ptr.h"
6
44typedef struct{
45 vl_atomic_ptr freeStack; // Head of the Treiber stack, storing free elements.
46 vl_atomic_uint32_t freeLength; // Total number of nodes in the free stack.
47
48 vl_atomic_ptr primaryBlock; // Head of the list of memory blocks.
49 vl_atomic_bool_t allocatingFlag; // Atomic allocation flag set when allocating a new block.
50 vl_atomic_uint16_t totalBlocks; // Total number of allocated blocks.
51
52 vl_uint16_t elementSize; // Size, in bytes, of each pool element.
53 vl_uint16_t nodeSize; // Size in bytes, of an individual pool node.
55
59typedef struct{
63 union{
64 vl_uintptr_t next;
65 vl_tagged_ptr pad;
66 };
67} vl_async_pool_header;
68
73
78
88void vlAsyncPoolInit(vl_async_pool* pool, vl_uint16_t elementSize);
89
102
112vl_async_pool* vlAsyncPoolNew(vl_uint16_t elementSize);
113
126
139
151
158void* vlAsyncPoolTake(vl_async_pool* pool);
159
167void vlAsyncPoolReturn(vl_async_pool* pool, void* element);
168
169#endif //VL_ASYNC_POOL_H
void vlAsyncPoolReturn(vl_async_pool *pool, void *element)
Returns an element to the specified async pool.
Definition vl_async_pool.c:173
vl_atomic_uint16_t totalBlocks
Definition vl_async_pool.h:50
vl_atomic_bool_t allocatingFlag
Definition vl_async_pool.h:49
vl_async_pool * vlAsyncPoolNew(vl_uint16_t elementSize)
Allocates and initializes a new async pool.
Definition vl_async_pool.c:95
void * vlAsyncPoolTake(vl_async_pool *pool)
Takes an element from the specified async pool.
Definition vl_async_pool.c:144
vl_uint16_t nodeSize
Definition vl_async_pool.h:53
vl_atomic_ptr primaryBlock
Definition vl_async_pool.h:48
vl_atomic_uint32_t freeLength
Definition vl_async_pool.h:46
vl_atomic_ptr freeStack
Definition vl_async_pool.h:45
void vlAsyncPoolReset(vl_async_pool *pool)
Resets the specified async pool, returning it to its state when it was first initialized.
Definition vl_async_pool.c:106
const vl_ularge_t VL_ASYNC_POOL_NODE_ALIGNMENT
Byte-level alignment of individual vlAsyncPool element nodes.
Definition vl_async_pool.c:11
void vlAsyncPoolClear(vl_async_pool *pool)
Resets the state of all blocks and the pool, retaining memory but invalidating taken elements.
Definition vl_async_pool.c:128
void vlAsyncPoolDelete(vl_async_pool *pool)
Deinitializes and deletes the specified async pool, and all associated memory.
Definition vl_async_pool.c:101
void vlAsyncPoolFree(vl_async_pool *pool)
Frees the specified async pool, and all associated memory.
Definition vl_async_pool.c:84
vl_uint16_t elementSize
Definition vl_async_pool.h:52
const vl_ularge_t VL_ASYNC_POOL_BLOCK_ALIGNMENT
Byte-level alignment of individual vlAsyncPool memory blocks.
Definition vl_async_pool.c:9
void vlAsyncPoolInit(vl_async_pool *pool, vl_uint16_t elementSize)
Initializes the specified async pool.
Definition vl_async_pool.c:70
A Non-Blocking Atomic (/Asynchronous) Memory Pool.
Definition vl_async_pool.h:44
VL_ATOMIC vl_tagged_ptr vl_atomic_ptr
Atomic variant of vl_tagged_ptr.
Definition vl_atomic_ptr.h:28
A Tagged Pointer structure for use with Atomic, lock-free algorithms.
Definition vl_atomic_ptr.h:19
VL_UPTR_T vl_uintptr_t
Unsigned integer type suitable for expressing memory addresses.
Definition vl_numtypes.h:101
VL_ULARGE_T vl_ularge_t
Largest available unsigned integer type.
Definition vl_numtypes.h:74