µEvLoop
A fast and lightweight event loop aimed at embedded platforms in C99.
object-pool.h
Go to the documentation of this file.
1 
6 #ifndef UEL_OBJECT_POOL_H
7 #define UEL_OBJECT_POOL_H
8 
10 
12 #include <stdint.h>
13 #include <stdlib.h>
15 
26 typedef struct uel_objpool uel_objpool_t;
27 struct uel_objpool {
29  uint8_t *buffer;
31  uel_cqueue_t queue;
32 };
33 
45 void uel_objpool_init(
46  uel_objpool_t *pool,
47  size_t size_log2n,
48  size_t item_size,
49  uint8_t *buffer,
50  void **queue_buffer
51 );
52 
58 void *uel_objpool_acquire(uel_objpool_t *pool);
59 
66 bool uel_objpool_release(uel_objpool_t *pool, void *element);
67 
73 bool uel_objpool_is_empty(uel_objpool_t *pool);
74 
85 #define UEL_DECLARE_OBJPOOL_BUFFERS(type, size_log2n, id) \
86  type id##_pool_buffer[(1<<size_log2n)]; \
87  void *id##_pool_queue_buffer[1<<size_log2n]
88 
96 #define UEL_OBJPOOL_BUFFERS(id) \
97  (uint8_t *)&id##_pool_buffer, id##_pool_queue_buffer
98 
109 #define UEL_OBJPOOL_BUFFERS_IN(id, obj) \
110  (uint8_t *)&obj.id##_pool_buffer, obj.id##_pool_queue_buffer
111 
122 #define UEL_OBJPOOL_BUFFERS_AT(id, obj) \
123  (uint8_t *)&obj->id##_pool_buffer, obj->id##_pool_queue_buffer
124 
125 #endif /* UEL_OBJECT_POOL_H */
uel_objpool_is_empty
bool uel_objpool_is_empty(uel_objpool_t *pool)
Checks if a pool is depleted.
uel_objpool::buffer
uint8_t * buffer
The buffer that contains each object managed by this pool.
Definition: object-pool.h:29
uel_objpool_acquire
void * uel_objpool_acquire(uel_objpool_t *pool)
Acquires an object from the pool.
uel_objpool_release
bool uel_objpool_release(uel_objpool_t *pool, void *element)
Releases an object to the pool.
circular-queue.h
Defines circular queues, fast and efficient FIFO data structures.
uel_objpool::queue
uel_cqueue_t queue
The queue containing the addresses for each object in the pool.
Definition: object-pool.h:31
uel_objpool
Pre-allocated memory bound to speciffic types suitable for providing dynamic object management in the...
Definition: object-pool.h:27
uel_objpool_init
void uel_objpool_init(uel_objpool_t *pool, size_t size_log2n, size_t item_size, uint8_t *buffer, void **queue_buffer)
Initialises an object pool.