Remove prefix mempool from mempools.
See commit about shared pointer.
This commit is contained in:
1 parent
5e6fb73898
commit
b49e286ae2
5 files changed
+44
-41
No files matched your search
@@ -2611,11 +2611,12 @@ The mempool functions are not thread safe for a given mempool.
|
|||||||
|
|
||||||
#### MEMPOOL\_DEF(name, type)
|
#### MEMPOOL\_DEF(name, type)
|
||||||
|
|
||||||
Generate specialized functions named 'name' to alloc & free a 'type' object.
|
Generate specialized functions & types prefixed by 'name'
|
||||||
|
to alloc & free a 'type' object.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
MEMPOOL_DEF(uint, unsigned int)
|
MEMPOOL_DEF(mempool_uint, unsigned int)
|
||||||
|
|
||||||
void f(void) {
|
void f(void) {
|
||||||
mempool_uint_t m;
|
mempool_uint_t m;
|
||||||
@@ -2629,27 +2630,27 @@ Example:
|
|||||||
|
|
||||||
The following methods are automatically and properly created by the previous macros. In the following methods, name stands for the name given to the macro which is used to identify the type.
|
The following methods are automatically and properly created by the previous macros. In the following methods, name stands for the name given to the macro which is used to identify the type.
|
||||||
|
|
||||||
##### mempool\_name\_t
|
##### name\_t
|
||||||
|
|
||||||
The type of a mempool.
|
The type of a mempool.
|
||||||
|
|
||||||
##### void mempool\_name\_init(mempool\_name\_t m)
|
##### void name\_init(name\_t m)
|
||||||
|
|
||||||
Initialize the mempool 'm'.
|
Initialize the mempool 'm'.
|
||||||
|
|
||||||
##### void mempool\_name\_clear(mempool\_name\_t m)
|
##### void name\_clear(name\_t m)
|
||||||
|
|
||||||
Clear the mempool 'm'.
|
Clear the mempool 'm'.
|
||||||
All allocated objects associated to the this mempool which weren't explicitly freed
|
All allocated objects associated to the this mempool which weren't explicitly freed
|
||||||
will be deleted too (without calling their clear method).
|
will be deleted too (without calling their clear method).
|
||||||
|
|
||||||
##### type *mempool\_name\_alloc(mempool\_name\_t m)
|
##### type *name\_alloc(name\_t m)
|
||||||
|
|
||||||
Create a new object of type 'type' and return a new pointer to the uninitialized object.
|
Create a new object of type 'type' and return a new pointer to the uninitialized object.
|
||||||
|
|
||||||
##### void mempool\_name\_free(mempool\_name\_t m, type *p)
|
##### void name\_free(name\_t m, type *p)
|
||||||
|
|
||||||
Free the object 'p' created by the call to mempool\_name\_alloc.
|
Free the object 'p' created by the call to name\_alloc.
|
||||||
The clear method of the type is not called.
|
The clear method of the type is not called.
|
||||||
|
|
||||||
|
|
||||||
@@ -100,7 +100,7 @@
|
|||||||
\
|
\
|
||||||
/* If MEMPOOL is required, we need to define it */ \
|
/* If MEMPOOL is required, we need to define it */ \
|
||||||
M_IF_METHOD(MEMPOOL, oplist)( \
|
M_IF_METHOD(MEMPOOL, oplist)( \
|
||||||
MEMPOOL_DEF(M_C(list_,name), struct M_C3(list_, name, _s)) \
|
MEMPOOL_DEF(M_C(mempool_list_,name), struct M_C3(list_, name, _s)) \
|
||||||
M_GET_MEMPOOL_LINKAGE oplist M_C3(mempool_list_, name, _t) M_GET_MEMPOOL oplist; \
|
M_GET_MEMPOOL_LINKAGE oplist M_C3(mempool_list_, name, _t) M_GET_MEMPOOL oplist; \
|
||||||
static inline struct M_C3(list_, name, _s) *M_C3(listi_,name,_new)(void) { \
|
static inline struct M_C3(list_, name, _s) *M_C3(listi_,name,_new)(void) { \
|
||||||
return M_C3(mempool_list_, name, _alloc)(M_GET_MEMPOOL oplist); \
|
return M_C3(mempool_list_, name, _alloc)(M_GET_MEMPOOL oplist); \
|
||||||
|
|||||||
+32
-30
@@ -43,29 +43,30 @@
|
|||||||
// NOTE: Can not use m-list since it may be expanded from LIST_DEF
|
// NOTE: Can not use m-list since it may be expanded from LIST_DEF
|
||||||
|
|
||||||
#define MEMPOOL_DEF(name, type) \
|
#define MEMPOOL_DEF(name, type) \
|
||||||
\
|
\
|
||||||
typedef union M_C3(mempool_,name,_union_s) { \
|
typedef union M_C(name,_union_s) { \
|
||||||
type t; \
|
type t; \
|
||||||
union M_C3(mempool_,name,_union_s) *next; \
|
union M_C(name,_union_s) *next; \
|
||||||
} M_C3(mempool_,name,_union_t); \
|
} M_C(name,_union_t); \
|
||||||
\
|
\
|
||||||
typedef struct M_C3(mempool_,name,_segment_s) { \
|
typedef struct M_C(name,_segment_s) { \
|
||||||
unsigned int count; \
|
unsigned int count; \
|
||||||
struct M_C3(mempool_,name,_segment_s) *next; \
|
struct M_C(name,_segment_s) *next; \
|
||||||
M_C3(mempool_,name,_union_t) tab[MEMPOOLI_MAX_PER_SEGMENT(type)]; \
|
M_C(name,_union_t) tab[MEMPOOLI_MAX_PER_SEGMENT(type)]; \
|
||||||
} M_C3(mempool_,name,_segment_t); \
|
} M_C(name,_segment_t); \
|
||||||
\
|
\
|
||||||
typedef struct { \
|
typedef struct { \
|
||||||
M_C3(mempool_,name,_union_t) *free_list; \
|
M_C(name,_union_t) *free_list; \
|
||||||
M_C3(mempool_,name,_segment_t) *current_segment; \
|
M_C(name,_segment_t) *current_segment; \
|
||||||
} M_C3(mempool_,name,_t)[1]; \
|
} M_C(name,_t)[1]; \
|
||||||
\
|
\
|
||||||
static inline void \
|
static inline void \
|
||||||
M_C3(mempool_,name,_init)(M_C3(mempool_,name,_t) mem) \
|
M_C(name,_init)(M_C(name,_t) mem) \
|
||||||
{ \
|
{ \
|
||||||
mem->free_list = NULL; \
|
mem->free_list = NULL; \
|
||||||
const size_t size = sizeof (M_C3(mempool_,name,_segment_t)); \
|
const size_t size = sizeof (M_C(name,_segment_t)); \
|
||||||
mem->current_segment = M_ASSIGN_CAST(M_C3(mempool_,name,_segment_t)*, malloc (size)); \
|
mem->current_segment = M_ASSIGN_CAST(M_C(name,_segment_t)*, \
|
||||||
|
malloc (size)); \
|
||||||
if (mem->current_segment == NULL) { \
|
if (mem->current_segment == NULL) { \
|
||||||
M_MEMORY_FULL(size); \
|
M_MEMORY_FULL(size); \
|
||||||
return; \
|
return; \
|
||||||
@@ -74,36 +75,37 @@
|
|||||||
mem->current_segment->count = 0; \
|
mem->current_segment->count = 0; \
|
||||||
MEMPOOLI_CONTRACT(mem, type); \
|
MEMPOOLI_CONTRACT(mem, type); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline void \
|
static inline void \
|
||||||
M_C3(mempool_,name,_clear)(M_C3(mempool_,name,_t) mem) \
|
M_C(name,_clear)(M_C(name,_t) mem) \
|
||||||
{ \
|
{ \
|
||||||
MEMPOOLI_CONTRACT(mem, type); \
|
MEMPOOLI_CONTRACT(mem, type); \
|
||||||
M_C3(mempool_,name,_segment_t) *segment = mem->current_segment; \
|
M_C(name,_segment_t) *segment = mem->current_segment; \
|
||||||
while (segment != NULL) { \
|
while (segment != NULL) { \
|
||||||
M_C3(mempool_,name,_segment_t) *next = segment->next; \
|
M_C(name,_segment_t) *next = segment->next; \
|
||||||
free(segment); \
|
free(segment); \
|
||||||
segment = next; \
|
segment = next; \
|
||||||
} \
|
} \
|
||||||
mem->free_list = NULL; \
|
mem->free_list = NULL; \
|
||||||
mem->current_segment = NULL; \
|
mem->current_segment = NULL; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline type * \
|
static inline type * \
|
||||||
M_C3(mempool_,name,_alloc)(M_C3(mempool_,name,_t) mem) \
|
M_C(name,_alloc)(M_C(name,_t) mem) \
|
||||||
{ \
|
{ \
|
||||||
MEMPOOLI_CONTRACT(mem, type); \
|
MEMPOOLI_CONTRACT(mem, type); \
|
||||||
M_C3(mempool_,name,_union_t) *ret = mem->free_list; \
|
M_C(name,_union_t) *ret = mem->free_list; \
|
||||||
if (ret != NULL) { \
|
if (ret != NULL) { \
|
||||||
mem->free_list = ret->next; \
|
mem->free_list = ret->next; \
|
||||||
return &ret->t; \
|
return &ret->t; \
|
||||||
} \
|
} \
|
||||||
M_C3(mempool_,name,_segment_t) *segment = mem->current_segment; \
|
M_C(name,_segment_t) *segment = mem->current_segment; \
|
||||||
assert(segment != NULL); \
|
assert(segment != NULL); \
|
||||||
unsigned int count = segment->count; \
|
unsigned int count = segment->count; \
|
||||||
if (count >= MEMPOOLI_MAX_PER_SEGMENT(type)) { \
|
if (count >= MEMPOOLI_MAX_PER_SEGMENT(type)) { \
|
||||||
const size_t s = sizeof (M_C3(mempool_,name,_segment_t)); \
|
const size_t s = sizeof (M_C(name,_segment_t)); \
|
||||||
M_C3(mempool_,name,_segment_t) *new_segment = M_ASSIGN_CAST(M_C3(mempool_,name,_segment_t)*, malloc (s)); \
|
M_C(name,_segment_t) *new_segment = M_ASSIGN_CAST(M_C(name,_segment_t)*, \
|
||||||
|
malloc (s)); \
|
||||||
if (new_segment == NULL) { \
|
if (new_segment == NULL) { \
|
||||||
M_MEMORY_FULL(s); \
|
M_MEMORY_FULL(s); \
|
||||||
return NULL; \
|
return NULL; \
|
||||||
@@ -119,14 +121,14 @@
|
|||||||
MEMPOOLI_CONTRACT(mem, type); \
|
MEMPOOLI_CONTRACT(mem, type); \
|
||||||
return &ret->t; \
|
return &ret->t; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline void \
|
static inline void \
|
||||||
M_C3(mempool_,name,_free)(M_C3(mempool_,name,_t) mem, type *ptr) \
|
M_C(name,_free)(M_C(name,_t) mem, type *ptr) \
|
||||||
{ \
|
{ \
|
||||||
MEMPOOLI_CONTRACT(mem, type); \
|
MEMPOOLI_CONTRACT(mem, type); \
|
||||||
/* NOTE: Unsafe cast: suppose that the given pointer \
|
/* NOTE: Unsafe cast: suppose that the given pointer \
|
||||||
was allocated by the previous alloc function. */ \
|
was allocated by the previous alloc function. */ \
|
||||||
M_C3(mempool_,name,_union_t) *ret = (M_C3(mempool_,name,_union_t) *)(uintptr_t)ptr; \
|
M_C(name,_union_t) *ret = (M_C(name,_union_t) *)(uintptr_t)ptr; \
|
||||||
ret->next = mem->free_list; \
|
ret->next = mem->free_list; \
|
||||||
mem->free_list = ret; \
|
mem->free_list = ret; \
|
||||||
MEMPOOLI_CONTRACT(mem, type); \
|
MEMPOOLI_CONTRACT(mem, type); \
|
||||||
|
|||||||
+1
-1
@@ -142,7 +142,7 @@ typedef enum {
|
|||||||
typedef type M_C3(rbtree_type_, name, _t); \
|
typedef type M_C3(rbtree_type_, name, _t); \
|
||||||
\
|
\
|
||||||
M_IF_METHOD(MEMPOOL, oplist)( \
|
M_IF_METHOD(MEMPOOL, oplist)( \
|
||||||
MEMPOOL_DEF(M_C(rbtree_,name), node_t) \
|
MEMPOOL_DEF(M_C(mempool_rbtree_,name), node_t) \
|
||||||
M_GET_MEMPOOL_LINKAGE oplist M_C3(mempool_rbtree_, name, _t) M_GET_MEMPOOL oplist; \
|
M_GET_MEMPOOL_LINKAGE oplist M_C3(mempool_rbtree_, name, _t) M_GET_MEMPOOL oplist; \
|
||||||
static inline node_t *M_C3(rbtreei_,name,_new)(void) { \
|
static inline node_t *M_C3(rbtreei_,name,_new)(void) { \
|
||||||
return M_C3(mempool_rbtree_, name, _alloc)(M_GET_MEMPOOL oplist); \
|
return M_C3(mempool_rbtree_, name, _alloc)(M_GET_MEMPOOL oplist); \
|
||||||
|
|||||||
@@ -28,7 +28,7 @@
|
|||||||
|
|
||||||
#include "coverage.h"
|
#include "coverage.h"
|
||||||
START_COVERAGE
|
START_COVERAGE
|
||||||
MEMPOOL_DEF(uint, unsigned int)
|
MEMPOOL_DEF(mempool_uint, unsigned int)
|
||||||
END_COVERAGE
|
END_COVERAGE
|
||||||
|
|
||||||
static void test(void)
|
static void test(void)
|
||||||
|
|||||||
Reference in new issue
Block a user