Remove prefix shared_ from all definition of the functions / types of shared pointer.

This make the name shorter, give the user full control over the prefix,
give the user full power over the name,
allow more flexibility over the kind of container (allowing switch quickly),
and uniformize with variant_, tuple_ & algo_.
This is better than the current situation and all containers will switch.

==> Break API compatibility:
To fix this quickly, just add shared_ before the name into the
macro SHARED_PTR_DEF & SHARED_OPLIST.
This will generate the same name than before.
This commit is contained in:
Patrick Pelissier committed 2017-07-25 22:19:08 +02:00
1 parent 19ed56f37f
commit e8c952def8
3 files changed
+65 -64

No files matched your search

+2 -2
View File
@@ -81,7 +81,7 @@ static void perform_computation4(bigdata_t p)
/**************************************************************/ /**************************************************************/
/* Let's define a shared pointer interface around the bigdata structure */ /* Let's define a shared pointer interface around the bigdata structure */
SHARED_PTR_DEF(bigdata, bigdata_t, (INIT(bigdata_init), CLEAR(bigdata_clear))) SHARED_PTR_DEF(shared_bigdata, bigdata_t, (INIT(bigdata_init), CLEAR(bigdata_clear)))
/* Let's define the communication queue between the thread: /* Let's define the communication queue between the thread:
* - size of queue is 10, * - size of queue is 10,
@@ -90,7 +90,7 @@ SHARED_PTR_DEF(bigdata, bigdata_t, (INIT(bigdata_init), CLEAR(bigdata_clear)))
*/ */
#define MY_QUEUE_SIZE 10 #define MY_QUEUE_SIZE 10
BUFFER_DEF(bigdata, shared_bigdata_t, MY_QUEUE_SIZE, BUFFER_DEF(bigdata, shared_bigdata_t, MY_QUEUE_SIZE,
BUFFER_QUEUE|BUFFER_PUSH_INIT_POP_MOVE, SHARED_PTR_OPLIST(bigdata)) BUFFER_QUEUE|BUFFER_PUSH_INIT_POP_MOVE, SHARED_PTR_OPLIST(shared_bigdata))
/* Let's build a Thread synchros tree: /* Let's build a Thread synchros tree:
* *
+61 -60
View File
@@ -49,49 +49,50 @@
/********************************** INTERNAL ************************************/ /********************************** INTERNAL ************************************/
#define SHAREDI_PTR_OPLIST(name, oplist) ( \ #define SHAREDI_PTR_OPLIST(name, oplist) ( \
INIT(M_C3(shared_, name, _init)), \ INIT(M_C(name, _init)), \
CLEAR(M_C3(shared_, name, _clear)), \ CLEAR(M_C(name, _clear)), \
INIT_SET(M_C3(shared_, name, _init_set)), \ INIT_SET(M_C(name, _init_set)), \
SET(M_C3(shared_, name, _set)) \ SET(M_C(name, _set)) \
INIT_MOVE(M_C3(shared_, name, _init_move)), \ INIT_MOVE(M_C(name, _init_move)), \
CLEAN(M_C3(shared_, name, _clean)), \ CLEAN(M_C(name, _clean)), \
MOVE(M_C3(shared_, name, _move)), \ MOVE(M_C(name, _move)), \
SWAP(M_C3(shared_, name, _swap)) \ SWAP(M_C(name, _swap)) \
,M_IF_METHOD(NEW, oplist)(NEW(M_GET_NEW oplist),) \ ,M_IF_METHOD(NEW, oplist)(NEW(M_GET_NEW oplist),) \
,M_IF_METHOD(REALLOC, oplist)(REALLOC(M_GET_REALLOC oplist),) \ ,M_IF_METHOD(REALLOC, oplist)(REALLOC(M_GET_REALLOC oplist),) \
,M_IF_METHOD(DEL, oplist)(DEL(M_GET_DEL oplist),) \ ,M_IF_METHOD(DEL, oplist)(DEL(M_GET_DEL oplist),) \
) )
#define SHAREDI_PTR_DEF2(name, type, oplist) \ #define SHAREDI_PTR_DEF2(name, type, oplist) \
typedef struct M_C3(shared_, name, _s){ \ \
typedef struct M_C(name, _s){ \
type *data; /* Pointer to the data */ \ type *data; /* Pointer to the data */ \
atomic_int cpt; /* Counter of how many points to the data */ \ atomic_int cpt; /* Counter of how many points to the data */ \
bool combineAlloc; /* Does the data and the ptr share the slot? */ \ bool combineAlloc; /* Does the data and the ptr share the slot? */ \
} *M_C3(shared_, name, _t)[1]; \ } *M_C(name, _t)[1]; \
\ \
typedef struct M_C3(shared_contain_, name, _s) { \ typedef struct M_C(name, combine_s) { \
type data; \ type data; \
struct M_C3(shared_, name, _s) ptr; \ struct M_C(name, _s) ptr; \
} M_C3(shared_contain_, name, _t)[1]; \ } M_C(name, combine_t)[1]; \
\ \
static inline void \ static inline void \
M_C3(shared_, name, _init)(M_C3(shared_, name, _t) shared) \ M_C(name, _init)(M_C(name, _t) shared) \
{ \ { \
*shared = NULL; \ *shared = NULL; \
} \ } \
\ \
static inline void \ static inline void \
M_C3(shared_, name, _init2)(M_C3(shared_, name, _t) shared, type *data) \ M_C(name, _init2)(M_C(name, _t) shared, type *data) \
{ \ { \
struct M_C3(shared_, name, _s) *ptr; \ struct M_C(name, _s) *ptr; \
if (data == NULL) { \ if (data == NULL) { \
*shared = NULL; \ *shared = NULL; \
return; \ return; \
} \ } \
ptr = M_GET_NEW oplist (struct M_C3(shared_, name, _s)); \ ptr = M_GET_NEW oplist (struct M_C(name, _s)); \
if (ptr == NULL) { \ if (ptr == NULL) { \
M_MEMORY_FULL(sizeof(struct M_C3(shared_, name, _s))); \ M_MEMORY_FULL(sizeof(struct M_C(name, _s))); \
return; \ return; \
} \ } \
ptr->data = data; \ ptr->data = data; \
@@ -100,18 +101,18 @@
*shared = ptr; \ *shared = ptr; \
SHAREDI_CONTRACT(shared); \ SHAREDI_CONTRACT(shared); \
} \ } \
\ \
static inline void \ static inline void \
M_C3(shared_, name, _init_new)(M_C3(shared_, name, _t) shared) \ M_C(name, _init_new)(M_C(name, _t) shared) \
{ \ { \
/* NOTE: Alloc 1 struct with both structures. */ \ /* NOTE: Alloc 1 struct with both structures. */ \
struct M_C3(shared_contain_, name, _s) *p = \ struct M_C(name, combine_s) *p = \
M_GET_NEW oplist (struct M_C3(shared_contain_, name, _s)); \ M_GET_NEW oplist (struct M_C(name, combine_s)); \
if (p == NULL) { \ if (p == NULL) { \
M_MEMORY_FULL(sizeof(struct M_C3(shared_contain_, name, _s))); \ M_MEMORY_FULL(sizeof(struct M_C(name, combine_s))); \
return; \ return; \
} \ } \
struct M_C3(shared_, name, _s) *ptr = &p->ptr; \ struct M_C(name, _s) *ptr = &p->ptr; \
type *data = &p->data; \ type *data = &p->data; \
M_GET_INIT oplist(*data); \ M_GET_INIT oplist(*data); \
ptr->data = data; \ ptr->data = data; \
@@ -120,17 +121,17 @@
*shared = ptr; \ *shared = ptr; \
SHAREDI_CONTRACT(shared); \ SHAREDI_CONTRACT(shared); \
} \ } \
\ \
static inline bool \ static inline bool \
M_C3(shared_, name, _NULL_p)(const M_C3(shared_, name, _t) shared) \ M_C(name, _NULL_p)(const M_C(name, _t) shared) \
{ \ { \
SHAREDI_CONTRACT(shared); \ SHAREDI_CONTRACT(shared); \
return *shared == NULL; \ return *shared == NULL; \
} \ } \
\ \
static inline void \ static inline void \
M_C3(shared_, name, _init_set)(M_C3(shared_, name, _t) dest, \ M_C(name, _init_set)(M_C(name, _t) dest, \
const M_C3(shared_, name, _t) shared) \ const M_C(name, _t) shared) \
{ \ { \
SHAREDI_CONTRACT(shared); \ SHAREDI_CONTRACT(shared); \
assert (dest != shared); \ assert (dest != shared); \
@@ -139,9 +140,9 @@
atomic_fetch_add(&((*dest)->cpt), 1); \ atomic_fetch_add(&((*dest)->cpt), 1); \
SHAREDI_CONTRACT(dest); \ SHAREDI_CONTRACT(dest); \
} \ } \
\ \
static inline void \ static inline void \
M_C3(shared_, name, _clear)(M_C3(shared_, name, _t) dest) \ M_C(name, _clear)(M_C(name, _t) dest) \
{ \ { \
SHAREDI_CONTRACT(dest); \ SHAREDI_CONTRACT(dest); \
if (*dest != NULL) { \ if (*dest != NULL) { \
@@ -162,25 +163,25 @@
} \ } \
\ \
static inline void \ static inline void \
M_C3(shared_, name, _clean)(M_C3(shared_, name, _t) dest) \ M_C(name, _clean)(M_C(name, _t) dest) \
{ \ { \
/* NOTE: Clear will also set dest to NULL */ \ /* NOTE: Clear will also set dest to NULL */ \
M_C3(shared_, name, _clear)(dest); \ M_C(name, _clear)(dest); \
} \ } \
\ \
static inline void \ static inline void \
M_C3(shared_, name, _set)(M_C3(shared_, name, _t) dest, \ M_C(name, _set)(M_C(name, _t) dest, \
const M_C3(shared_, name, _t) shared) \ const M_C(name, _t) shared) \
{ \ { \
SHAREDI_CONTRACT(dest); \ SHAREDI_CONTRACT(dest); \
SHAREDI_CONTRACT(shared); \ SHAREDI_CONTRACT(shared); \
M_C3(shared_, name, _clear)(dest); \ M_C(name, _clear)(dest); \
M_C3(shared_, name, _init_set)(dest, shared); \ M_C(name, _init_set)(dest, shared); \
} \ } \
\ \
static inline void \ static inline void \
M_C3(shared_, name, _init_move)(M_C3(shared_, name, _t) dest, \ M_C(name, _init_move)(M_C(name, _t) dest, \
M_C3(shared_, name, _t) shared) \ M_C(name, _t) shared) \
{ \ { \
SHAREDI_CONTRACT(shared); \ SHAREDI_CONTRACT(shared); \
assert (dest != NULL && dest != shared); \ assert (dest != NULL && dest != shared); \
@@ -188,32 +189,32 @@
*shared = NULL; \ *shared = NULL; \
SHAREDI_CONTRACT(dest); \ SHAREDI_CONTRACT(dest); \
} \ } \
\ \
static inline void \ static inline void \
M_C3(shared_, name, _move)(M_C3(shared_, name, _t) dest, \ M_C(name, _move)(M_C(name, _t) dest, \
M_C3(shared_, name, _t) shared) \ M_C(name, _t) shared) \
{ \ { \
SHAREDI_CONTRACT(dest); \ SHAREDI_CONTRACT(dest); \
SHAREDI_CONTRACT(shared); \ SHAREDI_CONTRACT(shared); \
assert (dest != shared); \ assert (dest != shared); \
M_C3(shared_, name, _clear)(dest); \ M_C(name, _clear)(dest); \
M_C3(shared_, name, _init_move)(dest, shared); \ M_C(name, _init_move)(dest, shared); \
} \ } \
\ \
static inline void \ static inline void \
M_C3(shared_, name, _swap)(M_C3(shared_, name, _t) p1, \ M_C(name, _swap)(M_C(name, _t) p1, \
M_C3(shared_, name, _t) p2) \ M_C(name, _t) p2) \
{ \ { \
SHAREDI_CONTRACT(p1); \ SHAREDI_CONTRACT(p1); \
SHAREDI_CONTRACT(p2); \ SHAREDI_CONTRACT(p2); \
M_SWAP (struct M_C3(shared_, name, _s)*, *p1, *p2); \ M_SWAP (struct M_C(name, _s)*, *p1, *p2); \
SHAREDI_CONTRACT(p1); \ SHAREDI_CONTRACT(p1); \
SHAREDI_CONTRACT(p2); \ SHAREDI_CONTRACT(p2); \
} \ } \
\ \
static inline bool \ static inline bool \
M_C3(shared_, name, _equal_p)(const M_C3(shared_, name, _t) p1, \ M_C(name, _equal_p)(const M_C(name, _t) p1, \
const M_C3(shared_, name, _t) p2) \ const M_C(name, _t) p2) \
{ \ { \
SHAREDI_CONTRACT(p1); \ SHAREDI_CONTRACT(p1); \
SHAREDI_CONTRACT(p2); \ SHAREDI_CONTRACT(p2); \
@@ -221,7 +222,7 @@
} \ } \
\ \
static inline const type * \ static inline const type * \
M_C3(shared_, name, _cref)(const M_C3(shared_, name, _t) shared) \ M_C(name, _cref)(const M_C(name, _t) shared) \
{ \ { \
SHAREDI_CONTRACT(shared); \ SHAREDI_CONTRACT(shared); \
assert(*shared != NULL); \ assert(*shared != NULL); \
@@ -231,7 +232,7 @@
} \ } \
\ \
static inline type * \ static inline type * \
M_C3(shared_, name, _ref)(M_C3(shared_, name, _t) shared) \ M_C(name, _ref)(M_C(name, _t) shared) \
{ \ { \
SHAREDI_CONTRACT(shared); \ SHAREDI_CONTRACT(shared); \
assert(*shared != NULL); \ assert(*shared != NULL); \
@@ -239,7 +240,7 @@
assert (data != NULL); \ assert (data != NULL); \
return data; \ return data; \
} \ } \
/********************************** INTERNAL ************************************/ /********************************** INTERNAL ************************************/
#define SHAREDI_CONTRACT(shared) do { \ #define SHAREDI_CONTRACT(shared) do { \
+2 -2
View File
@@ -27,9 +27,9 @@
#include "coverage.h" #include "coverage.h"
START_COVERAGE START_COVERAGE
SHARED_PTR_DEF(int, int) SHARED_PTR_DEF(shared_int, int)
END_COVERAGE END_COVERAGE
SHARED_PTR_DEF(mpz, mpz_t, M_CLASSIC_OPLIST(mpz)) SHARED_PTR_DEF(shared_mpz, mpz_t, M_CLASSIC_OPLIST(mpz))
static int f(const shared_int_t p) static int f(const shared_int_t p)
{ {