Support of incomplete type in m-shared.
This commit is contained in:
Patrick Pelissier committed 2024-09-21 12:39:29 +02:00
1 parent 82ea4341de
commit 45b11fb49b
3 files changed
+17 -4

No files matched your search

+6
View File
@@ -4456,6 +4456,12 @@ The object oplist is expected to have at least the following operators (`CLEAR`
There are designed to work with buffers with policy `BUFFER_PUSH_INIT_POP_MOVE`
to send a shared pointer across multiple threads.
If the type is an incomplete type, you need to disable the `INIT` operator and not defined the `EMPLACE_TYPE` operator in the given oplist like this:
```C
(INIT(0), CLEAR(API_2(incomplete_clear))) )
```
`SHARED_PTR_DEF_AS` is the same as `SHARED_PTR_DEF` except the name of the type `name_t`
is provided.
+6 -4
View File
@@ -183,10 +183,12 @@ M_INLINE int m_shar3d_integer_cref(int *p) { return *p; }
typedef shared_t M_F(name, _ct); \
typedef type M_F(name, _subtype_ct); \
\
typedef struct M_F(name, _combine_s) { \
struct M_F(name, _s) ptr; \
type data; \
} M_F(name, combine_ct)[1]; \
M_IF(M_OR(M_TEST_METHOD_P(INIT, oplist), M_TEST_METHOD_ALTER_P(EMPLACE_TYPE, oplist)))( \
typedef struct M_F(name, _combine_s) { \
struct M_F(name, _s) ptr; \
type data; \
} M_F(name, combine_ct)[1]; \
, /* nothing to do */ )
/* Define the core functions */
#define M_SHAR3D_PTR_DEF_CORE(name, type, oplist, cpt_oplist, shared_t) \
+5
View File
@@ -38,6 +38,11 @@ SHARED_PTR_DEF_AS(SharedDouble, SharedDouble, double)
SHARED_PTR_RELAXED_DEF_AS(SharedDouble2, SharedDouble2, double, M_BASIC_OPLIST)
SHARED_RESOURCE_DEF_AS(SharedRessource, SharedRessource, SharedRessourceIt, double)
// Test with incomplete structure
struct incomplete_s;
extern void incomplete_clear(struct incomplete_s *ptr);
SHARED_PTR_DEF( shared_incomplete, struct incomplete_s, (INIT(0), CLEAR(API_2(incomplete_clear))) )
static int f(const shared_int_t p)
{
return *shared_int_cref(p);