Move generating macro into the m_ namespace and create a wrapper using historical names for compatibility with existing code

This commit is contained in:
Patrick Pelissier committed 2022-03-24 20:46:49 +01:00
1 parent fc26e472ab
commit b8cd679679
20 files changed
+379 -214

No files matched your search

+16 -6
View File
@@ -31,7 +31,7 @@
which oplist is 'contOp', as static inline functions. which oplist is 'contOp', as static inline functions.
USAGE: USAGE:
ALGO_DEF(algogName, containerOplist|type if oplist has been registered) */ ALGO_DEF(algogName, containerOplist|type if oplist has been registered) */
#define ALGO_DEF(name, cont_oplist) \ #define M_ALGO_DEF(name, cont_oplist) \
M_BEGIN_PROTECTED_CODE \ M_BEGIN_PROTECTED_CODE \
M_ALG0_DEF_P1(name, M_GLOBAL_OPLIST(cont_oplist)) \ M_ALG0_DEF_P1(name, M_GLOBAL_OPLIST(cont_oplist)) \
M_END_PROTECTED_CODE M_END_PROTECTED_CODE
@@ -40,7 +40,7 @@
/* Map a function (or a macro) to all elements of a container. /* Map a function (or a macro) to all elements of a container.
USAGE: USAGE:
ALGO_FOR_EACH(container, containerOplist, function[, extra arguments of function]) */ ALGO_FOR_EACH(container, containerOplist, function[, extra arguments of function]) */
#define ALGO_FOR_EACH(container, cont_oplist, ...) \ #define M_ALGO_FOR_EACH(container, cont_oplist, ...) \
M_IF_NARGS_EQ1(__VA_ARGS__) \ M_IF_NARGS_EQ1(__VA_ARGS__) \
(M_ALG0_FOR_EACH(container, M_GLOBAL_OPLIST(cont_oplist), __VA_ARGS__), \ (M_ALG0_FOR_EACH(container, M_GLOBAL_OPLIST(cont_oplist), __VA_ARGS__), \
M_ALG0_FOR_EACH_ARG(container, M_GLOBAL_OPLIST(cont_oplist), __VA_ARGS__ )) M_ALG0_FOR_EACH_ARG(container, M_GLOBAL_OPLIST(cont_oplist), __VA_ARGS__ ))
@@ -51,7 +51,7 @@
USAGE: USAGE:
ALGO_TRANSFORM(contDst, contDOplist, contSrc, contSrcOplist, ALGO_TRANSFORM(contDst, contDOplist, contSrc, contSrcOplist,
function[, extra arguments of function]) */ function[, extra arguments of function]) */
#define ALGO_TRANSFORM(contD, contDop, contS, contSop, ...) \ #define M_ALGO_TRANSFORM(contD, contDop, contS, contSop, ...) \
M_IF_NARGS_EQ1(__VA_ARGS__) \ M_IF_NARGS_EQ1(__VA_ARGS__) \
(M_ALG0_TRANSFORM(contD, M_GLOBAL_OPLIST(contDop), contS, M_GLOBAL_OPLIST(contSop), __VA_ARGS__), \ (M_ALG0_TRANSFORM(contD, M_GLOBAL_OPLIST(contDop), contS, M_GLOBAL_OPLIST(contSop), __VA_ARGS__), \
M_ALG0_TRANSFORM_ARG(contD, M_GLOBAL_OPLIST(contDop), contS, M_GLOBAL_OPLIST(contSop), __VA_ARGS__ )) M_ALG0_TRANSFORM_ARG(contD, M_GLOBAL_OPLIST(contDop), contS, M_GLOBAL_OPLIST(contSop), __VA_ARGS__ ))
@@ -61,7 +61,7 @@
USAGE: USAGE:
ALGO_EXTRACT(contDst, contDstOplist, contSrc, contSrcOplist ALGO_EXTRACT(contDst, contDstOplist, contSrc, contSrcOplist
[, function [, extra arguments of function]]) */ [, function [, extra arguments of function]]) */
#define ALGO_EXTRACT(contD, contDop, contS, ...) \ #define M_ALGO_EXTRACT(contD, contDop, contS, ...) \
M_IF_NARGS_EQ1(__VA_ARGS__) \ M_IF_NARGS_EQ1(__VA_ARGS__) \
(M_ALG0_EXTRACT(contD, M_GLOBAL_OPLIST(contDop), M_GLOBAL_OPLIST(contS), __VA_ARGS__), \ (M_ALG0_EXTRACT(contD, M_GLOBAL_OPLIST(contDop), M_GLOBAL_OPLIST(contS), __VA_ARGS__), \
M_IF_NARGS_EQ2(__VA_ARGS__) \ M_IF_NARGS_EQ2(__VA_ARGS__) \
@@ -73,7 +73,7 @@
USAGE: USAGE:
ALGO_REDUCE(dstVar, container, contOplist, reduceFunc ALGO_REDUCE(dstVar, container, contOplist, reduceFunc
[, mapFunc[, extraParameters of map function]]) */ [, mapFunc[, extraParameters of map function]]) */
#define ALGO_REDUCE(dest, cont, contOp, ...) \ #define M_ALGO_REDUCE(dest, cont, contOp, ...) \
M_IF(M_PARENTHESIS_P(dest)) \ M_IF(M_PARENTHESIS_P(dest)) \
(M_ALG0_REDUCE_DISPATCH(M_PAIR_1 dest, M_GLOBAL_OPLIST(M_PAIR_2 dest), M_GLOBAL_TYPE(M_PAIR_2 dest),cont, M_GLOBAL_OPLIST(contOp), __VA_ARGS__), \ (M_ALG0_REDUCE_DISPATCH(M_PAIR_1 dest, M_GLOBAL_OPLIST(M_PAIR_2 dest), M_GLOBAL_TYPE(M_PAIR_2 dest),cont, M_GLOBAL_OPLIST(contOp), __VA_ARGS__), \
M_ALG0_REDUCE_DISPATCH(dest, M_GET_OPLIST M_GLOBAL_OPLIST(contOp), M_GET_SUBTYPE M_GLOBAL_OPLIST(contOp), cont, contOp, __VA_ARGS__)) \ M_ALG0_REDUCE_DISPATCH(dest, M_GET_OPLIST M_GLOBAL_OPLIST(contOp), M_GET_SUBTYPE M_GLOBAL_OPLIST(contOp), cont, contOp, __VA_ARGS__)) \
@@ -84,7 +84,7 @@
USAGE: USAGE:
ALGO_INSERT_AT(containerDst, containerDstOPLIST|containerDstType, containerDstIterator, containerSrc, containerSrcOPLIST|containerSrcType) ALGO_INSERT_AT(containerDst, containerDstOPLIST|containerDstType, containerDstIterator, containerSrc, containerSrcOPLIST|containerSrcType)
*/ */
#define ALGO_INSERT_AT(contDst, contDstOp, position, contSrc, contSrcOp) \ #define M_ALGO_INSERT_AT(contDst, contDstOp, position, contSrc, contSrcOp) \
M_ALG0_INSERT_AT(contDst, M_GLOBAL_OPLIST(contDstOp), position, contSrc, M_GLOBAL_OPLIST(contSrcOp) ) M_ALG0_INSERT_AT(contDst, M_GLOBAL_OPLIST(contDstOp), position, contSrc, M_GLOBAL_OPLIST(contSrcOp) )
@@ -1200,4 +1200,14 @@
} \ } \
} while (0) } while (0)
#if M_USE_SMALL_NAME
#define ALGO_DEF M_ALGO_DEF
#define ALGO_FOR_EACH M_ALGO_FOR_EACH
#define ALGO_TRANSFORM M_ALGO_TRANSFORM
#define ALGO_EXTRACT M_ALGO_EXTRACT
#define ALGO_REDUCE M_ALGO_REDUCE
#define ALGO_INSERT_AT M_ALGO_INSERT_AT
#endif
#endif #endif
+12 -5
View File
@@ -29,14 +29,14 @@
/* Define a dynamic array of the given type and its associated functions. /* Define a dynamic array of the given type and its associated functions.
USAGE: ARRAY_DEF(name, type [, oplist_of_the_type]) */ USAGE: ARRAY_DEF(name, type [, oplist_of_the_type]) */
#define ARRAY_DEF(name, ...) \ #define M_ARRAY_DEF(name, ...) \
ARRAY_DEF_AS(name, M_C(name,_t), M_C(name,_it_t), __VA_ARGS__) M_ARRAY_DEF_AS(name, M_C(name,_t), M_C(name,_it_t), __VA_ARGS__)
/* Define a dynamic array of the given type and its associated functions /* Define a dynamic array of the given type and its associated functions
as the provided type name_t with the iterator named it_t as the provided type name_t with the iterator named it_t
USAGE: ARRAY_DEF_AS(name, name_t, it_t, type [, oplist_of_the_type]) */ USAGE: ARRAY_DEF_AS(name, name_t, it_t, type [, oplist_of_the_type]) */
#define ARRAY_DEF_AS(name, name_t, it_t, ...) \ #define M_ARRAY_DEF_AS(name, name_t, it_t, ...) \
M_BEGIN_PROTECTED_CODE \ M_BEGIN_PROTECTED_CODE \
M_ARRA4_DEF_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \ M_ARRA4_DEF_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \
((name, __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), name_t, it_t ), \ ((name, __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), name_t, it_t ), \
@@ -47,7 +47,7 @@
/* Define the oplist of a dynamic array given its name and its oplist. /* Define the oplist of a dynamic array given its name and its oplist.
If no oplist is given it is assumed to be M_DEFAULT_OPLIST If no oplist is given it is assumed to be M_DEFAULT_OPLIST
USAGE: ARRAY_OPLIST(name[, oplist of the type]) */ USAGE: ARRAY_OPLIST(name[, oplist of the type]) */
#define ARRAY_OPLIST(...) \ #define M_ARRAY_OPLIST(...) \
M_ARRA4_OPLIST_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \ M_ARRA4_OPLIST_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \
((__VA_ARGS__, M_DEFAULT_OPLIST), \ ((__VA_ARGS__, M_DEFAULT_OPLIST), \
(__VA_ARGS__ ))) (__VA_ARGS__ )))
@@ -57,7 +57,7 @@
USAGE: USAGE:
array_t global_variable = ARRAY_INIT_VALUE(); array_t global_variable = ARRAY_INIT_VALUE();
*/ */
#define ARRAY_INIT_VALUE() \ #define M_ARRAY_INIT_VALUE() \
{ { 0, 0, NULL } } { { 0, 0, NULL } }
/********************************************************************************/ /********************************************************************************/
@@ -1095,4 +1095,11 @@
} \ } \
} \ } \
#if M_USE_SMALL_NAME
#define ARRAY_DEF M_ARRAY_DEF
#define ARRAY_DEF_AS M_ARRAY_DEF_AS
#define ARRAY_OPLIST M_ARRAY_OPLIST
#define ARRAY_INIT_VALUE M_ARRAY_INIT_VALUE
#endif
#endif #endif
+28 -15
View File
@@ -34,8 +34,8 @@
OR OR
BPTREE_DEF2(name, N, key_t, value_t) BPTREE_DEF2(name, N, key_t, value_t)
*/ */
#define BPTREE_DEF2(name, N, key_type, ...) \ #define M_BPTREE_DEF2(name, N, key_type, ...) \
BPTREE_DEF2_AS(name, M_C(name,_t), M_C(name,_it_t), M_C(name, _itref_t), N, key_type, __VA_ARGS__) M_BPTREE_DEF2_AS(name, M_C(name,_t), M_C(name,_it_t), M_C(name, _itref_t), N, key_type, __VA_ARGS__)
/* Define a B+tree of size 'N' that maps a 'key' to a 'value' /* Define a B+tree of size 'N' that maps a 'key' to a 'value'
@@ -45,7 +45,7 @@
OR OR
BPTREE_DEF2_AS(name, name_t, it_t, itref_t, N, key_t, value_t) BPTREE_DEF2_AS(name, name_t, it_t, itref_t, N, key_t, value_t)
*/ */
#define BPTREE_DEF2_AS(name, name_t, it_t, itref_t, N, key_type, ...) \ #define M_BPTREE_DEF2_AS(name, name_t, it_t, itref_t, N, key_type, ...) \
M_BEGIN_PROTECTED_CODE \ M_BEGIN_PROTECTED_CODE \
M_BPTR33_DEF_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \ M_BPTR33_DEF_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \
((name, N, key_type, M_GLOBAL_OPLIST_OR_DEF(key_type)(), __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), 1, 0, name_t, M_C(name, _node_ct), M_C(name, _pit_ct), it_t, itref_t ), \ ((name, N, key_type, M_GLOBAL_OPLIST_OR_DEF(key_type)(), __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), 1, 0, name_t, M_C(name, _node_ct), M_C(name, _pit_ct), it_t, itref_t ), \
@@ -56,14 +56,14 @@
/* Define a B+tree of a given type, of size N. /* Define a B+tree of a given type, of size N.
with its associated functions with its associated functions
USAGE: BPTREE_DEF(name, N, type, [, oplist_of_the_type]) */ USAGE: BPTREE_DEF(name, N, type, [, oplist_of_the_type]) */
#define BPTREE_DEF(name, N, ...) \ #define M_BPTREE_DEF(name, N, ...) \
BPTREE_DEF_AS(name, M_C(name,_t), M_C(name,_it_t), N, __VA_ARGS__) M_BPTREE_DEF_AS(name, M_C(name,_t), M_C(name,_it_t), N, __VA_ARGS__)
/* Define a B+tree of a given type, of size N. /* Define a B+tree of a given type, of size N.
as the given name name_t with its associated functions as the given name name_t with its associated functions
USAGE: BPTREE_DEF_AS(name, name_t, it_t, N, type, [, oplist_of_the_type]) */ USAGE: BPTREE_DEF_AS(name, name_t, it_t, N, type, [, oplist_of_the_type]) */
#define BPTREE_DEF_AS(name, name_t, it_t, N, ...) \ #define M_BPTREE_DEF_AS(name, name_t, it_t, N, ...) \
M_BEGIN_PROTECTED_CODE \ M_BEGIN_PROTECTED_CODE \
M_BPTR33_DEF_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \ M_BPTR33_DEF_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \
((name, N, __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), 0, 0, name_t, M_C(name, _node_ct), M_C(name, _pit_ct), it_t, M_C(name, _itref_ct) ), \ ((name, N, __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), 0, 0, name_t, M_C(name, _node_ct), M_C(name, _pit_ct), it_t, M_C(name, _itref_ct) ), \
@@ -79,8 +79,8 @@
OR OR
BPTREE_MULTI_DEF2(name, N, key_t, value_t) BPTREE_MULTI_DEF2(name, N, key_t, value_t)
*/ */
#define BPTREE_MULTI_DEF2(name, N, key_type, ...) \ #define M_BPTREE_MULTI_DEF2(name, N, key_type, ...) \
BPTREE_MULTI_DEF2_AS(name, M_C(name,_t), M_C(name,_it_t), M_C(name,_itref_t), N, key_type, __VA_ARGS__) M_BPTREE_MULTI_DEF2_AS(name, M_C(name,_t), M_C(name,_it_t), M_C(name,_itref_t), N, key_type, __VA_ARGS__)
/* Define a B+tree of size 'N' that maps a 'key' to a 'value', /* Define a B+tree of size 'N' that maps a 'key' to a 'value',
@@ -91,7 +91,7 @@
OR OR
BPTREE_MULTI_DEF2_AS(name, name_t, it_t, itref_t, N, key_t, value_t) BPTREE_MULTI_DEF2_AS(name, name_t, it_t, itref_t, N, key_t, value_t)
*/ */
#define BPTREE_MULTI_DEF2_AS(name, name_t, it_t, itref_t, N, key_type, ...) \ #define M_BPTREE_MULTI_DEF2_AS(name, name_t, it_t, itref_t, N, key_type, ...) \
M_BEGIN_PROTECTED_CODE \ M_BEGIN_PROTECTED_CODE \
M_BPTR33_DEF_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \ M_BPTR33_DEF_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \
((name, N, key_type, M_GLOBAL_OPLIST_OR_DEF(key_type)(), __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), 1, 1, name_t, M_C(name, _node_ct), M_C(name, _pit_ct), it_t, itref_t ), \ ((name, N, key_type, M_GLOBAL_OPLIST_OR_DEF(key_type)(), __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), 1, 1, name_t, M_C(name, _node_ct), M_C(name, _pit_ct), it_t, itref_t ), \
@@ -103,15 +103,15 @@
allowing multiple equal keys to exist, allowing multiple equal keys to exist,
with its associated functions with its associated functions
USAGE: BPTREE_MULTI_DEF(name, N, type, [, oplist_of_the_type]) */ USAGE: BPTREE_MULTI_DEF(name, N, type, [, oplist_of_the_type]) */
#define BPTREE_MULTI_DEF(name, N, ...) \ #define M_BPTREE_MULTI_DEF(name, N, ...) \
BPTREE_MULTI_DEF_AS(name, M_C(name,_t), M_C(name,_it_t), N, __VA_ARGS__) M_BPTREE_MULTI_DEF_AS(name, M_C(name,_t), M_C(name,_it_t), N, __VA_ARGS__)
/* Define a B+tree of a given type, of size N. /* Define a B+tree of a given type, of size N.
allowing multiple equal keys to exist, allowing multiple equal keys to exist,
as the given name name_t with its associated functions as the given name name_t with its associated functions
USAGE: BPTREE_MULTI_DEF_AS(name, name_t, it_t, N, type, [, oplist_of_the_type]) */ USAGE: BPTREE_MULTI_DEF_AS(name, name_t, it_t, N, type, [, oplist_of_the_type]) */
#define BPTREE_MULTI_DEF_AS(name, name_t, it_t, N, ...) \ #define M_BPTREE_MULTI_DEF_AS(name, name_t, it_t, N, ...) \
M_BEGIN_PROTECTED_CODE \ M_BEGIN_PROTECTED_CODE \
M_BPTR33_DEF_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \ M_BPTR33_DEF_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \
((name, N, __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), 0, 1, name_t, M_C(name, _node_ct), M_C(name, _pit_ct), it_t, M_C(name, _itref_ct) ), \ ((name, N, __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), 0, 1, name_t, M_C(name, _node_ct), M_C(name, _pit_ct), it_t, M_C(name, _itref_ct) ), \
@@ -121,7 +121,7 @@
/* Define the oplist of a B+TREE used as a set of type (from BPTREE_DEF). /* Define the oplist of a B+TREE used as a set of type (from BPTREE_DEF).
USAGE: BPTREE_OPLIST(name [, oplist_of_the_type]) */ USAGE: BPTREE_OPLIST(name [, oplist_of_the_type]) */
#define BPTREE_OPLIST(...) \ #define M_BPTREE_OPLIST(...) \
M_BPTR33_KEY_OPLIST_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \ M_BPTR33_KEY_OPLIST_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \
((__VA_ARGS__, M_DEFAULT_OPLIST ), \ ((__VA_ARGS__, M_DEFAULT_OPLIST ), \
(__VA_ARGS__ ))) (__VA_ARGS__ )))
@@ -132,7 +132,7 @@
NOTE: IT_REF is not exported so that the contained appears as not modifiable NOTE: IT_REF is not exported so that the contained appears as not modifiable
by algorithm. by algorithm.
*/ */
#define BPTREE_OPLIST2(...) \ #define M_BPTREE_OPLIST2(...) \
M_BPTR33_OPLIST2_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \ M_BPTR33_OPLIST2_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \
((__VA_ARGS__, M_DEFAULT_OPLIST, M_DEFAULT_OPLIST ), \ ((__VA_ARGS__, M_DEFAULT_OPLIST, M_DEFAULT_OPLIST ), \
(__VA_ARGS__ ))) (__VA_ARGS__ )))
@@ -1467,6 +1467,19 @@
return ret; \ return ret; \
} \ } \
, /* no in_serial */ ) \ , /* no in_serial */ ) \
\
#if M_USE_SMALL_NAME
#define BPTREE_DEF2 M_BPTREE_DEF2
#define BPTREE_DEF2_AS M_BPTREE_DEF2_AS
#define BPTREE_DEF M_BPTREE_DEF
#define BPTREE_DEF_AS M_BPTREE_DEF_AS
#define BPTREE_MULTI_DEF2 M_BPTREE_MULTI_DEF2
#define BPTREE_MULTI_DEF2_AS M_BPTREE_MULTI_DEF2_AS
#define BPTREE_MULTI_DEF M_BPTREE_MULTI_DEF
#define BPTREE_MULTI_DEF_AS M_BPTREE_MULTI_DEF_AS
#define BPTREE_OPLIST M_BPTREE_OPLIST
#define BPTREE_OPLIST2 M_BPTREE_OPLIST2
#endif
#endif #endif
+112 -87
View File
@@ -40,29 +40,29 @@
* - if the pop of an element is not complete until the call to pop_release (preventing push until this call). * - if the pop of an element is not complete until the call to pop_release (preventing push until this call).
*/ */
typedef enum { typedef enum {
BUFFER_QUEUE = 0, BUFFER_STACK = 1, M_BUFFER_QUEUE = 0, M_BUFFER_STACK = 1,
BUFFER_BLOCKING_PUSH = 0, BUFFER_UNBLOCKING_PUSH = 2, M_BUFFER_BLOCKING_PUSH = 0, M_BUFFER_UNBLOCKING_PUSH = 2,
BUFFER_BLOCKING_POP = 0, BUFFER_UNBLOCKING_POP = 4, M_BUFFER_BLOCKING_POP = 0, M_BUFFER_UNBLOCKING_POP = 4,
BUFFER_BLOCKING = 0, BUFFER_UNBLOCKING = 6, M_BUFFER_BLOCKING = 0, M_BUFFER_UNBLOCKING = 6,
BUFFER_THREAD_SAFE = 0, BUFFER_THREAD_UNSAFE = 8, M_BUFFER_THREAD_SAFE = 0, M_BUFFER_THREAD_UNSAFE = 8,
BUFFER_PUSH_INIT_POP_MOVE = 16, M_BUFFER_PUSH_INIT_POP_MOVE = 16,
BUFFER_PUSH_OVERWRITE = 32, M_BUFFER_PUSH_OVERWRITE = 32,
BUFFER_DEFERRED_POP = 64 M_BUFFER_DEFERRED_POP = 64
} buffer_policy_e; } m_buffer_policy_e;
/* Define a lock based buffer. /* Define a lock based buffer.
If size is 0, then the size will only be defined at run-time when initializing the buffer, If size is 0, then the size will only be defined at run-time when initializing the buffer,
otherwise the size will be a compile time constant. otherwise the size will be a compile time constant.
USAGE: BUFFER_DEF(name, type, size_of_buffer_or_0, policy[, oplist]) */ USAGE: BUFFER_DEF(name, type, size_of_buffer_or_0, policy[, oplist]) */
#define BUFFER_DEF(name, type, m_size, ... ) \ #define M_BUFFER_DEF(name, type, m_size, ... ) \
BUFFER_DEF_AS(name, M_C(name, _t), type, m_size, __VA_ARGS__) M_BUFFER_DEF_AS(name, M_C(name, _t), type, m_size, __VA_ARGS__)
/* Define a lock based buffer /* Define a lock based buffer
as the provided type name_t. as the provided type name_t.
USAGE: BUFFER_DEF_AS(name, name_t, type, size_of_buffer_or_0, policy[, oplist of type]) */ USAGE: BUFFER_DEF_AS(name, name_t, type, size_of_buffer_or_0, policy[, oplist of type]) */
#define BUFFER_DEF_AS(name, name_t, type, m_size, ... ) \ #define M_BUFFER_DEF_AS(name, name_t, type, m_size, ... ) \
M_BEGIN_PROTECTED_CODE \ M_BEGIN_PROTECTED_CODE \
M_BUFF3R_DEF_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \ M_BUFF3R_DEF_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \
((name, type, m_size,__VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(type)(), name_t ), \ ((name, type, m_size,__VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(type)(), name_t ), \
@@ -72,7 +72,7 @@ typedef enum {
/* Define the oplist of a lock based buffer given its name and its oplist. /* Define the oplist of a lock based buffer given its name and its oplist.
USAGE: BUFFER_OPLIST(name[, oplist of the type]) */ USAGE: BUFFER_OPLIST(name[, oplist of the type]) */
#define BUFFER_OPLIST(...) \ #define M_BUFFER_OPLIST(...) \
M_BUFF3R_OPLIST_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \ M_BUFF3R_OPLIST_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \
((__VA_ARGS__, M_DEFAULT_OPLIST), \ ((__VA_ARGS__, M_DEFAULT_OPLIST), \
(__VA_ARGS__ ))) (__VA_ARGS__ )))
@@ -84,8 +84,8 @@ typedef enum {
Size of created queue shall be a power of 2 and is defined at run-time. Size of created queue shall be a power of 2 and is defined at run-time.
USAGE: QUEUE_MPMC_DEF(name, type, policy, [oplist of type]) USAGE: QUEUE_MPMC_DEF(name, type, policy, [oplist of type])
*/ */
#define QUEUE_MPMC_DEF(name, type, ...) \ #define M_QUEUE_MPMC_DEF(name, type, ...) \
QUEUE_MPMC_DEF_AS(name, M_C(name,_t), type, __VA_ARGS__) M_QUEUE_MPMC_DEF_AS(name, M_C(name,_t), type, __VA_ARGS__)
/* Define a nearly lock-free queue for Many Producer Many Consummer /* Define a nearly lock-free queue for Many Producer Many Consummer
@@ -95,7 +95,7 @@ typedef enum {
Size of created queue shall be a power of 2 and is defined at run-time. Size of created queue shall be a power of 2 and is defined at run-time.
USAGE: QUEUE_MPMC_DEF_AS(name, name_t, type, policy, [oplist of type]) USAGE: QUEUE_MPMC_DEF_AS(name, name_t, type, policy, [oplist of type])
*/ */
#define QUEUE_MPMC_DEF_AS(name, name_t, type, ...) \ #define M_QUEUE_MPMC_DEF_AS(name, name_t, type, ...) \
M_BEGIN_PROTECTED_CODE \ M_BEGIN_PROTECTED_CODE \
M_QU3UE_MPMC_DEF_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \ M_QU3UE_MPMC_DEF_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \
((name, type, __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(type)(), name_t ), \ ((name, type, __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(type)(), name_t ), \
@@ -109,8 +109,8 @@ typedef enum {
Size of created queue shall be a power of 2 and is defined at run-time. Size of created queue shall be a power of 2 and is defined at run-time.
USAGE: QUEUE_SPSC_DEF(name, type, policy, [oplist of type]) USAGE: QUEUE_SPSC_DEF(name, type, policy, [oplist of type])
*/ */
#define QUEUE_SPSC_DEF(name, type, ...) \ #define M_QUEUE_SPSC_DEF(name, type, ...) \
QUEUE_SPSC_DEF_AS(name, M_C(name, _t), type, __VA_ARGS__) M_QUEUE_SPSC_DEF_AS(name, M_C(name, _t), type, __VA_ARGS__)
/* Define a wait-free queue for Single Producer Single Consummer /* Define a wait-free queue for Single Producer Single Consummer
@@ -120,7 +120,7 @@ typedef enum {
Size of created queue shall be a power of 2 and is defined at run-time. Size of created queue shall be a power of 2 and is defined at run-time.
USAGE: QUEUE_SPSC_DEF_AS(name, name_t, type, policy, [oplist of type]) USAGE: QUEUE_SPSC_DEF_AS(name, name_t, type, policy, [oplist of type])
*/ */
#define QUEUE_SPSC_DEF_AS(name, name_t, type, ...) \ #define M_QUEUE_SPSC_DEF_AS(name, name_t, type, ...) \
M_BEGIN_PROTECTED_CODE \ M_BEGIN_PROTECTED_CODE \
M_QU3UE_SPSC_DEF_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \ M_QU3UE_SPSC_DEF_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \
((name, type, __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(type)(), name_t ), \ ((name, type, __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(type)(), name_t ), \
@@ -155,7 +155,7 @@ typedef union m_buff3r_number_s {
static inline void static inline void
m_buff3r_number_init(m_buff3r_number_ct n, unsigned int policy) m_buff3r_number_init(m_buff3r_number_ct n, unsigned int policy)
{ {
if (!M_BUFF3R_POLICY_P(policy, BUFFER_THREAD_UNSAFE)) if (!M_BUFF3R_POLICY_P(policy, M_BUFFER_THREAD_UNSAFE))
atomic_init(&n->a, 0U); atomic_init(&n->a, 0U);
else else
n->u = 0UL; n->u = 0UL;
@@ -164,7 +164,7 @@ m_buff3r_number_init(m_buff3r_number_ct n, unsigned int policy)
static inline unsigned int static inline unsigned int
m_buff3r_number_load(m_buff3r_number_ct n, unsigned int policy) m_buff3r_number_load(m_buff3r_number_ct n, unsigned int policy)
{ {
if (!M_BUFF3R_POLICY_P(policy, BUFFER_THREAD_UNSAFE)) if (!M_BUFF3R_POLICY_P(policy, M_BUFFER_THREAD_UNSAFE))
// Perform a memory acquire so that further usage of the buffer // Perform a memory acquire so that further usage of the buffer
// is synchronized. // is synchronized.
return atomic_load_explicit(&n->a, memory_order_acquire); return atomic_load_explicit(&n->a, memory_order_acquire);
@@ -175,7 +175,7 @@ m_buff3r_number_load(m_buff3r_number_ct n, unsigned int policy)
static inline void static inline void
m_buff3r_number_store(m_buff3r_number_ct n, unsigned int v, unsigned int policy) m_buff3r_number_store(m_buff3r_number_ct n, unsigned int v, unsigned int policy)
{ {
if (!M_BUFF3R_POLICY_P(policy, BUFFER_THREAD_UNSAFE)) if (!M_BUFF3R_POLICY_P(policy, M_BUFFER_THREAD_UNSAFE))
// This function is used in context where a relaxed access is sufficient. // This function is used in context where a relaxed access is sufficient.
atomic_store_explicit(&n->a, v, memory_order_relaxed); atomic_store_explicit(&n->a, v, memory_order_relaxed);
else else
@@ -185,7 +185,7 @@ m_buff3r_number_store(m_buff3r_number_ct n, unsigned int v, unsigned int policy)
static inline void static inline void
m_buff3r_number_set(m_buff3r_number_ct n, m_buff3r_number_ct v, unsigned int policy) m_buff3r_number_set(m_buff3r_number_ct n, m_buff3r_number_ct v, unsigned int policy)
{ {
if (!M_BUFF3R_POLICY_P(policy, BUFFER_THREAD_UNSAFE)) if (!M_BUFF3R_POLICY_P(policy, M_BUFFER_THREAD_UNSAFE))
// This function is used in context where a relaxed access is sufficient. // This function is used in context where a relaxed access is sufficient.
atomic_store_explicit(&n->a, atomic_load_explicit(&v->a, memory_order_relaxed), memory_order_relaxed); atomic_store_explicit(&n->a, atomic_load_explicit(&v->a, memory_order_relaxed), memory_order_relaxed);
else else
@@ -195,7 +195,7 @@ m_buff3r_number_set(m_buff3r_number_ct n, m_buff3r_number_ct v, unsigned int pol
static inline unsigned int static inline unsigned int
m_buff3r_number_inc(m_buff3r_number_ct n, unsigned int policy) m_buff3r_number_inc(m_buff3r_number_ct n, unsigned int policy)
{ {
if (!M_BUFF3R_POLICY_P(policy, BUFFER_THREAD_UNSAFE)) if (!M_BUFF3R_POLICY_P(policy, M_BUFFER_THREAD_UNSAFE))
return atomic_fetch_add(&n->a, 1U); return atomic_fetch_add(&n->a, 1U);
else else
return n->u ++; return n->u ++;
@@ -204,7 +204,7 @@ m_buff3r_number_inc(m_buff3r_number_ct n, unsigned int policy)
static inline unsigned int static inline unsigned int
m_buff3r_number_dec(m_buff3r_number_ct n, unsigned int policy) m_buff3r_number_dec(m_buff3r_number_ct n, unsigned int policy)
{ {
if (!M_BUFF3R_POLICY_P(policy, BUFFER_THREAD_UNSAFE)) if (!M_BUFF3R_POLICY_P(policy, M_BUFFER_THREAD_UNSAFE))
return atomic_fetch_sub(&n->a, 1U); return atomic_fetch_sub(&n->a, 1U);
else else
return n->u --; return n->u --;
@@ -243,7 +243,7 @@ m_buff3r_number_dec(m_buff3r_number_ct n, unsigned int policy)
/* Stop processing with a compilation failure */ /* Stop processing with a compilation failure */
#define M_BUFF3R_DEF_FAILURE(name, type, m_size, policy, oplist, buffer_t) \ #define M_BUFF3R_DEF_FAILURE(name, type, m_size, policy, oplist, buffer_t) \
M_STATIC_FAILURE(M_LIB_NOT_AN_OPLIST, "(BUFFER_DEF): the given argument is not a valid oplist: " M_AS_STR(oplist)) M_STATIC_FAILURE(M_LIB_NOT_AN_OPLIST, "(M_BUFFER_DEF): the given argument is not a valid oplist: " M_AS_STR(oplist))
/* Define the buffer type using mutex lock and its functions. /* Define the buffer type using mutex lock and its functions.
- name: main prefix of the container - name: main prefix of the container
@@ -259,7 +259,7 @@ m_buff3r_number_dec(m_buff3r_number_ct n, unsigned int policy)
by multiple writing threads. No need to align if there is no thread */ \ by multiple writing threads. No need to align if there is no thread */ \
typedef union M_C(name, _el_s) { \ typedef union M_C(name, _el_s) { \
type x; \ type x; \
char align[M_BUFF3R_POLICY_P(policy, BUFFER_THREAD_UNSAFE) ? 1 : M_ALIGN_FOR_CACHELINE_EXCLUSION]; \ char align[M_BUFF3R_POLICY_P(policy, M_BUFFER_THREAD_UNSAFE) ? 1 : M_ALIGN_FOR_CACHELINE_EXCLUSION]; \
} M_C(name, _el_ct); \ } M_C(name, _el_ct); \
\ \
typedef struct M_C(name, _s) { \ typedef struct M_C(name, _s) { \
@@ -276,7 +276,7 @@ m_buff3r_number_dec(m_buff3r_number_ct n, unsigned int policy)
size_t idx_cons; /* Index of the consumption threads */ \ size_t idx_cons; /* Index of the consumption threads */ \
/* number[0] := Number of elements in the buffer */ \ /* number[0] := Number of elements in the buffer */ \
/* number[1] := [OPTION] Number of elements being deferred in the buffer */ \ /* number[1] := [OPTION] Number of elements being deferred in the buffer */ \
m_buff3r_number_ct number[1 + M_BUFF3R_POLICY_P(policy, BUFFER_DEFERRED_POP)]; \ m_buff3r_number_ct number[1 + M_BUFF3R_POLICY_P(policy, M_BUFFER_DEFERRED_POP)]; \
/* If fixed size, array of elements, otherwise pointer to element */ \ /* If fixed size, array of elements, otherwise pointer to element */ \
M_C(name, _el_ct) M_BUFF3R_IF_CTE_SIZE(m_size)(data[m_size], *data); \ M_C(name, _el_ct) M_BUFF3R_IF_CTE_SIZE(m_size)(data[m_size], *data); \
} buffer_t[1]; \ } buffer_t[1]; \
@@ -298,15 +298,15 @@ M_C(name, _init)(buffer_t v, size_t size) \
M_ASSERT(size <= UINT_MAX); \ M_ASSERT(size <= UINT_MAX); \
v->idx_prod = v->idx_cons = v->overwrite = 0; \ v->idx_prod = v->idx_cons = v->overwrite = 0; \
m_buff3r_number_init (v->number[0], policy); \ m_buff3r_number_init (v->number[0], policy); \
if (M_BUFF3R_POLICY_P(policy, BUFFER_DEFERRED_POP)) \ if (M_BUFF3R_POLICY_P(policy, M_BUFFER_DEFERRED_POP)) \
m_buff3r_number_init (v->number[1], policy); \ m_buff3r_number_init (v->number[1], policy); \
if (!M_BUFF3R_POLICY_P((policy), BUFFER_THREAD_UNSAFE)) { \ if (!M_BUFF3R_POLICY_P((policy), M_BUFFER_THREAD_UNSAFE)) { \
m_mutex_init(v->mutexPush); \ m_mutex_init(v->mutexPush); \
m_mutex_init(v->mutexPop); \ m_mutex_init(v->mutexPop); \
m_cond_init(v->there_is_data); \ m_cond_init(v->there_is_data); \
m_cond_init(v->there_is_room_for_data); \ m_cond_init(v->there_is_room_for_data); \
} else { \ } else { \
M_ASSERT(M_BUFF3R_POLICY_P((policy), BUFFER_UNBLOCKING)); \ M_ASSERT(M_BUFF3R_POLICY_P((policy), M_BUFFER_UNBLOCKING)); \
} \ } \
\ \
M_BUFF3R_IF_CTE_SIZE(m_size)( /* Statically allocated */ , \ M_BUFF3R_IF_CTE_SIZE(m_size)( /* Statically allocated */ , \
@@ -316,7 +316,7 @@ M_C(name, _init)(buffer_t v, size_t size) \
return; \ return; \
} \ } \
) \ ) \
if (!M_BUFF3R_POLICY_P((policy), BUFFER_PUSH_INIT_POP_MOVE)) { \ if (!M_BUFF3R_POLICY_P((policy), M_BUFFER_PUSH_INIT_POP_MOVE)) { \
for(size_t i = 0; i < size; i++) { \ for(size_t i = 0; i < size; i++) { \
M_CALL_INIT(oplist, v->data[i].x); \ M_CALL_INIT(oplist, v->data[i].x); \
} \ } \
@@ -336,22 +336,22 @@ M_C(name, _init)(buffer_t v, size_t size) \
M_C3(m_buff3r_,name,_clear_obj)(buffer_t v) \ M_C3(m_buff3r_,name,_clear_obj)(buffer_t v) \
{ \ { \
M_BUFF3R_CONTRACT(v,m_size); \ M_BUFF3R_CONTRACT(v,m_size); \
if (!M_BUFF3R_POLICY_P((policy), BUFFER_PUSH_INIT_POP_MOVE)) { \ if (!M_BUFF3R_POLICY_P((policy), M_BUFFER_PUSH_INIT_POP_MOVE)) { \
for(size_t i = 0; i < M_BUFF3R_SIZE(m_size); i++) { \ for(size_t i = 0; i < M_BUFF3R_SIZE(m_size); i++) { \
M_CALL_CLEAR(oplist, v->data[i].x); \ M_CALL_CLEAR(oplist, v->data[i].x); \
} \ } \
} else { \ } else { \
size_t i = M_BUFF3R_POLICY_P((policy), BUFFER_STACK) ? 0 : v->idx_cons; \ size_t i = M_BUFF3R_POLICY_P((policy), M_BUFFER_STACK) ? 0 : v->idx_cons; \
while (i != v->idx_prod) { \ while (i != v->idx_prod) { \
M_CALL_CLEAR(oplist, v->data[i].x); \ M_CALL_CLEAR(oplist, v->data[i].x); \
i++; \ i++; \
if (!M_BUFF3R_POLICY_P((policy), BUFFER_STACK) && i >= M_BUFF3R_SIZE(m_size)) \ if (!M_BUFF3R_POLICY_P((policy), M_BUFFER_STACK) && i >= M_BUFF3R_SIZE(m_size)) \
i = 0; \ i = 0; \
} \ } \
} \ } \
v->idx_prod = v->idx_cons = 0; \ v->idx_prod = v->idx_cons = 0; \
m_buff3r_number_store (v->number[0], 0U, policy); \ m_buff3r_number_store (v->number[0], 0U, policy); \
if (M_BUFF3R_POLICY_P(policy, BUFFER_DEFERRED_POP)) \ if (M_BUFF3R_POLICY_P(policy, M_BUFFER_DEFERRED_POP)) \
m_buff3r_number_store(v->number[1], 0U, policy); \ m_buff3r_number_store(v->number[1], 0U, policy); \
M_BUFF3R_CONTRACT(v,m_size); \ M_BUFF3R_CONTRACT(v,m_size); \
} \ } \
@@ -366,7 +366,7 @@ M_C(name, _init)(buffer_t v, size_t size) \
v->data = NULL; \ v->data = NULL; \
) \ ) \
v->overwrite = 0; \ v->overwrite = 0; \
if (!M_BUFF3R_POLICY_P((policy), BUFFER_THREAD_UNSAFE)) { \ if (!M_BUFF3R_POLICY_P((policy), M_BUFFER_THREAD_UNSAFE)) { \
m_mutex_clear(v->mutexPush); \ m_mutex_clear(v->mutexPush); \
m_mutex_clear(v->mutexPop); \ m_mutex_clear(v->mutexPop); \
m_cond_clear(v->there_is_data); \ m_cond_clear(v->there_is_data); \
@@ -378,18 +378,18 @@ M_C(name, _init)(buffer_t v, size_t size) \
M_C(name, _reset)(buffer_t v) \ M_C(name, _reset)(buffer_t v) \
{ \ { \
M_BUFF3R_CONTRACT(v,m_size); \ M_BUFF3R_CONTRACT(v,m_size); \
if (!M_BUFF3R_POLICY_P((policy), BUFFER_THREAD_UNSAFE)) { \ if (!M_BUFF3R_POLICY_P((policy), M_BUFFER_THREAD_UNSAFE)) { \
m_mutex_lock(v->mutexPush); \ m_mutex_lock(v->mutexPush); \
m_mutex_lock(v->mutexPop); \ m_mutex_lock(v->mutexPop); \
} \ } \
M_BUFF3R_PROTECTED_CONTRACT(policy, v, m_size); \ M_BUFF3R_PROTECTED_CONTRACT(policy, v, m_size); \
if (M_BUFF3R_POLICY_P((policy), BUFFER_PUSH_INIT_POP_MOVE)) \ if (M_BUFF3R_POLICY_P((policy), M_BUFFER_PUSH_INIT_POP_MOVE)) \
M_C3(m_buff3r_,name,_clear_obj)(v); \ M_C3(m_buff3r_,name,_clear_obj)(v); \
v->idx_prod = v->idx_cons = 0; \ v->idx_prod = v->idx_cons = 0; \
m_buff3r_number_store (v->number[0], 0U, policy); \ m_buff3r_number_store (v->number[0], 0U, policy); \
if (M_BUFF3R_POLICY_P(policy, BUFFER_DEFERRED_POP)) \ if (M_BUFF3R_POLICY_P(policy, M_BUFFER_DEFERRED_POP)) \
m_buff3r_number_store(v->number[1], 0U, policy); \ m_buff3r_number_store(v->number[1], 0U, policy); \
if (!M_BUFF3R_POLICY_P((policy), BUFFER_THREAD_UNSAFE)) { \ if (!M_BUFF3R_POLICY_P((policy), M_BUFFER_THREAD_UNSAFE)) { \
m_cond_broadcast(v->there_is_room_for_data); \ m_cond_broadcast(v->there_is_room_for_data); \
m_mutex_unlock(v->mutexPop); \ m_mutex_unlock(v->mutexPop); \
m_mutex_unlock(v->mutexPush); \ m_mutex_unlock(v->mutexPush); \
@@ -413,22 +413,22 @@ M_C(name, _init)(buffer_t v, size_t size) \
M_ASSERT (dest != v); \ M_ASSERT (dest != v); \
M_BUFF3R_CONTRACT(v,m_size); \ M_BUFF3R_CONTRACT(v,m_size); \
M_C(name, _init)(dest, M_BUFF3R_SIZE(m_size)); \ M_C(name, _init)(dest, M_BUFF3R_SIZE(m_size)); \
if (!M_BUFF3R_POLICY_P((policy), BUFFER_THREAD_UNSAFE)) { \ if (!M_BUFF3R_POLICY_P((policy), M_BUFFER_THREAD_UNSAFE)) { \
m_mutex_lock(v->mutexPush); \ m_mutex_lock(v->mutexPush); \
m_mutex_lock(v->mutexPop); \ m_mutex_lock(v->mutexPop); \
} \ } \
\ \
M_BUFF3R_PROTECTED_CONTRACT(policy, v, m_size); \ M_BUFF3R_PROTECTED_CONTRACT(policy, v, m_size); \
if (!M_BUFF3R_POLICY_P((policy), BUFFER_PUSH_INIT_POP_MOVE)) { \ if (!M_BUFF3R_POLICY_P((policy), M_BUFFER_PUSH_INIT_POP_MOVE)) { \
for(size_t i = 0; i < M_BUFF3R_SIZE(m_size); i++) { \ for(size_t i = 0; i < M_BUFF3R_SIZE(m_size); i++) { \
M_CALL_INIT_SET(oplist, dest->data[i].x, v->data[i].x); \ M_CALL_INIT_SET(oplist, dest->data[i].x, v->data[i].x); \
} \ } \
} else { \ } else { \
size_t i = M_BUFF3R_POLICY_P((policy), BUFFER_STACK) ? 0 : v->idx_cons; \ size_t i = M_BUFF3R_POLICY_P((policy), M_BUFFER_STACK) ? 0 : v->idx_cons; \
while (i != v->idx_prod) { \ while (i != v->idx_prod) { \
M_CALL_INIT_SET(oplist, dest->data[i].x, v->data[i].x); \ M_CALL_INIT_SET(oplist, dest->data[i].x, v->data[i].x); \
i++; \ i++; \
if (!M_BUFF3R_POLICY_P((policy), BUFFER_STACK) && i >= M_BUFF3R_SIZE(m_size)) \ if (!M_BUFF3R_POLICY_P((policy), M_BUFFER_STACK) && i >= M_BUFF3R_SIZE(m_size)) \
i = 0; \ i = 0; \
} \ } \
} \ } \
@@ -436,10 +436,10 @@ M_C(name, _init)(buffer_t v, size_t size) \
dest->idx_prod = v->idx_prod; \ dest->idx_prod = v->idx_prod; \
dest->idx_cons = v->idx_cons; \ dest->idx_cons = v->idx_cons; \
m_buff3r_number_set (dest->number[0], v->number[0], policy); \ m_buff3r_number_set (dest->number[0], v->number[0], policy); \
if (M_BUFF3R_POLICY_P(policy, BUFFER_DEFERRED_POP)) \ if (M_BUFF3R_POLICY_P(policy, M_BUFFER_DEFERRED_POP)) \
m_buff3r_number_set(dest->number[1], v->number[1], policy); \ m_buff3r_number_set(dest->number[1], v->number[1], policy); \
\ \
if (!M_BUFF3R_POLICY_P((policy), BUFFER_THREAD_UNSAFE)) { \ if (!M_BUFF3R_POLICY_P((policy), M_BUFFER_THREAD_UNSAFE)) { \
m_mutex_unlock(v->mutexPop); \ m_mutex_unlock(v->mutexPop); \
m_mutex_unlock(v->mutexPush); \ m_mutex_unlock(v->mutexPush); \
} \ } \
@@ -458,7 +458,7 @@ M_C(name, _init)(buffer_t v, size_t size) \
M_BUFF3R_CONTRACT(v,m_size); \ M_BUFF3R_CONTRACT(v,m_size); \
\ \
if (dest == v) return; \ if (dest == v) return; \
if (!M_BUFF3R_POLICY_P((policy), BUFFER_THREAD_UNSAFE)) { \ if (!M_BUFF3R_POLICY_P((policy), M_BUFFER_THREAD_UNSAFE)) { \
/* Case of deadlock: A := B, B:=C, C:=A (all in //) \ /* Case of deadlock: A := B, B:=C, C:=A (all in //) \
Solution: order the lock by increasing memory */ \ Solution: order the lock by increasing memory */ \
if (dest < v) { \ if (dest < v) { \
@@ -477,16 +477,16 @@ M_C(name, _init)(buffer_t v, size_t size) \
M_BUFF3R_PROTECTED_CONTRACT(policy, v, m_size); \ M_BUFF3R_PROTECTED_CONTRACT(policy, v, m_size); \
M_C3(m_buff3r_,name,_clear_obj)(dest); \ M_C3(m_buff3r_,name,_clear_obj)(dest); \
\ \
if (!M_BUFF3R_POLICY_P((policy), BUFFER_PUSH_INIT_POP_MOVE)) { \ if (!M_BUFF3R_POLICY_P((policy), M_BUFFER_PUSH_INIT_POP_MOVE)) { \
for(size_t i = 0; i < M_BUFF3R_SIZE(m_size); i++) { \ for(size_t i = 0; i < M_BUFF3R_SIZE(m_size); i++) { \
M_CALL_INIT_SET(oplist, dest->data[i].x, v->data[i].x); \ M_CALL_INIT_SET(oplist, dest->data[i].x, v->data[i].x); \
} \ } \
} else { \ } else { \
size_t i = M_BUFF3R_POLICY_P((policy), BUFFER_STACK) ? 0 : v->idx_cons; \ size_t i = M_BUFF3R_POLICY_P((policy), M_BUFFER_STACK) ? 0 : v->idx_cons; \
while (i != v->idx_prod) { \ while (i != v->idx_prod) { \
M_CALL_INIT_SET(oplist, dest->data[i].x, v->data[i].x); \ M_CALL_INIT_SET(oplist, dest->data[i].x, v->data[i].x); \
i++; \ i++; \
if (!M_BUFF3R_POLICY_P((policy), BUFFER_STACK) && i >= M_BUFF3R_SIZE(m_size)) \ if (!M_BUFF3R_POLICY_P((policy), M_BUFFER_STACK) && i >= M_BUFF3R_SIZE(m_size)) \
i = 0; \ i = 0; \
} \ } \
} \ } \
@@ -494,10 +494,10 @@ M_C(name, _init)(buffer_t v, size_t size) \
dest->idx_prod = v->idx_prod; \ dest->idx_prod = v->idx_prod; \
dest->idx_cons = v->idx_cons; \ dest->idx_cons = v->idx_cons; \
m_buff3r_number_set (dest->number[0], v->number[0], policy); \ m_buff3r_number_set (dest->number[0], v->number[0], policy); \
if (M_BUFF3R_POLICY_P(policy, BUFFER_DEFERRED_POP)) \ if (M_BUFF3R_POLICY_P(policy, M_BUFFER_DEFERRED_POP)) \
m_buff3r_number_set(dest->number[1], v->number[1], policy); \ m_buff3r_number_set(dest->number[1], v->number[1], policy); \
\ \
if (!M_BUFF3R_POLICY_P((policy), BUFFER_THREAD_UNSAFE)) { \ if (!M_BUFF3R_POLICY_P((policy), M_BUFFER_THREAD_UNSAFE)) { \
/* It may be false, but it is not wrong! */ \ /* It may be false, but it is not wrong! */ \
m_cond_broadcast(v->there_is_room_for_data); \ m_cond_broadcast(v->there_is_room_for_data); \
m_cond_broadcast(v->there_is_data); \ m_cond_broadcast(v->there_is_data); \
@@ -525,7 +525,7 @@ M_C(name, _init)(buffer_t v, size_t size) \
we considered the queue as empty when the number of \ we considered the queue as empty when the number of \
deferred pop has reached 0, not the number of items in the \ deferred pop has reached 0, not the number of items in the \
buffer is 0. */ \ buffer is 0. */ \
if (M_BUFF3R_POLICY_P(policy, BUFFER_DEFERRED_POP)) \ if (M_BUFF3R_POLICY_P(policy, M_BUFFER_DEFERRED_POP)) \
return m_buff3r_number_load (v->number[1], policy) == 0; \ return m_buff3r_number_load (v->number[1], policy) == 0; \
else \ else \
return m_buff3r_number_load (v->number[0], policy) == 0; \ return m_buff3r_number_load (v->number[0], policy) == 0; \
@@ -552,9 +552,9 @@ M_C(name, _init)(buffer_t v, size_t size) \
M_BUFF3R_CONTRACT(v,m_size); \ M_BUFF3R_CONTRACT(v,m_size); \
\ \
/* Producer Mutex lock (mutex lock performs an acquire memory barrier) */ \ /* Producer Mutex lock (mutex lock performs an acquire memory barrier) */ \
if (!M_BUFF3R_POLICY_P((policy), BUFFER_THREAD_UNSAFE)) { \ if (!M_BUFF3R_POLICY_P((policy), M_BUFFER_THREAD_UNSAFE)) { \
m_mutex_lock(v->mutexPush); \ m_mutex_lock(v->mutexPush); \
while (!M_BUFF3R_POLICY_P((policy), BUFFER_PUSH_OVERWRITE) \ while (!M_BUFF3R_POLICY_P((policy), M_BUFFER_PUSH_OVERWRITE) \
&& M_C(name, _full_p)(v)) { \ && M_C(name, _full_p)(v)) { \
if (!blocking) { \ if (!blocking) { \
m_mutex_unlock(v->mutexPush); \ m_mutex_unlock(v->mutexPush); \
@@ -562,20 +562,20 @@ M_C(name, _init)(buffer_t v, size_t size) \
} \ } \
m_cond_wait(v->there_is_room_for_data, v->mutexPush); \ m_cond_wait(v->there_is_room_for_data, v->mutexPush); \
} \ } \
} else if (!M_BUFF3R_POLICY_P((policy), BUFFER_PUSH_OVERWRITE) \ } else if (!M_BUFF3R_POLICY_P((policy), M_BUFFER_PUSH_OVERWRITE) \
&& M_C(name, _full_p)(v)) \ && M_C(name, _full_p)(v)) \
return false; \ return false; \
M_BUFF3R_PROTECTED_CONTRACT(policy, v, m_size); \ M_BUFF3R_PROTECTED_CONTRACT(policy, v, m_size); \
\ \
size_t previousSize, idx = v->idx_prod; \ size_t previousSize, idx = v->idx_prod; \
/* INDEX computation if we have to overwrite the last element */ \ /* INDEX computation if we have to overwrite the last element */ \
if (M_UNLIKELY (M_BUFF3R_POLICY_P((policy), BUFFER_PUSH_OVERWRITE) \ if (M_UNLIKELY (M_BUFF3R_POLICY_P((policy), M_BUFFER_PUSH_OVERWRITE) \
&& M_C(name, _full_p)(v))) { \ && M_C(name, _full_p)(v))) { \
v->overwrite++; \ v->overwrite++; \
/* Let's overwrite the last element */ \ /* Let's overwrite the last element */ \
/* Compute the index of the last push element */ \ /* Compute the index of the last push element */ \
idx--; \ idx--; \
if (!M_BUFF3R_POLICY_P((policy), BUFFER_STACK)) { \ if (!M_BUFF3R_POLICY_P((policy), M_BUFFER_STACK)) { \
idx = idx >= M_BUFF3R_SIZE(m_size) ? M_BUFF3R_SIZE(m_size)-1 : idx; \ idx = idx >= M_BUFF3R_SIZE(m_size) ? M_BUFF3R_SIZE(m_size)-1 : idx; \
} \ } \
/* Update data in the buffer */ \ /* Update data in the buffer */ \
@@ -584,7 +584,7 @@ M_C(name, _init)(buffer_t v, size_t size) \
} else { \ } else { \
/* Add a new item in the buffer */ \ /* Add a new item in the buffer */ \
/* PUSH data in the buffer */ \ /* PUSH data in the buffer */ \
if (!M_BUFF3R_POLICY_P((policy), BUFFER_PUSH_INIT_POP_MOVE)) { \ if (!M_BUFF3R_POLICY_P((policy), M_BUFFER_PUSH_INIT_POP_MOVE)) { \
M_CALL_SET(oplist, v->data[idx].x, data); \ M_CALL_SET(oplist, v->data[idx].x, data); \
} else { \ } else { \
M_CALL_INIT_SET(oplist, v->data[idx].x, data); \ M_CALL_INIT_SET(oplist, v->data[idx].x, data); \
@@ -592,7 +592,7 @@ M_C(name, _init)(buffer_t v, size_t size) \
\ \
/* Increment production INDEX of the buffer */ \ /* Increment production INDEX of the buffer */ \
idx++; \ idx++; \
if (!M_BUFF3R_POLICY_P((policy), BUFFER_STACK)) { \ if (!M_BUFF3R_POLICY_P((policy), M_BUFFER_STACK)) { \
idx = (idx == M_BUFF3R_SIZE(m_size)) ? 0 : idx; \ idx = (idx == M_BUFF3R_SIZE(m_size)) ? 0 : idx; \
} \ } \
v->idx_prod = idx; \ v->idx_prod = idx; \
@@ -603,14 +603,14 @@ M_C(name, _init)(buffer_t v, size_t size) \
that performs a release memory barrier. */ \ that performs a release memory barrier. */ \
/* Increment number of elements of the buffer */ \ /* Increment number of elements of the buffer */ \
previousSize = m_buff3r_number_inc (v->number[0], policy); \ previousSize = m_buff3r_number_inc (v->number[0], policy); \
if (M_BUFF3R_POLICY_P((policy), BUFFER_DEFERRED_POP)) { \ if (M_BUFF3R_POLICY_P((policy), M_BUFFER_DEFERRED_POP)) { \
previousSize = m_buff3r_number_inc (v->number[1], policy); \ previousSize = m_buff3r_number_inc (v->number[1], policy); \
} \ } \
/* From this point, consummer may read the data in the table */ \ /* From this point, consummer may read the data in the table */ \
} \ } \
\ \
/* Producer unlock (mutex unlock performs a release memory barrier) */ \ /* Producer unlock (mutex unlock performs a release memory barrier) */ \
if (!M_BUFF3R_POLICY_P((policy), BUFFER_THREAD_UNSAFE)) { \ if (!M_BUFF3R_POLICY_P((policy), M_BUFFER_THREAD_UNSAFE)) { \
m_mutex_unlock(v->mutexPush); \ m_mutex_unlock(v->mutexPush); \
/* If the number of items in the buffer was 0, some consummer \ /* If the number of items in the buffer was 0, some consummer \
may be waiting. Signal to them the availibility of the data \ may be waiting. Signal to them the availibility of the data \
@@ -633,7 +633,7 @@ M_C(name, _init)(buffer_t v, size_t size) \
M_ASSERT (data != NULL); \ M_ASSERT (data != NULL); \
\ \
/* Consummer lock (mutex lock performs an acquire memory barrier) */ \ /* Consummer lock (mutex lock performs an acquire memory barrier) */ \
if (!M_BUFF3R_POLICY_P((policy), BUFFER_THREAD_UNSAFE)) { \ if (!M_BUFF3R_POLICY_P((policy), M_BUFFER_THREAD_UNSAFE)) { \
m_mutex_lock(v->mutexPop); \ m_mutex_lock(v->mutexPop); \
while (M_C(name, _empty_p)(v)) { \ while (M_C(name, _empty_p)(v)) { \
if (!blocking) { \ if (!blocking) { \
@@ -647,9 +647,9 @@ M_C(name, _init)(buffer_t v, size_t size) \
M_BUFF3R_PROTECTED_CONTRACT(policy, v, m_size); \ M_BUFF3R_PROTECTED_CONTRACT(policy, v, m_size); \
\ \
/* POP data from the buffer and update INDEX */ \ /* POP data from the buffer and update INDEX */ \
if (!M_BUFF3R_POLICY_P((policy), BUFFER_STACK)) { \ if (!M_BUFF3R_POLICY_P((policy), M_BUFFER_STACK)) { \
/* FIFO queue */ \ /* FIFO queue */ \
if (!M_BUFF3R_POLICY_P((policy), BUFFER_PUSH_INIT_POP_MOVE)) { \ if (!M_BUFF3R_POLICY_P((policy), M_BUFFER_PUSH_INIT_POP_MOVE)) { \
M_CALL_SET(oplist, *data, v->data[v->idx_cons].x); \ M_CALL_SET(oplist, *data, v->data[v->idx_cons].x); \
} else { \ } else { \
M_DO_INIT_MOVE (oplist, *data, v->data[v->idx_cons].x); \ M_DO_INIT_MOVE (oplist, *data, v->data[v->idx_cons].x); \
@@ -658,7 +658,7 @@ M_C(name, _init)(buffer_t v, size_t size) \
} else { \ } else { \
/* STACK queue */ \ /* STACK queue */ \
v->idx_prod --; \ v->idx_prod --; \
if (!M_BUFF3R_POLICY_P((policy), BUFFER_PUSH_INIT_POP_MOVE)) { \ if (!M_BUFF3R_POLICY_P((policy), M_BUFFER_PUSH_INIT_POP_MOVE)) { \
M_CALL_SET(oplist, *data, v->data[v->idx_prod].x); \ M_CALL_SET(oplist, *data, v->data[v->idx_prod].x); \
} else { \ } else { \
M_DO_INIT_MOVE (oplist, *data, v->data[v->idx_prod].x); \ M_DO_INIT_MOVE (oplist, *data, v->data[v->idx_prod].x); \
@@ -671,7 +671,7 @@ M_C(name, _init)(buffer_t v, size_t size) \
that performs a release memory barrier. */ \ that performs a release memory barrier. */ \
/* Decrement number of elements in the buffer */ \ /* Decrement number of elements in the buffer */ \
size_t previousSize; \ size_t previousSize; \
if (!M_BUFF3R_POLICY_P((policy), BUFFER_DEFERRED_POP)) { \ if (!M_BUFF3R_POLICY_P((policy), M_BUFFER_DEFERRED_POP)) { \
previousSize = m_buff3r_number_dec (v->number[0], policy); \ previousSize = m_buff3r_number_dec (v->number[0], policy); \
} else { \ } else { \
m_buff3r_number_dec (v->number[1], policy); \ m_buff3r_number_dec (v->number[1], policy); \
@@ -679,12 +679,12 @@ M_C(name, _init)(buffer_t v, size_t size) \
/* Space may be reused by a producer thread from this point */ \ /* Space may be reused by a producer thread from this point */ \
\ \
/* Consummer unlock (mutex unlock perfoms a release memory barrier) */ \ /* Consummer unlock (mutex unlock perfoms a release memory barrier) */ \
if (!M_BUFF3R_POLICY_P((policy), BUFFER_THREAD_UNSAFE)) { \ if (!M_BUFF3R_POLICY_P((policy), M_BUFFER_THREAD_UNSAFE)) { \
m_mutex_unlock(v->mutexPop); \ m_mutex_unlock(v->mutexPop); \
/* If the number of items in the buffer was the max, some producer \ /* If the number of items in the buffer was the max, some producer \
may be waiting. Signal to them the availibility of the free room \ may be waiting. Signal to them the availibility of the free room \
We cannot only signal one thread. */ \ We cannot only signal one thread. */ \
if ((!M_BUFF3R_POLICY_P((policy), BUFFER_DEFERRED_POP)) \ if ((!M_BUFF3R_POLICY_P((policy), M_BUFFER_DEFERRED_POP)) \
&& previousSize == M_BUFF3R_SIZE(m_size)) { \ && previousSize == M_BUFF3R_SIZE(m_size)) { \
m_mutex_lock(v->mutexPush); \ m_mutex_lock(v->mutexPush); \
m_cond_broadcast(v->there_is_room_for_data); \ m_cond_broadcast(v->there_is_room_for_data); \
@@ -701,14 +701,14 @@ M_C(name, _init)(buffer_t v, size_t size) \
M_C(name, _push)(buffer_t v, type const data) \ M_C(name, _push)(buffer_t v, type const data) \
{ \ { \
return M_C(name, _push_blocking)(v, data, \ return M_C(name, _push_blocking)(v, data, \
!M_BUFF3R_POLICY_P((policy), BUFFER_UNBLOCKING_PUSH)); \ !M_BUFF3R_POLICY_P((policy), M_BUFFER_UNBLOCKING_PUSH)); \
} \ } \
\ \
static inline bool \ static inline bool \
M_C(name, _pop)(type *data, buffer_t v) \ M_C(name, _pop)(type *data, buffer_t v) \
{ \ { \
return M_C(name, _pop_blocking)(data, v, \ return M_C(name, _pop_blocking)(data, v, \
!M_BUFF3R_POLICY_P((policy), BUFFER_UNBLOCKING_POP)); \ !M_BUFF3R_POLICY_P((policy), M_BUFFER_UNBLOCKING_POP)); \
} \ } \
\ \
static inline size_t \ static inline size_t \
@@ -728,7 +728,7 @@ M_C(name, _init)(buffer_t v, size_t size) \
M_C(name, _pop_release)(buffer_t v) \ M_C(name, _pop_release)(buffer_t v) \
{ \ { \
/* Decrement the effective number of elements in the buffer */ \ /* Decrement the effective number of elements in the buffer */ \
if (M_BUFF3R_POLICY_P((policy), BUFFER_DEFERRED_POP)) { \ if (M_BUFF3R_POLICY_P((policy), M_BUFFER_DEFERRED_POP)) { \
size_t previousSize = m_buff3r_number_dec (v->number[0], policy); \ size_t previousSize = m_buff3r_number_dec (v->number[0], policy); \
if (previousSize == M_BUFF3R_SIZE(m_size)) { \ if (previousSize == M_BUFF3R_SIZE(m_size)) { \
m_mutex_lock(v->mutexPush); \ m_mutex_lock(v->mutexPush); \
@@ -833,7 +833,7 @@ M_C(name, _init)(buffer_t v, size_t size) \
return false; \ return false; \
} \ } \
/* If it is interrupted here, it may block pop method (not push) */ \ /* If it is interrupted here, it may block pop method (not push) */ \
if (!M_BUFF3R_POLICY_P((policy), BUFFER_PUSH_INIT_POP_MOVE)) { \ if (!M_BUFF3R_POLICY_P((policy), M_BUFFER_PUSH_INIT_POP_MOVE)) { \
M_CALL_SET(oplist, table->Tab[i].x, x); \ M_CALL_SET(oplist, table->Tab[i].x, x); \
} else { \ } else { \
M_CALL_INIT_SET(oplist, table->Tab[i].x, x); \ M_CALL_INIT_SET(oplist, table->Tab[i].x, x); \
@@ -863,7 +863,7 @@ M_C(name, _init)(buffer_t v, size_t size) \
/* Thread has been preempted by another one */ \ /* Thread has been preempted by another one */ \
return false; \ return false; \
} \ } \
if (!M_BUFF3R_POLICY_P((policy), BUFFER_PUSH_INIT_POP_MOVE)) { \ if (!M_BUFF3R_POLICY_P((policy), M_BUFFER_PUSH_INIT_POP_MOVE)) { \
M_CALL_SET(oplist, *ptr, table->Tab[i].x); \ M_CALL_SET(oplist, *ptr, table->Tab[i].x); \
} else { \ } else { \
M_DO_INIT_MOVE (oplist, *ptr, table->Tab[i].x); \ M_DO_INIT_MOVE (oplist, *ptr, table->Tab[i].x); \
@@ -879,7 +879,7 @@ M_C(name, _init)(buffer_t v, size_t size) \
M_ASSERT (buffer != NULL); \ M_ASSERT (buffer != NULL); \
M_ASSERT( M_POWEROF2_P(size)); \ M_ASSERT( M_POWEROF2_P(size)); \
M_ASSERT (0 < size && size <= UINT_MAX); \ M_ASSERT (0 < size && size <= UINT_MAX); \
M_ASSERT(((policy) & (BUFFER_STACK|BUFFER_THREAD_UNSAFE|BUFFER_PUSH_OVERWRITE)) == 0); \ M_ASSERT(((policy) & (M_BUFFER_STACK|M_BUFFER_THREAD_UNSAFE|M_BUFFER_PUSH_OVERWRITE)) == 0); \
atomic_init(&buffer->ProdIdx, (unsigned int) size); \ atomic_init(&buffer->ProdIdx, (unsigned int) size); \
atomic_init(&buffer->ConsoIdx, (unsigned int) size); \ atomic_init(&buffer->ConsoIdx, (unsigned int) size); \
buffer->size = (unsigned int) size; \ buffer->size = (unsigned int) size; \
@@ -890,7 +890,7 @@ M_C(name, _init)(buffer_t v, size_t size) \
} \ } \
for(unsigned int j = 0; j < (unsigned int) size; j++) { \ for(unsigned int j = 0; j < (unsigned int) size; j++) { \
atomic_init(&buffer->Tab[j].seq, 2*j+1U); \ atomic_init(&buffer->Tab[j].seq, 2*j+1U); \
if (!M_BUFF3R_POLICY_P((policy), BUFFER_PUSH_INIT_POP_MOVE)) { \ if (!M_BUFF3R_POLICY_P((policy), M_BUFFER_PUSH_INIT_POP_MOVE)) { \
M_CALL_INIT(oplist, buffer->Tab[j].x); \ M_CALL_INIT(oplist, buffer->Tab[j].x); \
} \ } \
} \ } \
@@ -901,7 +901,7 @@ M_C(name, _init)(buffer_t v, size_t size) \
M_C(name, _clear)(buffer_t buffer) \ M_C(name, _clear)(buffer_t buffer) \
{ \ { \
M_QU3UE_MPMC_CONTRACT(buffer); \ M_QU3UE_MPMC_CONTRACT(buffer); \
if (!M_BUFF3R_POLICY_P((policy), BUFFER_PUSH_INIT_POP_MOVE)) { \ if (!M_BUFF3R_POLICY_P((policy), M_BUFFER_PUSH_INIT_POP_MOVE)) { \
for(unsigned int j = 0; j < buffer->size; j++) { \ for(unsigned int j = 0; j < buffer->size; j++) { \
M_CALL_CLEAR(oplist, buffer->Tab[j].x); \ M_CALL_CLEAR(oplist, buffer->Tab[j].x); \
} \ } \
@@ -1037,7 +1037,7 @@ M_C(name, _init)(buffer_t v, size_t size) \
if (w-r >= table->size) \ if (w-r >= table->size) \
return false; \ return false; \
unsigned int i = w & (table->size -1); \ unsigned int i = w & (table->size -1); \
if (!M_BUFF3R_POLICY_P((policy), BUFFER_PUSH_INIT_POP_MOVE)) { \ if (!M_BUFF3R_POLICY_P((policy), M_BUFFER_PUSH_INIT_POP_MOVE)) { \
M_CALL_SET(oplist, table->Tab[i].x, x); \ M_CALL_SET(oplist, table->Tab[i].x, x); \
} else { \ } else { \
M_CALL_INIT_SET(oplist, table->Tab[i].x, x); \ M_CALL_INIT_SET(oplist, table->Tab[i].x, x); \
@@ -1058,7 +1058,7 @@ M_C(name, _init)(buffer_t v, size_t size) \
if (w-r >= table->size) \ if (w-r >= table->size) \
return false; \ return false; \
unsigned int i = w & (table->size -1); \ unsigned int i = w & (table->size -1); \
if (!M_BUFF3R_POLICY_P((policy), BUFFER_PUSH_INIT_POP_MOVE)) { \ if (!M_BUFF3R_POLICY_P((policy), M_BUFFER_PUSH_INIT_POP_MOVE)) { \
M_DO_MOVE(oplist, table->Tab[i].x, *x); \ M_DO_MOVE(oplist, table->Tab[i].x, *x); \
} else { \ } else { \
M_DO_INIT_MOVE(oplist, table->Tab[i].x, *x); \ M_DO_INIT_MOVE(oplist, table->Tab[i].x, *x); \
@@ -1080,7 +1080,7 @@ M_C(name, _init)(buffer_t v, size_t size) \
if (w-r == 0) \ if (w-r == 0) \
return false; \ return false; \
unsigned int i = r & (table->size -1); \ unsigned int i = r & (table->size -1); \
if (!M_BUFF3R_POLICY_P((policy), BUFFER_PUSH_INIT_POP_MOVE)) { \ if (!M_BUFF3R_POLICY_P((policy), M_BUFFER_PUSH_INIT_POP_MOVE)) { \
M_CALL_SET(oplist, *ptr , table->Tab[i].x); \ M_CALL_SET(oplist, *ptr , table->Tab[i].x); \
} else { \ } else { \
M_DO_INIT_MOVE (oplist, *ptr, table->Tab[i].x); \ M_DO_INIT_MOVE (oplist, *ptr, table->Tab[i].x); \
@@ -1105,7 +1105,7 @@ M_C(name, _init)(buffer_t v, size_t size) \
return 0; \ return 0; \
for(unsigned int k = 0; k < max; k++) { \ for(unsigned int k = 0; k < max; k++) { \
unsigned int i = (w+k) & (table->size -1); \ unsigned int i = (w+k) & (table->size -1); \
if (!M_BUFF3R_POLICY_P((policy), BUFFER_PUSH_INIT_POP_MOVE)) { \ if (!M_BUFF3R_POLICY_P((policy), M_BUFFER_PUSH_INIT_POP_MOVE)) { \
M_CALL_SET(oplist, table->Tab[i].x, x[k]); \ M_CALL_SET(oplist, table->Tab[i].x, x[k]); \
} else { \ } else { \
M_CALL_INIT_SET(oplist, table->Tab[i].x, x[k]); \ M_CALL_INIT_SET(oplist, table->Tab[i].x, x[k]); \
@@ -1131,7 +1131,7 @@ M_C(name, _init)(buffer_t v, size_t size) \
unsigned int max = M_MIN(w-r, n); \ unsigned int max = M_MIN(w-r, n); \
for(unsigned int k = 0; k < max; k++) { \ for(unsigned int k = 0; k < max; k++) { \
unsigned int i = (r+k) & (table->size -1); \ unsigned int i = (r+k) & (table->size -1); \
if (!M_BUFF3R_POLICY_P((policy), BUFFER_PUSH_INIT_POP_MOVE)) { \ if (!M_BUFF3R_POLICY_P((policy), M_BUFFER_PUSH_INIT_POP_MOVE)) { \
M_CALL_SET(oplist, ptr[k], table->Tab[i].x); \ M_CALL_SET(oplist, ptr[k], table->Tab[i].x); \
} else { \ } else { \
M_DO_INIT_MOVE (oplist, ptr[k], table->Tab[i].x); \ M_DO_INIT_MOVE (oplist, ptr[k], table->Tab[i].x); \
@@ -1156,7 +1156,7 @@ M_C(name, _init)(buffer_t v, size_t size) \
r += b; \ r += b; \
} \ } \
unsigned int i = w & (table->size -1); \ unsigned int i = w & (table->size -1); \
if (!M_BUFF3R_POLICY_P((policy), BUFFER_PUSH_INIT_POP_MOVE)) { \ if (!M_BUFF3R_POLICY_P((policy), M_BUFFER_PUSH_INIT_POP_MOVE)) { \
M_CALL_SET(oplist, table->Tab[i].x, x); \ M_CALL_SET(oplist, table->Tab[i].x, x); \
} else { \ } else { \
M_CALL_INIT_SET(oplist, table->Tab[i].x, x); \ M_CALL_INIT_SET(oplist, table->Tab[i].x, x); \
@@ -1210,7 +1210,7 @@ M_C(name, _init)(buffer_t v, size_t size) \
M_ASSERT (buffer != NULL); \ M_ASSERT (buffer != NULL); \
M_ASSERT( M_POWEROF2_P(size)); \ M_ASSERT( M_POWEROF2_P(size)); \
M_ASSERT (0 < size && size <= UINT_MAX); \ M_ASSERT (0 < size && size <= UINT_MAX); \
M_ASSERT(((policy) & (BUFFER_STACK|BUFFER_THREAD_UNSAFE|BUFFER_PUSH_OVERWRITE)) == 0); \ M_ASSERT(((policy) & (M_BUFFER_STACK|M_BUFFER_THREAD_UNSAFE|M_BUFFER_PUSH_OVERWRITE)) == 0); \
atomic_init(&buffer->prodIdx, (unsigned int) size); \ atomic_init(&buffer->prodIdx, (unsigned int) size); \
atomic_init(&buffer->consoIdx, (unsigned int) size); \ atomic_init(&buffer->consoIdx, (unsigned int) size); \
buffer->size = (unsigned int) size; \ buffer->size = (unsigned int) size; \
@@ -1219,7 +1219,7 @@ M_C(name, _init)(buffer_t v, size_t size) \
M_MEMORY_FULL (size*sizeof(M_C(name, _el_ct) )); \ M_MEMORY_FULL (size*sizeof(M_C(name, _el_ct) )); \
return; \ return; \
} \ } \
if (!M_BUFF3R_POLICY_P((policy), BUFFER_PUSH_INIT_POP_MOVE)) { \ if (!M_BUFF3R_POLICY_P((policy), M_BUFFER_PUSH_INIT_POP_MOVE)) { \
for(unsigned int j = 0; j < (unsigned int) size; j++) { \ for(unsigned int j = 0; j < (unsigned int) size; j++) { \
M_CALL_INIT(oplist, buffer->Tab[j].x); \ M_CALL_INIT(oplist, buffer->Tab[j].x); \
} \ } \
@@ -1231,7 +1231,7 @@ M_C(name, _init)(buffer_t v, size_t size) \
M_C(name, _clear)(buffer_t buffer) \ M_C(name, _clear)(buffer_t buffer) \
{ \ { \
M_QU3UE_SPSC_CONTRACT(buffer); \ M_QU3UE_SPSC_CONTRACT(buffer); \
if (!M_BUFF3R_POLICY_P((policy), BUFFER_PUSH_INIT_POP_MOVE)) { \ if (!M_BUFF3R_POLICY_P((policy), M_BUFFER_PUSH_INIT_POP_MOVE)) { \
for(unsigned int j = 0; j < buffer->size; j++) { \ for(unsigned int j = 0; j < buffer->size; j++) { \
M_CALL_CLEAR(oplist, buffer->Tab[j].x); \ M_CALL_CLEAR(oplist, buffer->Tab[j].x); \
} \ } \
@@ -1282,5 +1282,30 @@ M_C(name, _init)(buffer_t v, size_t size) \
,GET_SIZE(M_C(name, _size)) \ ,GET_SIZE(M_C(name, _size)) \
) )
#if M_USE_SMALL_NAME
#define BUFFER_DEF M_BUFFER_DEF
#define BUFFER_DEF_AS M_BUFFER_DEF_AS
#define BUFFER_OPLIST M_BUFFER_OPLIST
#define QUEUE_MPMC_DEF M_QUEUE_MPMC_DEF
#define QUEUE_MPMC_DEF_AS M_QUEUE_MPMC_DEF_AS
#define QUEUE_SPSC_DEF M_QUEUE_SPSC_DEF
#define QUEUE_SPSC_DEF_AS M_QUEUE_SPSC_DEF_AS
#define buffer_policy_e m_buffer_policy_e
#define BUFFER_QUEUE M_BUFFER_QUEUE
#define BUFFER_STACK M_BUFFER_STACK
#define BUFFER_BLOCKING_PUSH M_BUFFER_BLOCKING_PUSH
#define BUFFER_UNBLOCKING_PUSH M_BUFFER_UNBLOCKING_PUSH
#define BUFFER_BLOCKING_POP M_BUFFER_BLOCKING_POP
#define BUFFER_UNBLOCKING_POP M_BUFFER_UNBLOCKING_POP
#define BUFFER_BLOCKING M_BUFFER_BLOCKING
#define BUFFER_UNBLOCKING M_BUFFER_UNBLOCKING
#define BUFFER_THREAD_SAFE M_BUFFER_THREAD_SAFE
#define BUFFER_THREAD_UNSAFE M_BUFFER_THREAD_UNSAFE
#define BUFFER_PUSH_INIT_POP_MOVE M_BUFFER_PUSH_INIT_POP_MOVE
#define BUFFER_PUSH_OVERWRITE M_BUFFER_PUSH_OVERWRITE
#define BUFFER_DEFERRED_POP M_BUFFER_DEFERRED_POP
#endif
#endif #endif
+5 -1
View File
@@ -34,7 +34,7 @@ M_BEGIN_PROTECTED_CODE
/* Minimum number of nodes per group of nodes */ /* Minimum number of nodes per group of nodes */
#define M_CMEMP00L_MIN_NODE_PER_GROUP 16 #define M_CMEMP00L_MIN_NODE_PER_GROUP 16
#define C_MEMPOOL_DEF(name, type_t) \ #define M_C_MEMPOOL_DEF(name, type_t) \
M_BEGIN_PROTECTED_CODE \ M_BEGIN_PROTECTED_CODE \
M_CMEMP00L_DEF_SINGLY_LIST(name, type_t) \ M_CMEMP00L_DEF_SINGLY_LIST(name, type_t) \
M_CMEMP00L_DEF_LF_QUEUE(name, type_t) \ M_CMEMP00L_DEF_LF_QUEUE(name, type_t) \
@@ -828,4 +828,8 @@ m_vlapool_del(m_vlapool_t mem, void *d, m_gc_tid_t id)
M_END_PROTECTED_CODE M_END_PROTECTED_CODE
#if M_USE_SMALL_NAME
#define C_MEMPOOL_DEF M_C_MEMPOOL_DEF
#endif
#endif #endif
+14 -7
View File
@@ -32,14 +32,14 @@
/* Define a protected concurrent container and its associated functions /* Define a protected concurrent container and its associated functions
based on the given container. based on the given container.
USAGE: CONCURRENT_DEF(name, type [, oplist_of_the_type]) */ USAGE: CONCURRENT_DEF(name, type [, oplist_of_the_type]) */
#define CONCURRENT_DEF(name, ...) \ #define M_CONCURRENT_DEF(name, ...) \
CONCURRENT_DEF_AS(name, M_C(name,_t), __VA_ARGS__) M_CONCURRENT_DEF_AS(name, M_C(name,_t), __VA_ARGS__)
/* Define a protected concurrent container and its associated functions /* Define a protected concurrent container and its associated functions
based on the given container as the given name name_t based on the given container as the given name name_t
USAGE: CONCURRENT_DEF_AS(name, name_t, type [, oplist_of_the_type]) */ USAGE: CONCURRENT_DEF_AS(name, name_t, type [, oplist_of_the_type]) */
#define CONCURRENT_DEF_AS(name, name_t, ...) \ #define M_CONCURRENT_DEF_AS(name, name_t, ...) \
M_BEGIN_PROTECTED_CODE \ M_BEGIN_PROTECTED_CODE \
M_C0NCURRENT_DEF_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \ M_C0NCURRENT_DEF_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \
((name, __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), name_t ), \ ((name, __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), name_t ), \
@@ -51,8 +51,8 @@
based on its given container. Operations that perform only read of the container based on its given container. Operations that perform only read of the container
can be done in parallel. can be done in parallel.
USAGE: CONCURRENT_RP_DEF(name, type [, oplist_of_the_type]) */ USAGE: CONCURRENT_RP_DEF(name, type [, oplist_of_the_type]) */
#define CONCURRENT_RP_DEF(name, ...) \ #define M_CONCURRENT_RP_DEF(name, ...) \
CONCURRENT_RP_DEF_AS(name, M_C(name,_t), __VA_ARGS__) M_CONCURRENT_RP_DEF_AS(name, M_C(name,_t), __VA_ARGS__)
/* Define a protected concurrent container and its associated functions /* Define a protected concurrent container and its associated functions
@@ -60,7 +60,7 @@
based on its given container. Operations that perform only read of the container based on its given container. Operations that perform only read of the container
can be done in parallel. can be done in parallel.
USAGE: CONCURRENT_RP_DEF_AS(name, name_t, type [, oplist_of_the_type]) */ USAGE: CONCURRENT_RP_DEF_AS(name, name_t, type [, oplist_of_the_type]) */
#define CONCURRENT_RP_DEF_AS(name, name_t, ...) \ #define M_CONCURRENT_RP_DEF_AS(name, name_t, ...) \
M_BEGIN_PROTECTED_CODE \ M_BEGIN_PROTECTED_CODE \
M_C0NCURRENT_RP_DEF_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \ M_C0NCURRENT_RP_DEF_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \
((name, __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), name_t ), \ ((name, __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), name_t ), \
@@ -70,7 +70,7 @@
/* Define the oplist of a protected concurrent container given its name and its oplist. /* Define the oplist of a protected concurrent container given its name and its oplist.
USAGE: CONCURRENT_OPLIST(name[, oplist of the type]) */ USAGE: CONCURRENT_OPLIST(name[, oplist of the type]) */
#define CONCURRENT_OPLIST(...) \ #define M_CONCURRENT_OPLIST(...) \
M_C0NCURRENT_OPLIST_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \ M_C0NCURRENT_OPLIST_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \
((__VA_ARGS__, M_DEFAULT_OPLIST), \ ((__VA_ARGS__, M_DEFAULT_OPLIST), \
(__VA_ARGS__ ))) (__VA_ARGS__ )))
@@ -895,5 +895,12 @@
\ \
M_C0NCURRENT_DEF_FUNC_P3(name, type, oplist, concurrent_t) M_C0NCURRENT_DEF_FUNC_P3(name, type, oplist, concurrent_t)
#if M_USE_SMALL_NAME
#define CONCURRENT_DEF M_CONCURRENT_DEF
#define CONCURRENT_DEF_AS M_CONCURRENT_DEF_AS
#define CONCURRENT_RP_DEF M_CONCURRENT_RP_DEF
#define CONCURRENT_RP_DEF_AS M_CONCURRENT_RP_DEF_AS
#define CONCURRENT_OPLIST M_CONCURRENT_OPLIST
#endif
#endif #endif
+10 -4
View File
@@ -29,14 +29,14 @@
/* Define a deque of a given type and its associated functions. /* Define a deque of a given type and its associated functions.
USAGE: DEQUE_DEF(name, type [, oplist_of_the_type]) */ USAGE: DEQUE_DEF(name, type [, oplist_of_the_type]) */
#define DEQUE_DEF(name, ...) \ #define M_DEQUE_DEF(name, ...) \
DEQUE_DEF_AS(name, M_C(name,_t), M_C(name,_it_t), __VA_ARGS__) M_DEQUE_DEF_AS(name, M_C(name,_t), M_C(name,_it_t), __VA_ARGS__)
/* Define a deque of a given type and its associated functions. /* Define a deque of a given type and its associated functions.
as the provided type name_t with the iterator named it_t. as the provided type name_t with the iterator named it_t.
USAGE: DEQUE_DEF(name, name_t, it_t, type [, oplist_of_the_type]) */ USAGE: DEQUE_DEF(name, name_t, it_t, type [, oplist_of_the_type]) */
#define DEQUE_DEF_AS(name, name_t, it_t, ...) \ #define M_DEQUE_DEF_AS(name, name_t, it_t, ...) \
M_BEGIN_PROTECTED_CODE \ M_BEGIN_PROTECTED_CODE \
M_D3QU3_DEF_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \ M_D3QU3_DEF_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \
((name, __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), name_t, it_t, M_C(name, _node_ct) ), \ ((name, __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), name_t, it_t, M_C(name, _node_ct) ), \
@@ -46,7 +46,7 @@
/* Define the oplist of a deque of a type. /* Define the oplist of a deque of a type.
USAGE: DEQUE_OPLIST(name[, oplist of the type]) */ USAGE: DEQUE_OPLIST(name[, oplist of the type]) */
#define DEQUE_OPLIST(...) \ #define M_DEQUE_OPLIST(...) \
M_D3QU3_OPLIST_P1 (M_IF_NARGS_EQ1(__VA_ARGS__) \ M_D3QU3_OPLIST_P1 (M_IF_NARGS_EQ1(__VA_ARGS__) \
((__VA_ARGS__, M_DEFAULT_OPLIST), \ ((__VA_ARGS__, M_DEFAULT_OPLIST), \
(__VA_ARGS__ ))) (__VA_ARGS__ )))
@@ -1100,4 +1100,10 @@
,M_IF_METHOD(DEL, oplist)(DEL(M_GET_DEL oplist),) \ ,M_IF_METHOD(DEL, oplist)(DEL(M_GET_DEL oplist),) \
) )
#if M_USE_SMALL_NAME
#define DEQUE_DEF M_DEQUE_DEF
#define DEQUE_DEF_AS M_DEQUE_DEF_AS
#define DEQUE_OPLIST M_DEQUE_OPLIST
#endif
#endif #endif
+31 -17
View File
@@ -36,8 +36,8 @@
OR OR
DICT_DEF2(name, key_type, value_type) DICT_DEF2(name, key_type, value_type)
*/ */
#define DICT_DEF2(name, key_type, ...) \ #define M_DICT_DEF2(name, key_type, ...) \
DICT_DEF2_AS(name, M_C(name,_t), M_C(name,_it_t), M_C(name,_itref_t), key_type, __VA_ARGS__) M_DICT_DEF2_AS(name, M_C(name,_t), M_C(name,_it_t), M_C(name,_itref_t), key_type, __VA_ARGS__)
/* Define a dictionary associating the key key_type to the value value_type and its associated functions. /* Define a dictionary associating the key key_type to the value value_type and its associated functions.
@@ -47,7 +47,7 @@
OR OR
DICT_DEF2_AS(name, name_t, it_t, itref_t, key_type, value_type) DICT_DEF2_AS(name, name_t, it_t, itref_t, key_type, value_type)
*/ */
#define DICT_DEF2_AS(name, name_t, it_t, itref_t, key_type, ...) \ #define M_DICT_DEF2_AS(name, name_t, it_t, itref_t, key_type, ...) \
M_BEGIN_PROTECTED_CODE \ M_BEGIN_PROTECTED_CODE \
M_D1CT_DEF2_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \ M_D1CT_DEF2_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \
((name, key_type, M_GLOBAL_OPLIST_OR_DEF(key_type)(), __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), name_t, it_t, itref_t ), \ ((name, key_type, M_GLOBAL_OPLIST_OR_DEF(key_type)(), __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), name_t, it_t, itref_t ), \
@@ -63,8 +63,8 @@
OR OR
DICT_STOREHASH_DEF2(name, key_type[, key_oplist], value_type[, value_oplist]) DICT_STOREHASH_DEF2(name, key_type[, key_oplist], value_type[, value_oplist])
*/ */
#define DICT_STOREHASH_DEF2(name, key_type, ...) \ #define M_DICT_STOREHASH_DEF2(name, key_type, ...) \
DICT_STOREHASH_DEF2_AS(name, M_C(name,_t), M_C(name,_it_t), M_C(name,_itref_t), key_type, __VA_ARGS__) M_DICT_STOREHASH_DEF2_AS(name, M_C(name,_t), M_C(name,_it_t), M_C(name,_itref_t), key_type, __VA_ARGS__)
/* Define a dictionary asssociating the key key_type to the value value_type and its associated functions. /* Define a dictionary asssociating the key key_type to the value value_type and its associated functions.
@@ -76,7 +76,7 @@
OR OR
DICT_STOREHASH_DEF2_AS(name, name_t, it_t, itref_t, key_type[, key_oplist], value_type[, value_oplist]) DICT_STOREHASH_DEF2_AS(name, name_t, it_t, itref_t, key_type[, key_oplist], value_type[, value_oplist])
*/ */
#define DICT_STOREHASH_DEF2_AS(name, name_t, it_t, itref_t, key_type, ...) \ #define M_DICT_STOREHASH_DEF2_AS(name, name_t, it_t, itref_t, key_type, ...) \
M_BEGIN_PROTECTED_CODE \ M_BEGIN_PROTECTED_CODE \
M_D1CT_SHASH_DEF2_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \ M_D1CT_SHASH_DEF2_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \
((name, key_type, M_GLOBAL_OPLIST_OR_DEF(key_type)(), __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), name_t, it_t, itref_t ), \ ((name, key_type, M_GLOBAL_OPLIST_OR_DEF(key_type)(), __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), name_t, it_t, itref_t ), \
@@ -92,8 +92,8 @@
OR OR
DICT_OA_DEF2(name, key_type, value_type) DICT_OA_DEF2(name, key_type, value_type)
*/ */
#define DICT_OA_DEF2(name, key_type, ...) \ #define M_DICT_OA_DEF2(name, key_type, ...) \
DICT_OA_DEF2_AS(name, M_C(name,_t), M_C(name,_it_t), M_C(name,_itref_t), key_type, __VA_ARGS__) M_DICT_OA_DEF2_AS(name, M_C(name,_t), M_C(name,_it_t), M_C(name,_itref_t), key_type, __VA_ARGS__)
/* Define a dictionary associating the key key_type to the value value_type /* Define a dictionary associating the key key_type to the value value_type
@@ -105,7 +105,7 @@
OR OR
DICT_OA_DEF2_AS(name, name_t, it_t, itref_t, key_type, value_type) DICT_OA_DEF2_AS(name, name_t, it_t, itref_t, key_type, value_type)
*/ */
#define DICT_OA_DEF2_AS(name, name_t, it_t, itref_t, key_type, ...) \ #define M_DICT_OA_DEF2_AS(name, name_t, it_t, itref_t, key_type, ...) \
M_BEGIN_PROTECTED_CODE \ M_BEGIN_PROTECTED_CODE \
M_D1CT_OA_DEF_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \ M_D1CT_OA_DEF_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \
((name, key_type, M_GLOBAL_OPLIST_OR_DEF(key_type)(), __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), name_t, it_t, itref_t ), \ ((name, key_type, M_GLOBAL_OPLIST_OR_DEF(key_type)(), __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), name_t, it_t, itref_t ), \
@@ -117,8 +117,8 @@
The set is unordered. The set is unordered.
USAGE: DICT_SET_DEF(name, key_type[, key_oplist]) USAGE: DICT_SET_DEF(name, key_type[, key_oplist])
*/ */
#define DICT_SET_DEF(name, ...) \ #define M_DICT_SET_DEF(name, ...) \
DICT_SET_DEF_AS(name, M_C(name,_t), M_C(name,_it_t), __VA_ARGS__) M_DICT_SET_DEF_AS(name, M_C(name,_t), M_C(name,_it_t), __VA_ARGS__)
/* Define a set of the key key_type and its associated functions. /* Define a set of the key key_type and its associated functions.
@@ -126,7 +126,7 @@
The set is unordered. The set is unordered.
USAGE: DICT_SET_DEF_AS(name, name_t, it_t, key_type[, key_oplist]) USAGE: DICT_SET_DEF_AS(name, name_t, it_t, key_type[, key_oplist])
*/ */
#define DICT_SET_DEF_AS(name, name_t, it_t, ...) \ #define M_DICT_SET_DEF_AS(name, name_t, it_t, ...) \
M_BEGIN_PROTECTED_CODE \ M_BEGIN_PROTECTED_CODE \
M_D1CT_SET_DEF_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \ M_D1CT_SET_DEF_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \
((name, __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), name_t, it_t, M_C(name, _itref_ct) ), \ ((name, __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), name_t, it_t, M_C(name, _itref_ct) ), \
@@ -139,8 +139,8 @@
The set is unordered. The set is unordered.
USAGE: DICT_OASET_DEF(name, key_type[, key_oplist]) USAGE: DICT_OASET_DEF(name, key_type[, key_oplist])
*/ */
#define DICT_OASET_DEF(name, ...) \ #define M_DICT_OASET_DEF(name, ...) \
DICT_OASET_DEF_AS(name, M_C(name,_t), M_C(name,_it_t), __VA_ARGS__) M_DICT_OASET_DEF_AS(name, M_C(name,_t), M_C(name,_it_t), __VA_ARGS__)
/* Define a set of the key key_type /* Define a set of the key key_type
@@ -149,7 +149,7 @@
The set is unordered. The set is unordered.
USAGE: DICT_OASET_DEF_AS(name, name_t, it_t, key_type[, key_oplist]) USAGE: DICT_OASET_DEF_AS(name, name_t, it_t, key_type[, key_oplist])
*/ */
#define DICT_OASET_DEF_AS(name, name_t, it_t, ...) \ #define M_DICT_OASET_DEF_AS(name, name_t, it_t, ...) \
M_BEGIN_PROTECTED_CODE \ M_BEGIN_PROTECTED_CODE \
M_D1CT_OASET_DEF_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \ M_D1CT_OASET_DEF_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \
((name, __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), name_t, it_t, M_C(name, _itref_ct) ), \ ((name, __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), name_t, it_t, M_C(name, _itref_ct) ), \
@@ -163,7 +163,7 @@
OR OR
DICT_OPLIST(name) DICT_OPLIST(name)
*/ */
#define DICT_OPLIST(...) \ #define M_DICT_OPLIST(...) \
M_IF_NARGS_EQ1(__VA_ARGS__) \ M_IF_NARGS_EQ1(__VA_ARGS__) \
(M_D1CT_OPLIST_P1((__VA_ARGS__, M_DEFAULT_OPLIST, M_DEFAULT_OPLIST )), \ (M_D1CT_OPLIST_P1((__VA_ARGS__, M_DEFAULT_OPLIST, M_DEFAULT_OPLIST )), \
M_D1CT_OPLIST_P1((__VA_ARGS__ ))) M_D1CT_OPLIST_P1((__VA_ARGS__ )))
@@ -171,7 +171,7 @@
/* Define the oplist of a dictionnary (DICT_SET_DEF). /* Define the oplist of a dictionnary (DICT_SET_DEF).
USAGE: DICT_SET_OPLIST(name[, oplist of the key type]) */ USAGE: DICT_SET_OPLIST(name[, oplist of the key type]) */
#define DICT_SET_OPLIST(...) \ #define M_DICT_SET_OPLIST(...) \
M_IF_NARGS_EQ1(__VA_ARGS__) \ M_IF_NARGS_EQ1(__VA_ARGS__) \
(M_D1CT_SET_OPLIST_P1((__VA_ARGS__, M_DEFAULT_OPLIST)), \ (M_D1CT_SET_OPLIST_P1((__VA_ARGS__, M_DEFAULT_OPLIST)), \
M_D1CT_SET_OPLIST_P1((__VA_ARGS__ ))) M_D1CT_SET_OPLIST_P1((__VA_ARGS__ )))
@@ -1959,5 +1959,19 @@ enum m_d1ct_oa_element_e {
\ \
M_D1CT_FUNC_ADDITIONAL_DEF2(name, key_type, key_oplist, value_type, value_oplist, isSet, dict_t, dict_it_t, it_deref_t) M_D1CT_FUNC_ADDITIONAL_DEF2(name, key_type, key_oplist, value_type, value_oplist, isSet, dict_t, dict_it_t, it_deref_t)
#if M_USE_SMALL_NAME
#define DICT_DEF2 M_DICT_DEF2
#define DICT_DEF2_AS M_DICT_DEF2_AS
#define DICT_STOREHASH_DEF2 M_DICT_STOREHASH_DEF2
#define DICT_STOREHASH_DEF2_AS M_DICT_STOREHASH_DEF2_AS
#define DICT_OA_DEF2 M_DICT_OA_DEF2
#define DICT_OA_DEF2_AS M_DICT_OA_DEF2_AS
#define DICT_SET_DEF M_DICT_SET_DEF
#define DICT_SET_DEF_AS M_DICT_SET_DEF_AS
#define DICT_OASET_DEF M_DICT_OASET_DEF
#define DICT_OASET_DEF_AS M_DICT_OASET_DEF_AS
#define DICT_OPLIST M_DICT_OPLIST
#define DICT_SET_OPLIST M_DICT_SET_OPLIST
#endif
#endif #endif
+14 -7
View File
@@ -32,8 +32,8 @@
* USAGE: * USAGE:
* FUNC_OBJ_ITF_DEF(name, retcode type, type of param1, type of param 2, ...) * FUNC_OBJ_ITF_DEF(name, retcode type, type of param1, type of param 2, ...)
*/ */
#define FUNC_OBJ_ITF_DEF(name, ...) \ #define M_FUNC_OBJ_ITF_DEF(name, ...) \
FUNC_OBJ_ITF_DEF_AS(name, M_C(name,_t), __VA_ARGS__) M_FUNC_OBJ_ITF_DEF_AS(name, M_C(name,_t), __VA_ARGS__)
/* Define a function object interface of name 'name' /* Define a function object interface of name 'name'
@@ -41,7 +41,7 @@
* USAGE: * USAGE:
* FUNC_OBJ_ITF_DEF_AS(name, name_t, retcode type, type of param1, type of param 2, ...) * FUNC_OBJ_ITF_DEF_AS(name, name_t, retcode type, type of param1, type of param 2, ...)
*/ */
#define FUNC_OBJ_ITF_DEF_AS(name, name_t, ...) \ #define M_FUNC_OBJ_ITF_DEF_AS(name, name_t, ...) \
M_BEGIN_PROTECTED_CODE \ M_BEGIN_PROTECTED_CODE \
M_IF_NARGS_EQ1(__VA_ARGS__)(M_FUNC0BJ_ITF_NO_PARAM_DEF, M_FUNC0BJ_ITF_PARAM_DEF)(name, name_t, __VA_ARGS__) \ M_IF_NARGS_EQ1(__VA_ARGS__)(M_FUNC0BJ_ITF_NO_PARAM_DEF, M_FUNC0BJ_ITF_PARAM_DEF)(name, name_t, __VA_ARGS__) \
M_END_PROTECTED_CODE M_END_PROTECTED_CODE
@@ -65,8 +65,8 @@
* USAGE/EXAMPLE: * USAGE/EXAMPLE:
* FUNC_OBJ_INS_DEF(name, base_name, (param1, ...), { return param1 * self->member1 }, (member1, int), ...) * FUNC_OBJ_INS_DEF(name, base_name, (param1, ...), { return param1 * self->member1 }, (member1, int), ...)
*/ */
#define FUNC_OBJ_INS_DEF(name, base_name, param_list, ...) \ #define M_FUNC_OBJ_INS_DEF(name, base_name, param_list, ...) \
FUNC_OBJ_INS_DEF_AS(name, M_C(name,_t), base_name, param_list, __VA_ARGS__) M_FUNC_OBJ_INS_DEF_AS(name, M_C(name,_t), base_name, param_list, __VA_ARGS__)
/* Define a function object instance of name 'name' based on the interface 'base_name' /* Define a function object instance of name 'name' based on the interface 'base_name'
@@ -76,7 +76,7 @@
* USAGE/EXAMPLE: * USAGE/EXAMPLE:
* FUNC_OBJ_INS_DEF_AS(name, name_t, base_name, (param1, ...), { return param1 * self->member1 }, (member1, int), ...) * FUNC_OBJ_INS_DEF_AS(name, name_t, base_name, (param1, ...), { return param1 * self->member1 }, (member1, int), ...)
*/ */
#define FUNC_OBJ_INS_DEF_AS(name, name_t, base_name, param_list, ...) \ #define M_FUNC_OBJ_INS_DEF_AS(name, name_t, base_name, param_list, ...) \
M_BEGIN_PROTECTED_CODE \ M_BEGIN_PROTECTED_CODE \
M_IF_NARGS_EQ1(__VA_ARGS__)(M_FUNC0BJ_INS_NO_ATTR_DEF, M_FUNC0BJ_INS_ATTR_DEF)(name, name_t, base_name, param_list, __VA_ARGS__) \ M_IF_NARGS_EQ1(__VA_ARGS__)(M_FUNC0BJ_INS_NO_ATTR_DEF, M_FUNC0BJ_INS_ATTR_DEF)(name, name_t, base_name, param_list, __VA_ARGS__) \
M_END_PROTECTED_CODE M_END_PROTECTED_CODE
@@ -86,7 +86,7 @@
* USAGE: * USAGE:
* FUNC_OBJ_INS_OPLIST(name, oplist of the attr1, ...) * FUNC_OBJ_INS_OPLIST(name, oplist of the attr1, ...)
*/ */
#define FUNC_OBJ_INS_OPLIST(...) \ #define M_FUNC_OBJ_INS_OPLIST(...) \
M_IF_NARGS_EQ1(__VA_ARGS__)(M_FUNC0BJ_INS_NO_ATTR_OPLIST, M_FUNC0BJ_INS_ATTR_OPLIST_P1)( __VA_ARGS__) M_IF_NARGS_EQ1(__VA_ARGS__)(M_FUNC0BJ_INS_NO_ATTR_OPLIST, M_FUNC0BJ_INS_ATTR_OPLIST_P1)( __VA_ARGS__)
@@ -395,5 +395,12 @@
#define M_FUNC0BJ_CONTROL_OPLIST(name, a) \ #define M_FUNC0BJ_CONTROL_OPLIST(name, a) \
M_CHECK_COMPATIBLE_OPLIST(name, M_RET_ARG1 a, M_RET_ARG2 a, M_RET_ARG3 a) M_CHECK_COMPATIBLE_OPLIST(name, M_RET_ARG1 a, M_RET_ARG2 a, M_RET_ARG3 a)
#if M_USE_SMALL_NAME
#define FUNC_OBJ_ITF_DEF M_FUNC_OBJ_ITF_DEF
#define FUNC_OBJ_ITF_DEF_AS M_FUNC_OBJ_ITF_DEF_AS
#define FUNC_OBJ_INS_DEF M_FUNC_OBJ_INS_DEF
#define FUNC_OBJ_INS_DEF_AS M_FUNC_OBJ_INS_DEF_AS
#define FUNC_OBJ_INS_OPLIST M_FUNC_OBJ_INS_OPLIST
#endif
#endif #endif
+12 -5
View File
@@ -38,7 +38,7 @@
... ...
} tmp_str_t; } tmp_str_t;
*/ */
#define ILIST_INTERFACE(name, type) \ #define M_ILIST_INTERFACE(name, type) \
struct m_il1st_head_s name struct m_il1st_head_s name
@@ -46,8 +46,8 @@
The type needs to have ILIST_INTERFACE(). The type needs to have ILIST_INTERFACE().
USAGE: USAGE:
ILIST_DEF(name, type [, oplist_of_the_type]) */ ILIST_DEF(name, type [, oplist_of_the_type]) */
#define ILIST_DEF(name, ...) \ #define M_ILIST_DEF(name, ...) \
ILIST_DEF_AS(name, M_C(name,_t), M_C(name,_it_t), __VA_ARGS__) M_ILIST_DEF_AS(name, M_C(name,_t), M_C(name,_it_t), __VA_ARGS__)
/* Define a doubly-linked intrusive list of a given type /* Define a doubly-linked intrusive list of a given type
@@ -55,7 +55,7 @@
The type needs to have ILIST_INTERFACE(). The type needs to have ILIST_INTERFACE().
USAGE: USAGE:
ILIST_DEF_AS(name, name_t, it_t, type [, oplist_of_the_type]) */ ILIST_DEF_AS(name, name_t, it_t, type [, oplist_of_the_type]) */
#define ILIST_DEF_AS(name, name_t, it_t, ...) \ #define M_ILIST_DEF_AS(name, name_t, it_t, ...) \
M_BEGIN_PROTECTED_CODE \ M_BEGIN_PROTECTED_CODE \
M_IL1ST_DEF_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \ M_IL1ST_DEF_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \
((name, __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), name_t, it_t ), \ ((name, __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), name_t, it_t ), \
@@ -66,7 +66,7 @@
/* Define the oplist of a doubly-linked instrusive list of type. /* Define the oplist of a doubly-linked instrusive list of type.
USAGE: USAGE:
ILIST_OPLIST(name [, oplist_of_the_type]) */ ILIST_OPLIST(name [, oplist_of_the_type]) */
#define ILIST_OPLIST(...) \ #define M_ILIST_OPLIST(...) \
M_IL1ST_OPLIST_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \ M_IL1ST_OPLIST_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \
((__VA_ARGS__, M_DEFAULT_OPLIST), \ ((__VA_ARGS__, M_DEFAULT_OPLIST), \
(__VA_ARGS__ ))) (__VA_ARGS__ )))
@@ -658,4 +658,11 @@ typedef struct m_il1st_head_s {
M_L1ST_ITBASE_DEF(name, type, oplist, list_t, it_t) M_L1ST_ITBASE_DEF(name, type, oplist, list_t, it_t)
#if M_USE_SMALL_NAME
#define ILIST_INTERFACE M_ILIST_INTERFACE
#define ILIST_DEF M_ILIST_DEF
#define ILIST_DEF_AS M_ILIST_DEF_AS
#define ILIST_OPLIST M_ILIST_OPLIST
#endif
#endif #endif
+16 -7
View File
@@ -32,7 +32,7 @@ M_BEGIN_PROTECTED_CODE
/* Define the oplist of a intrusive shared pointer. /* Define the oplist of a intrusive shared pointer.
USAGE: ISHARED_OPLIST(name [, oplist_of_the_type]) */ USAGE: ISHARED_OPLIST(name [, oplist_of_the_type]) */
#define ISHARED_PTR_OPLIST(...) \ #define M_ISHARED_PTR_OPLIST(...) \
M_ISHAR3D_PTR_OPLIST_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \ M_ISHAR3D_PTR_OPLIST_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \
((__VA_ARGS__, M_DEFAULT_OPLIST), \ ((__VA_ARGS__, M_DEFAULT_OPLIST), \
(__VA_ARGS__ ))) (__VA_ARGS__ )))
@@ -42,29 +42,29 @@ M_BEGIN_PROTECTED_CODE
name: name of the intrusive shared pointer. name: name of the intrusive shared pointer.
type: name of the type of the structure (aka. struct test_s) - not used currently. type: name of the type of the structure (aka. struct test_s) - not used currently.
NOTE: There can be only one interface of this kind in a type! */ NOTE: There can be only one interface of this kind in a type! */
#define ISHARED_PTR_INTERFACE(name, type) \ #define M_ISHARED_PTR_INTERFACE(name, type) \
atomic_int M_C(name, _cpt) atomic_int M_C(name, _cpt)
/* Value of the interface field for static intialization (Uses C99 designated element). */ /* Value of the interface field for static intialization (Uses C99 designated element). */
#define ISHARED_PTR_STATIC_DESIGNATED_INIT(name, type) \ #define M_ISHARED_PTR_STATIC_DESIGNATED_INIT(name, type) \
.M_C(name, _cpt) = ATOMIC_VAR_INIT(0) .M_C(name, _cpt) = ATOMIC_VAR_INIT(0)
/* Value of the interface field for static intialization (Uses C89 designated element). */ /* Value of the interface field for static intialization (Uses C89 designated element). */
#define ISHARED_PTR_STATIC_INIT(name, type) \ #define M_ISHARED_PTR_STATIC_INIT(name, type) \
ATOMIC_VAR_INIT(0) ATOMIC_VAR_INIT(0)
/* Define the intrusive shared pointer type and its static inline functions. /* Define the intrusive shared pointer type and its static inline functions.
USAGE: ISHARED_PTR_DEF(name, type, [, oplist]) */ USAGE: ISHARED_PTR_DEF(name, type, [, oplist]) */
#define ISHARED_PTR_DEF(name, ...) \ #define M_ISHARED_PTR_DEF(name, ...) \
ISHARED_PTR_DEF_AS(name, M_C(name,_t), __VA_ARGS__) M_ISHARED_PTR_DEF_AS(name, M_C(name,_t), __VA_ARGS__)
/* Define the intrusive shared pointer type and its static inline functions /* Define the intrusive shared pointer type and its static inline functions
as the name name_t as the name name_t
USAGE: ISHARED_PTR_DEF_AS(name, name_t, type, [, oplist]) */ USAGE: ISHARED_PTR_DEF_AS(name, name_t, type, [, oplist]) */
#define ISHARED_PTR_DEF_AS(name, name_t, ...) \ #define M_ISHARED_PTR_DEF_AS(name, name_t, ...) \
M_BEGIN_PROTECTED_CODE \ M_BEGIN_PROTECTED_CODE \
M_ISHAR3D_PTR_DEF_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \ M_ISHAR3D_PTR_DEF_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \
((name, __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), name_t ), \ ((name, __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), name_t ), \
@@ -232,4 +232,13 @@ M_BEGIN_PROTECTED_CODE
M_END_PROTECTED_CODE M_END_PROTECTED_CODE
#if M_USE_SMALL_NAME
#define ISHARED_PTR_OPLIST M_ISHARED_PTR_OPLIST
#define ISHARED_PTR_INTERFACE M_ISHARED_PTR_INTERFACE
#define ISHARED_PTR_STATIC_DESIGNATED_INIT M_ISHARED_PTR_STATIC_DESIGNATED_INIT
#define ISHARED_PTR_STATIC_INIT M_ISHARED_PTR_STATIC_INIT
#define ISHARED_PTR_DEF M_ISHARED_PTR_DEF
#define ISHARED_PTR_DEF_AS M_ISHARED_PTR_DEF_AS
#endif
#endif #endif
+19 -9
View File
@@ -29,14 +29,14 @@
/* Define a singly linked list of a given type. /* Define a singly linked list of a given type.
USAGE: LIST_DEF(name, type [, oplist_of_the_type]) */ USAGE: LIST_DEF(name, type [, oplist_of_the_type]) */
#define LIST_DEF(name, ...) \ #define M_LIST_DEF(name, ...) \
LIST_DEF_AS(name, M_C(name, _t), M_C(name, _it_t), __VA_ARGS__) M_LIST_DEF_AS(name, M_C(name, _t), M_C(name, _it_t), __VA_ARGS__)
/* Define a singly linked list of a given type /* Define a singly linked list of a given type
as the provided type name_t with the iterator named it_t as the provided type name_t with the iterator named it_t
USAGE: LIST_DEF_AS(name, name_t, it_t, type [, oplist_of_the_type]) */ USAGE: LIST_DEF_AS(name, name_t, it_t, type [, oplist_of_the_type]) */
#define LIST_DEF_AS(name, name_t, it_t, ...) \ #define M_LIST_DEF_AS(name, name_t, it_t, ...) \
M_BEGIN_PROTECTED_CODE \ M_BEGIN_PROTECTED_CODE \
M_L1ST_DEF_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \ M_L1ST_DEF_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \
((name, __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), name_t, it_t ), \ ((name, __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), name_t, it_t ), \
@@ -46,14 +46,14 @@
/* Define a singly linked list of a given type allowing both push. /* Define a singly linked list of a given type allowing both push.
USAGE: LIST_DUAL_PUSH_DEF_AS(name, name_t, type [, oplist_of_the_type]) */ USAGE: LIST_DUAL_PUSH_DEF_AS(name, name_t, type [, oplist_of_the_type]) */
#define LIST_DUAL_PUSH_DEF(name, ...) \ #define M_LIST_DUAL_PUSH_DEF(name, ...) \
LIST_DUAL_PUSH_DEF_AS(name, M_C(name,_t), M_C(name, _it_t), __VA_ARGS__) M_LIST_DUAL_PUSH_DEF_AS(name, M_C(name,_t), M_C(name, _it_t), __VA_ARGS__)
/* Define a singly linked list of a given type allowing both push. /* Define a singly linked list of a given type allowing both push.
as the provided type name_t with the iterator named it_t as the provided type name_t with the iterator named it_t
USAGE: LIST_DUAL_PUSH_DEF(name, type [, oplist_of_the_type]) */ USAGE: LIST_DUAL_PUSH_DEF(name, type [, oplist_of_the_type]) */
#define LIST_DUAL_PUSH_DEF_AS(name, name_t, it_t, ...) \ #define M_LIST_DUAL_PUSH_DEF_AS(name, name_t, it_t, ...) \
M_BEGIN_PROTECTED_CODE \ M_BEGIN_PROTECTED_CODE \
M_L1ST_DUAL_PUSH_DEF_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \ M_L1ST_DUAL_PUSH_DEF_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \
((name, __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), name_t, it_t ), \ ((name, __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), name_t, it_t ), \
@@ -63,7 +63,7 @@
/* Define the oplist of a list of the given type. /* Define the oplist of a list of the given type.
USAGE: LIST_OPLIST(name [, oplist_of_the_type]) */ USAGE: LIST_OPLIST(name [, oplist_of_the_type]) */
#define LIST_OPLIST(...) \ #define M_LIST_OPLIST(...) \
M_L1ST_OPLIST_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \ M_L1ST_OPLIST_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \
((__VA_ARGS__, M_DEFAULT_OPLIST ), \ ((__VA_ARGS__, M_DEFAULT_OPLIST ), \
(__VA_ARGS__ ))) (__VA_ARGS__ )))
@@ -72,7 +72,7 @@
USAGE: USAGE:
list_t global_variable = LIST_INIT_VALUE(); list_t global_variable = LIST_INIT_VALUE();
*/ */
#define LIST_INIT_VALUE() \ #define M_LIST_INIT_VALUE() \
{ NULL } { NULL }
@@ -80,7 +80,7 @@
USAGE: USAGE:
list_t global_variable = LIST_DUAL_PUSH_INIT_VALUE(); list_t global_variable = LIST_DUAL_PUSH_INIT_VALUE();
*/ */
#define LIST_DUAL_PUSH_INIT_VALUE() \ #define M_LIST_DUAL_PUSH_INIT_VALUE() \
{ { NULL, NULL } } { { NULL, NULL } }
@@ -1464,4 +1464,14 @@
M_L1ST_DUAL_PUSH_CONTRACT(list); \ M_L1ST_DUAL_PUSH_CONTRACT(list); \
} \ } \
#if M_USE_SMALL_NAME
#define LIST_DEF M_LIST_DEF
#define LIST_DEF_AS M_LIST_DEF_AS
#define LIST_DUAL_PUSH_DEF M_LIST_DUAL_PUSH_DEF
#define LIST_DUAL_PUSH_DEF_AS M_LIST_DUAL_PUSH_DEF_AS
#define LIST_OPLIST M_LIST_OPLIST
#define LIST_INIT_VALUE M_LIST_INIT_VALUE
#define LIST_DUAL_PUSH_INIT_VALUE M_LIST_DUAL_PUSH_INIT_VALUE
#endif
#endif #endif
+8 -3
View File
@@ -39,15 +39,15 @@
mempool_uint_clear(m); // Give back memory to system mempool_uint_clear(m); // Give back memory to system
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 M_MEMPOOL_DEF(name, type) \
MEMPOOL_DEF_AS(name, M_C(name,_t), type) M_MEMPOOL_DEF_AS(name, M_C(name,_t), type)
/* Fast Fixed Size thread unsafe allocator based on memory region. /* Fast Fixed Size thread unsafe allocator based on memory region.
USAGE: USAGE:
MEMPOOL_DEF_AS(memppol_uint, name_t, unsigned int) MEMPOOL_DEF_AS(memppol_uint, name_t, unsigned int)
*/ */
#define MEMPOOL_DEF_AS(name, name_t, type) \ #define M_MEMPOOL_DEF_AS(name, name_t, type) \
M_BEGIN_PROTECTED_CODE \ M_BEGIN_PROTECTED_CODE \
M_M3MPOOL_DEF_P2(name, type, name_t ) \ M_M3MPOOL_DEF_P2(name, type, name_t ) \
M_END_PROTECTED_CODE M_END_PROTECTED_CODE
@@ -176,4 +176,9 @@
M_ASSERT((mempool)->current_segment->count <= M_USE_MEMPOOL_MAX_PER_SEGMENT(type)); \ M_ASSERT((mempool)->current_segment->count <= M_USE_MEMPOOL_MAX_PER_SEGMENT(type)); \
} while (0) } while (0)
#if M_USE_SMALL_NAME
#define MEMPOOL_DEF M_MEMPOOL_DEF
#define MEMPOOL_DEF_AS M_MEMPOOL_DEF_AS
#endif
#endif #endif
+9 -4
View File
@@ -32,14 +32,14 @@
/* Define a prioqueue of a given type and its associated functions. /* Define a prioqueue of a given type and its associated functions.
USAGE: PRIOQUEUE_DEF(name, type [, oplist_of_the_type]) */ USAGE: PRIOQUEUE_DEF(name, type [, oplist_of_the_type]) */
#define PRIOQUEUE_DEF(name, ...) \ #define M_PRIOQUEUE_DEF(name, ...) \
PRIOQUEUE_DEF_AS(name, M_C(name,_t), M_C(name,_it_t), __VA_ARGS__) M_PRIOQUEUE_DEF_AS(name, M_C(name,_t), M_C(name,_it_t), __VA_ARGS__)
/* Define a prioqueue of a given type and its associated functions. /* Define a prioqueue of a given type and its associated functions.
as the name name_t with an iterator named it_t as the name name_t with an iterator named it_t
USAGE: PRIOQUEUE_DEF_AS(name, name_t, it_t, type [, oplist_of_the_type]) */ USAGE: PRIOQUEUE_DEF_AS(name, name_t, it_t, type [, oplist_of_the_type]) */
#define PRIOQUEUE_DEF_AS(name, name_t, it_t, ...) \ #define M_PRIOQUEUE_DEF_AS(name, name_t, it_t, ...) \
M_BEGIN_PROTECTED_CODE \ M_BEGIN_PROTECTED_CODE \
M_PR1OQUEUE_DEF_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \ M_PR1OQUEUE_DEF_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \
((name, __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), name_t, it_t ), \ ((name, __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), name_t, it_t ), \
@@ -49,7 +49,7 @@
/* Define the oplist of a prioqueue of type. /* Define the oplist of a prioqueue of type.
USAGE: PRIOQUEUE_OPLIST(name[, oplist of the type]) */ USAGE: PRIOQUEUE_OPLIST(name[, oplist of the type]) */
#define PRIOQUEUE_OPLIST(...) \ #define M_PRIOQUEUE_OPLIST(...) \
M_PR1OQUEUE_OPLIST_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \ M_PR1OQUEUE_OPLIST_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \
((__VA_ARGS__, M_DEFAULT_OPLIST), \ ((__VA_ARGS__, M_DEFAULT_OPLIST), \
(__VA_ARGS__ ))) (__VA_ARGS__ )))
@@ -432,5 +432,10 @@
// TODO: set all & remove all function // TODO: set all & remove all function
#if M_USE_SMALL_NAME
#define PRIOQUEUE_DEF M_PRIOQUEUE_DEF
#define PRIOQUEUE_DEF_AS M_PRIOQUEUE_DEF_AS
#define PRIOQUEUE_OPLIST M_PRIOQUEUE_OPLIST
#endif
#endif #endif
+9 -5
View File
@@ -29,14 +29,14 @@
/* Define a Red/Black binary tree of a given type. /* Define a Red/Black binary tree of a given type.
USAGE: RBTREE_DEF(name, type [, oplist_of_the_type]) */ USAGE: RBTREE_DEF(name, type [, oplist_of_the_type]) */
#define RBTREE_DEF(name, ...) \ #define M_RBTREE_DEF(name, ...) \
RBTREE_DEF_AS(name, M_C(name,_t), M_C(name,_it_t), __VA_ARGS__) M_RBTREE_DEF_AS(name, M_C(name,_t), M_C(name,_it_t), __VA_ARGS__)
/* Define a Red/Black binary tree of a given type /* Define a Red/Black binary tree of a given type
as the name name_t and the iterator it_t. as the name name_t and the iterator it_t.
USAGE: RBTREE_DEF_AS(name, name_t, it_t, type [, oplist_of_the_type]) */ USAGE: RBTREE_DEF_AS(name, name_t, it_t, type [, oplist_of_the_type]) */
#define RBTREE_DEF_AS(name, name_t, it_t, ...) \ #define M_RBTREE_DEF_AS(name, name_t, it_t, ...) \
M_BEGIN_PROTECTED_CODE \ M_BEGIN_PROTECTED_CODE \
M_RBTR33_DEF_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \ M_RBTR33_DEF_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \
((name, __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), name_t, M_C(name, _node_ct), it_t ), \ ((name, __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), name_t, M_C(name, _node_ct), it_t ), \
@@ -46,7 +46,7 @@
/* Define the oplist of a rbtree of type. /* Define the oplist of a rbtree of type.
USAGE: RBTREE_OPLIST(name [, oplist_of_the_type]) */ USAGE: RBTREE_OPLIST(name [, oplist_of_the_type]) */
#define RBTREE_OPLIST(...) \ #define M_RBTREE_OPLIST(...) \
M_RBTR33_OPLIST_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \ M_RBTR33_OPLIST_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \
((__VA_ARGS__, M_DEFAULT_OPLIST), \ ((__VA_ARGS__, M_DEFAULT_OPLIST), \
(__VA_ARGS__ ))) (__VA_ARGS__ )))
@@ -1167,6 +1167,10 @@ typedef enum {
\ \
// TODO: specialized _sort shall do nothing, but shall check the requested order. How ? // TODO: specialized _sort shall do nothing, but shall check the requested order. How ?
#if M_USE_SMALL_NAME
#define RBTREE_DEF M_RBTREE_DEF
#define RBTREE_DEF_AS M_RBTREE_DEF_AS
#define RBTREE_OPLIST M_RBTREE_OPLIST
#endif
#endif #endif
+20 -10
View File
@@ -33,7 +33,7 @@ M_BEGIN_PROTECTED_CODE
/* Define the oplist of a shared pointer. /* Define the oplist of a shared pointer.
USAGE: SHARED_OPLIST(name [, oplist_of_the_type]) */ USAGE: SHARED_OPLIST(name [, oplist_of_the_type]) */
#define SHARED_PTR_OPLIST(...) \ #define M_SHARED_PTR_OPLIST(...) \
M_SHAR3D_PTR_OPLIST_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \ M_SHAR3D_PTR_OPLIST_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \
((__VA_ARGS__, M_DEFAULT_OPLIST ), \ ((__VA_ARGS__, M_DEFAULT_OPLIST ), \
(__VA_ARGS__ ))) (__VA_ARGS__ )))
@@ -41,14 +41,14 @@ M_BEGIN_PROTECTED_CODE
/* Define shared pointer and its function. /* Define shared pointer and its function.
USAGE: SHARED_PTR_DEF(name, type, [, oplist]) */ USAGE: SHARED_PTR_DEF(name, type, [, oplist]) */
#define SHARED_PTR_DEF(name, ...) \ #define M_SHARED_PTR_DEF(name, ...) \
SHARED_PTR_DEF_AS(name, M_C(name,_t), __VA_ARGS__) M_SHARED_PTR_DEF_AS(name, M_C(name,_t), __VA_ARGS__)
/* Define shared pointer and its function /* Define shared pointer and its function
as the given name name_t as the given name name_t
USAGE: SHARED_PTR_DEF_AS(name, name_t, type, [, oplist]) */ USAGE: SHARED_PTR_DEF_AS(name, name_t, type, [, oplist]) */
#define SHARED_PTR_DEF_AS(name, name_t, ...) \ #define M_SHARED_PTR_DEF_AS(name, name_t, ...) \
M_BEGIN_PROTECTED_CODE \ M_BEGIN_PROTECTED_CODE \
M_SHAR3D_PTR_DEF_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \ M_SHAR3D_PTR_DEF_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \
((name, __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), M_SHAR3D_ATOMIC_OPLIST, name_t ), \ ((name, __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), M_SHAR3D_ATOMIC_OPLIST, name_t ), \
@@ -58,14 +58,14 @@ M_BEGIN_PROTECTED_CODE
/* Define relaxed shared pointer and its function (thread unsafe). /* Define relaxed shared pointer and its function (thread unsafe).
USAGE: SHARED_PTR_RELAXED_DEF(name, type, [, oplist]) */ USAGE: SHARED_PTR_RELAXED_DEF(name, type, [, oplist]) */
#define SHARED_PTR_RELAXED_DEF(name, ...) \ #define M_SHARED_PTR_RELAXED_DEF(name, ...) \
SHARED_PTR_RELAXED_DEF_AS(name, M_C(name,_t), __VA_ARGS__) M_SHARED_PTR_RELAXED_DEF_AS(name, M_C(name,_t), __VA_ARGS__)
/* Define relaxed shared pointer and its function (thread unsafe) /* Define relaxed shared pointer and its function (thread unsafe)
as the given name name_t as the given name name_t
USAGE: SHARED_PTR_RELAXED_DEF(name, type, [, oplist]) */ USAGE: SHARED_PTR_RELAXED_DEF(name, type, [, oplist]) */
#define SHARED_PTR_RELAXED_DEF_AS(name, name_t, ...) \ #define M_SHARED_PTR_RELAXED_DEF_AS(name, name_t, ...) \
M_BEGIN_PROTECTED_CODE \ M_BEGIN_PROTECTED_CODE \
M_SHAR3D_PTR_DEF_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \ M_SHAR3D_PTR_DEF_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \
((name, __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), M_SHAR3D_INTEGER_OPLIST, name_t ), \ ((name, __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), M_SHAR3D_INTEGER_OPLIST, name_t ), \
@@ -76,15 +76,15 @@ M_BEGIN_PROTECTED_CODE
/* Define shared resource and its function. /* Define shared resource and its function.
This is a bounded pool of resource shared by multiple owners. This is a bounded pool of resource shared by multiple owners.
USAGE: SHARED_RESOURCE_DEF(name, type, [, oplist]) */ USAGE: SHARED_RESOURCE_DEF(name, type, [, oplist]) */
#define SHARED_RESOURCE_DEF(name, ...) \ #define M_SHARED_RESOURCE_DEF(name, ...) \
SHARED_RESOURCE_DEF_AS(name, M_C(name,_t), M_C(name,_it_t), __VA_ARGS__) M_SHARED_RESOURCE_DEF_AS(name, M_C(name,_t), M_C(name,_it_t), __VA_ARGS__)
/* Define shared resource and its function /* Define shared resource and its function
as the given name named_t and the iterator it_t as the given name named_t and the iterator it_t
This is a bounded pool of resource shared by multiple owners. This is a bounded pool of resource shared by multiple owners.
USAGE: SHARED_RESOURCE_DEF_AS(name, name_t, it_t, type, [, oplist]) */ USAGE: SHARED_RESOURCE_DEF_AS(name, name_t, it_t, type, [, oplist]) */
#define SHARED_RESOURCE_DEF_AS(name, name_t, it_t, ...) \ #define M_SHARED_RESOURCE_DEF_AS(name, name_t, it_t, ...) \
M_BEGIN_PROTECTED_CODE \ M_BEGIN_PROTECTED_CODE \
M_SHAR3D_RESOURCE_DEF_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \ M_SHAR3D_RESOURCE_DEF_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \
((name, __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), name_t, it_t ), \ ((name, __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), name_t, it_t ), \
@@ -492,4 +492,14 @@ static inline int m_shar3d_integer_cref(int *p) { return *p; }
M_END_PROTECTED_CODE M_END_PROTECTED_CODE
#if M_USE_SMALL_NAME
#define SHARED_PTR_OPLIST M_SHARED_PTR_OPLIST
#define SHARED_PTR_DEF M_SHARED_PTR_DEF
#define SHARED_PTR_DEF_AS M_SHARED_PTR_DEF_AS
#define SHARED_PTR_RELAXED_DEF M_SHARED_PTR_RELAXED_DEF
#define SHARED_PTR_RELAXED_DEF_AS M_SHARED_PTR_RELAXED_DEF_AS
#define SHARED_RESOURCE_DEF M_SHARED_RESOURCE_DEF
#define SHARED_RESOURCE_DEF_AS M_SHARED_RESOURCE_DEF_AS
#endif
#endif #endif
+20 -10
View File
@@ -33,14 +33,14 @@ M_BEGIN_PROTECTED_CODE
/* Define a Single Producer Single Consummer snapshot and its functions /* Define a Single Producer Single Consummer snapshot and its functions
USAGE: SNAPSHOT_SPSC_DEF(name, type[, oplist]) */ USAGE: SNAPSHOT_SPSC_DEF(name, type[, oplist]) */
#define SNAPSHOT_SPSC_DEF(name, ...) \ #define M_SNAPSHOT_SPSC_DEF(name, ...) \
SNAPSHOT_SPSC_DEF_AS(name, M_C(name,_t), __VA_ARGS__) M_SNAPSHOT_SPSC_DEF_AS(name, M_C(name,_t), __VA_ARGS__)
/* Define a Single Producer Single Consummer snapshot and its functions /* Define a Single Producer Single Consummer snapshot and its functions
as the given name name_t as the given name name_t
USAGE: SNAPSHOT_SPSC_DEF_AS(name, name_t, type[, oplist]) */ USAGE: SNAPSHOT_SPSC_DEF_AS(name, name_t, type[, oplist]) */
#define SNAPSHOT_SPSC_DEF_AS(name, name_t, ...) \ #define M_SNAPSHOT_SPSC_DEF_AS(name, name_t, ...) \
M_BEGIN_PROTECTED_CODE \ M_BEGIN_PROTECTED_CODE \
M_SNAPSH0T_SPSC_DEF_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \ M_SNAPSH0T_SPSC_DEF_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \
((name, __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), name_t ), \ ((name, __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), name_t ), \
@@ -50,14 +50,14 @@ M_BEGIN_PROTECTED_CODE
/* Define a Single Producer Multiple Consummer snapshot and its functions /* Define a Single Producer Multiple Consummer snapshot and its functions
USAGE: SNAPSHOT_SPMC_DEF(name, type[, oplist]) */ USAGE: SNAPSHOT_SPMC_DEF(name, type[, oplist]) */
#define SNAPSHOT_SPMC_DEF(name, ...) \ #define M_SNAPSHOT_SPMC_DEF(name, ...) \
SNAPSHOT_SPMC_DEF_AS(name, M_C(name,_t), __VA_ARGS__) M_SNAPSHOT_SPMC_DEF_AS(name, M_C(name,_t), __VA_ARGS__)
/* Define a Single Producer Multiple Consummer snapshot and its functions /* Define a Single Producer Multiple Consummer snapshot and its functions
as the given name name_t as the given name name_t
USAGE: SNAPSHOT_SPMC_DEF_AS(name, type[, oplist]) */ USAGE: SNAPSHOT_SPMC_DEF_AS(name, type[, oplist]) */
#define SNAPSHOT_SPMC_DEF_AS(name, name_t, ...) \ #define M_SNAPSHOT_SPMC_DEF_AS(name, name_t, ...) \
M_BEGIN_PROTECTED_CODE \ M_BEGIN_PROTECTED_CODE \
M_SNAPSH0T_SPMC_DEF_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \ M_SNAPSH0T_SPMC_DEF_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \
((name, __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), name_t ), \ ((name, __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), name_t ), \
@@ -67,14 +67,14 @@ M_BEGIN_PROTECTED_CODE
/* Define a Multiple Producer Multiple Consummer snapshot and its functions /* Define a Multiple Producer Multiple Consummer snapshot and its functions
USAGE: SNAPSHOT_MPMC_DEF(name, type[, oplist]) */ USAGE: SNAPSHOT_MPMC_DEF(name, type[, oplist]) */
#define SNAPSHOT_MPMC_DEF(name, ...) \ #define M_SNAPSHOT_MPMC_DEF(name, ...) \
SNAPSHOT_MPMC_DEF_AS(name, M_C(name,_t), __VA_ARGS__) M_SNAPSHOT_MPMC_DEF_AS(name, M_C(name,_t), __VA_ARGS__)
/* Define a Multiple Producer Multiple Consummer snapshot and its functions /* Define a Multiple Producer Multiple Consummer snapshot and its functions
as the given name name_t as the given name name_t
USAGE: SNAPSHOT_MPMC_DEF_AS(name, name_t, type[, oplist]) */ USAGE: SNAPSHOT_MPMC_DEF_AS(name, name_t, type[, oplist]) */
#define SNAPSHOT_MPMC_DEF_AS(name, name_t, ...) \ #define M_SNAPSHOT_MPMC_DEF_AS(name, name_t, ...) \
M_BEGIN_PROTECTED_CODE \ M_BEGIN_PROTECTED_CODE \
M_SNAPSH0T_MPMC_DEF_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \ M_SNAPSH0T_MPMC_DEF_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \
((name, __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), name_t ), \ ((name, __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), name_t ), \
@@ -84,7 +84,7 @@ M_BEGIN_PROTECTED_CODE
/* Define the oplist of a snapshot (SPSC, SPMC or MPMC). /* Define the oplist of a snapshot (SPSC, SPMC or MPMC).
USAGE: SNAPSHOT_OPLIST(name[, oplist]) */ USAGE: SNAPSHOT_OPLIST(name[, oplist]) */
#define SNAPSHOT_OPLIST(...) \ #define M_SNAPSHOT_OPLIST(...) \
M_SNAPSH0T_OPLIST_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \ M_SNAPSH0T_OPLIST_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \
((__VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)() ), \ ((__VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)() ), \
(__VA_ARGS__ ))) (__VA_ARGS__ )))
@@ -778,4 +778,14 @@ m_snapsh0t_mrsw_read_end(m_snapsh0t_mrsw_ct s, unsigned int idx)
M_END_PROTECTED_CODE M_END_PROTECTED_CODE
#if M_USE_SMALL_NAME
#define SNAPSHOT_SPSC_DEF M_SNAPSHOT_SPSC_DEF
#define SNAPSHOT_SPSC_DEF_AS M_SNAPSHOT_SPSC_DEF_AS
#define SNAPSHOT_SPMC_DEF M_SNAPSHOT_SPMC_DEF
#define SNAPSHOT_SPMC_DEF_AS M_SNAPSHOT_SPMC_DEF_AS
#define SNAPSHOT_MPMC_DEF M_SNAPSHOT_MPMC_DEF
#define SNAPSHOT_MPMC_DEF_AS M_SNAPSHOT_MPMC_DEF_AS
#define SNAPSHOT_OPLIST M_SNAPSHOT_OPLIST
#endif
#endif #endif
+12 -6
View File
@@ -32,15 +32,15 @@
/* Define the tuple type and functions. /* Define the tuple type and functions.
USAGE: USAGE:
TUPLE_DEF2(name, [(field1, type1[, oplist1]), (field2, type2[, oplist2]), ...] ) */ TUPLE_DEF2(name, [(field1, type1[, oplist1]), (field2, type2[, oplist2]), ...] ) */
#define TUPLE_DEF2(name, ...) \ #define M_TUPLE_DEF2(name, ...) \
TUPLE_DEF2_AS(name, M_C(name,_t), __VA_ARGS__) M_TUPLE_DEF2_AS(name, M_C(name,_t), __VA_ARGS__)
/* Define the tuple type and functions /* Define the tuple type and functions
as the given name. as the given name.
USAGE: USAGE:
TUPLE_DEF2_AS(name, name_t, [(field1, type1[, oplist1]), (field2, type2[, oplist2]), ...] ) */ TUPLE_DEF2_AS(name, name_t, [(field1, type1[, oplist1]), (field2, type2[, oplist2]), ...] ) */
#define TUPLE_DEF2_AS(name, name_t, ...) \ #define M_TUPLE_DEF2_AS(name, name_t, ...) \
M_BEGIN_PROTECTED_CODE \ M_BEGIN_PROTECTED_CODE \
M_TUPL3_DEF2_P1( (name, name_t M_TUPL3_INJECT_GLOBAL(__VA_ARGS__)) ) \ M_TUPL3_DEF2_P1( (name, name_t M_TUPL3_INJECT_GLOBAL(__VA_ARGS__)) ) \
M_END_PROTECTED_CODE M_END_PROTECTED_CODE
@@ -48,7 +48,7 @@
/* Define the oplist of a tuple. /* Define the oplist of a tuple.
USAGE: TUPLE_OPLIST(name[, oplist of the first type, ...]) */ USAGE: TUPLE_OPLIST(name[, oplist of the first type, ...]) */
#define TUPLE_OPLIST(...) \ #define M_TUPLE_OPLIST(...) \
M_IF_NARGS_EQ1(__VA_ARGS__) \ M_IF_NARGS_EQ1(__VA_ARGS__) \
(M_TUPL3_OPLIST_P1((__VA_ARGS__, M_DEFAULT_OPLIST )), \ (M_TUPL3_OPLIST_P1((__VA_ARGS__, M_DEFAULT_OPLIST )), \
M_TUPL3_OPLIST_P1((__VA_ARGS__ ))) M_TUPL3_OPLIST_P1((__VA_ARGS__ )))
@@ -60,7 +60,7 @@
(shall be constexpr, but only supported in C++14). (shall be constexpr, but only supported in C++14).
*/ */
#ifndef __cplusplus #ifndef __cplusplus
#define TUPLE_ORDER(name, ...) \ #define M_TUPLE_ORDER(name, ...) \
( (const int[]) {M_MAP2_C(M_TUPL3_ORDER_CONVERT, name, __VA_ARGS__), 0}) ( (const int[]) {M_MAP2_C(M_TUPL3_ORDER_CONVERT, name, __VA_ARGS__), 0})
#else #else
#include <initializer_list> #include <initializer_list>
@@ -76,7 +76,7 @@ namespace m_lib {
} }
}; };
} }
#define TUPLE_ORDER(name, ...) \ #define M_TUPLE_ORDER(name, ...) \
(m_lib::m_tupl3_integer_va<M_NARGS(__VA_ARGS__,0)>({M_MAP2_C(M_TUPL3_ORDER_CONVERT, name, __VA_ARGS__), 0}).data) (m_lib::m_tupl3_integer_va<M_NARGS(__VA_ARGS__,0)>({M_MAP2_C(M_TUPL3_ORDER_CONVERT, name, __VA_ARGS__), 0}).data)
#endif #endif
@@ -738,5 +738,11 @@ namespace m_lib {
M_IF_METHOD(DEL, M_RET_ARG1(__VA_ARGS__,))(DEL(M_DELAY2(M_GET_DEL) M_RET_ARG1(__VA_ARGS__,)),), \ M_IF_METHOD(DEL, M_RET_ARG1(__VA_ARGS__,))(DEL(M_DELAY2(M_GET_DEL) M_RET_ARG1(__VA_ARGS__,)),), \
) )
#if M_USE_SMALL_NAME
#define TUPLE_DEF2 M_TUPLE_DEF2
#define TUPLE_DEF2_AS M_TUPLE_DEF2_AS
#define TUPLE_OPLIST M_TUPLE_OPLIST
#define TUPLE_ORDER M_TUPLE_ORDER
#endif
#endif #endif
+10 -4
View File
@@ -33,15 +33,15 @@
/* Define the variant type and functions. /* Define the variant type and functions.
USAGE: USAGE:
VARIANT_DEF2(name, [(field1, type1, oplist1), (field2, type2, oplist2), ...] ) */ VARIANT_DEF2(name, [(field1, type1, oplist1), (field2, type2, oplist2), ...] ) */
#define VARIANT_DEF2(name, ...) \ #define M_VARIANT_DEF2(name, ...) \
VARIANT_DEF2_AS(name, M_C(name,_t), __VA_ARGS__) M_VARIANT_DEF2_AS(name, M_C(name,_t), __VA_ARGS__)
/* Define the variant type and functions /* Define the variant type and functions
as the given name_t as the given name_t
USAGE: USAGE:
VARIANT_DEF2_AS(name, name_t, [(field1, type1, oplist1), (field2, type2, oplist2), ...] ) */ VARIANT_DEF2_AS(name, name_t, [(field1, type1, oplist1), (field2, type2, oplist2), ...] ) */
#define VARIANT_DEF2_AS(name, name_t, ...) \ #define M_VARIANT_DEF2_AS(name, name_t, ...) \
M_BEGIN_PROTECTED_CODE \ M_BEGIN_PROTECTED_CODE \
M_VAR1ANT_DEF2_P1( (name, name_t M_VAR1ANT_INJECT_GLOBAL(__VA_ARGS__)) ) \ M_VAR1ANT_DEF2_P1( (name, name_t M_VAR1ANT_INJECT_GLOBAL(__VA_ARGS__)) ) \
M_END_PROTECTED_CODE M_END_PROTECTED_CODE
@@ -49,7 +49,7 @@
/* Define the oplist of a variant. /* Define the oplist of a variant.
USAGE: VARIANT_OPLIST(name[, oplist of the first type, ...]) */ USAGE: VARIANT_OPLIST(name[, oplist of the first type, ...]) */
#define VARIANT_OPLIST(...) \ #define M_VARIANT_OPLIST(...) \
M_IF_NARGS_EQ1(__VA_ARGS__) \ M_IF_NARGS_EQ1(__VA_ARGS__) \
(M_VAR1ANT_OPLIST_P1((__VA_ARGS__, M_DEFAULT_OPLIST)), \ (M_VAR1ANT_OPLIST_P1((__VA_ARGS__, M_DEFAULT_OPLIST)), \
M_VAR1ANT_OPLIST_P1((__VA_ARGS__ ))) M_VAR1ANT_OPLIST_P1((__VA_ARGS__ )))
@@ -771,4 +771,10 @@
#define M_VAR1ANT_IF_ALL2(method1, method2, ...) \ #define M_VAR1ANT_IF_ALL2(method1, method2, ...) \
M_IF(M_REDUCE2(M_VAR1ANT_TEST_METHOD2_P, M_AND, (method1, method2), __VA_ARGS__)) M_IF(M_REDUCE2(M_VAR1ANT_TEST_METHOD2_P, M_AND, (method1, method2), __VA_ARGS__))
#if M_USE_SMALL_NAME
#define VARIANT_DEF2 M_VARIANT_DEF2
#define VARIANT_DEF2_AS M_VARIANT_DEF2_AS
#define VARIANT_OPLIST M_VARIANT_OPLIST
#endif
#endif #endif
+2 -2
View File
@@ -109,7 +109,7 @@ void f(void)
#include "m-array.h" #include "m-array.h"
ARRAY_DEF(array, int) ARRAY_DEF(array, int)
ALGO_DEF(array, M_ARRAY_OPLIST(array)) ALGO_DEF(array, M_M_ARRAY_OPLIST(array))
#elif TEST == 12 #elif TEST == 12
@@ -173,7 +173,7 @@ QUEUE_SPSC_DEF(buffer, int, BUFFER_QUEUE, DEFAULT_OPLIST)
#include "m-concurrent.h" #include "m-concurrent.h"
ARRAY_DEF(array, int) ARRAY_DEF(array, int)
CONCURRENT_DEF(lock_array, array_t, M_ARRAY_OPLIST(array)) CONCURRENT_DEF(lock_array, array_t, M_M_ARRAY_OPLIST(array))
#elif TEST == 22 #elif TEST == 22