µEvLoop
A fast and lightweight event loop aimed at embedded platforms in C99.
automatic-pool.h
Go to the documentation of this file.
1 
8 #ifndef UEL_AUTOMATIC_POOL_H
9 #define UEL_AUTOMATIC_POOL_H
10 
12 #include "uevloop/utils/closure.h"
13 
14 struct uel_autopool;
15 
26 struct uel_autoptr {
27  void *object;
28  struct uel_autopool *source;
29 };
30 
34 typedef void ** uel_autoptr_t;
35 
45 
50 typedef struct uel_autopool uel_autopool_t;
51 struct uel_autopool {
52  uel_objpool_t autoptr_pool;
53  uel_closure_t constructor;
54  uel_closure_t destructor;
55 };
56 
71  uel_autopool_t *pool,
72  size_t size_log2n,
73  size_t item_size,
74  uint8_t *object_buffer,
75  struct uel_autoptr *autoptr_buffer,
76  void **queue_buffer
77 );
78 
90 uel_autoptr_t uel_autopool_alloc(uel_autopool_t *pool);
91 
92 
98 bool uel_autopool_is_empty(uel_autopool_t *pool);
99 
110 void uel_autopool_set_constructor(uel_autopool_t *pool, uel_closure_t constructor);
111 
122 void uel_autopool_set_destructor(uel_autopool_t *pool, uel_closure_t destructor);
123 
134 #define UEL_DECLARE_AUTOPOOL_BUFFERS(type, size_log2n, id) \
135  type id##_buffer[(1<<size_log2n)]; \
136  struct uel_autoptr id##_pool_buffer[1<<size_log2n]; \
137  void *id##_pool_queue_buffer[1<<size_log2n];
138 
146 #define UEL_AUTOPOOL_BUFFERS(id) \
147  (uint8_t *)&id##_buffer, id##_pool_buffer, id##_pool_queue_buffer
148 
159 #define UEL_AUTOPOOL_BUFFERS_IN(id, obj) \
160  (uint8_t *)&obj.id##_buffer, obj.id##_pool_buffer, \
161  obj.id##_pool_queue_buffer
162 
173 #define UEL_AUTOPOOL_BUFFERS_AT(id, obj) \
174  (uint8_t *)&obj->id##_buffer, obj->id##_pool_buffer, \
175  obj->id##_pool_queue_buffer
176 
177 #endif /* end of include guard: UEL_AUTOMATIC_POOL_H */
uel_autoptr
Automatic pointers are pointers wrapped by information of where they were issued.
Definition: automatic-pool.h:26
uel_autopool_alloc
uel_autoptr_t uel_autopool_alloc(uel_autopool_t *pool)
Allocates an object and wrap it in a automatic pointer.
uel_autopool::autoptr_pool
uel_objpool_t autoptr_pool
The object pool that holds autopointers.
Definition: automatic-pool.h:52
uel_autoptr_t
void ** uel_autoptr_t
Aliases uel_autoptr_t to void ** so it can be cast to pointers to other types.
Definition: automatic-pool.h:34
uel_autopool_init
void uel_autopool_init(uel_autopool_t *pool, size_t size_log2n, size_t item_size, uint8_t *object_buffer, struct uel_autoptr *autoptr_buffer, void **queue_buffer)
Initialises an automatic pool.
closure.h
Defines closures, objects that bind functions to creating and calling contexts.
uel_autoptr::object
void * object
A pointer to the wrapped object.
Definition: automatic-pool.h:27
uel_autoptr_dealloc
void uel_autoptr_dealloc(uel_autoptr_t autoptr)
Deallocates an automatic pointer.
object-pool.h
Defines object pools, arrays of pre-allocated objects for dynamic use.
uel_autopool_set_constructor
void uel_autopool_set_constructor(uel_autopool_t *pool, uel_closure_t constructor)
Sets the constructor closure of an autopool.
uel_autoptr::source
struct uel_autopool * source
The pool where the autoptr object was issued.
Definition: automatic-pool.h:28
uel_autopool_set_destructor
void uel_autopool_set_destructor(uel_autopool_t *pool, uel_closure_t destructor)
Sets the destructor closure of an autopool.
uel_autopool::destructor
uel_closure_t destructor
The destructor closure.
Definition: automatic-pool.h:54
uel_autopool
Automatic pools are wrappers to object pools. They manage the acquisition and release cycle from obje...
Definition: automatic-pool.h:51
uel_autopool::constructor
uel_closure_t constructor
The constructor closure.
Definition: automatic-pool.h:53
uel_autopool_is_empty
bool uel_autopool_is_empty(uel_autopool_t *pool)
Checks if a pool is depleted.