Fix compatibility with C++
which doesn't support designated init.
This commit is contained in:
1 parent
5533ffffaa
commit
1c5c4aa50f
3 files changed
+26
-6
No files matched your search
@@ -4031,10 +4031,22 @@ Provide the static initialization value of an object defined with a
|
||||
ISHARED\_PTR\_INTERFACE extra fields. It shall be used only for global
|
||||
variables with the \_init\_once function.
|
||||
|
||||
Usage:
|
||||
Usage (provided that the interface is used as the first element of the structure):
|
||||
|
||||
struct mystruct variable = { ISHARED_PTR_STATIC_INIT(ishared_double, struct mystruct) };
|
||||
|
||||
#### ISHARED\_PTR\_STATIC\_DESIGNATED\_INIT(name, type)
|
||||
|
||||
Provide the static initialization value of an object defined with a
|
||||
ISHARED\_PTR\_INTERFACE extra fields. It shall be used only for global
|
||||
variables with the \_init\_once function.
|
||||
|
||||
It uses designated initializers to set the right fields.
|
||||
|
||||
Usage:
|
||||
|
||||
struct mystruct variable = { ISHARED_PTR_STATIC_DESIGNATED_INIT(ishared_double, struct mystruct) };
|
||||
|
||||
#### ISHARED\_PTR\_DEF(name, type[, oplist])
|
||||
|
||||
Define the associated methods to handle the shared pointer named 'name'
|
||||
|
||||
+6
-2
@@ -46,10 +46,14 @@ M_BEGIN_PROTECTED_CODE
|
||||
atomic_int M_C(name, _cpt)
|
||||
|
||||
|
||||
/* Value of the interface field for static intialization. */
|
||||
#define ISHARED_PTR_STATIC_INIT(name, type) \
|
||||
/* Value of the interface field for static intialization (Uses C99 designated element). */
|
||||
#define ISHARED_PTR_STATIC_DESIGNATED_INIT(name, type) \
|
||||
.M_C(name, _cpt) = ATOMIC_VAR_INIT(0)
|
||||
|
||||
/* Value of the interface field for static intialization (Uses C89 designated element). */
|
||||
#define ISHARED_PTR_STATIC_INIT(name, type) \
|
||||
ATOMIC_VAR_INIT(0)
|
||||
|
||||
|
||||
/* Define the intrusive shared pointer type and its static inline functions.
|
||||
USAGE: ISHARED_PTR_DEF(name, type, [, oplist]) */
|
||||
|
||||
@@ -77,7 +77,7 @@ static void test_single(void)
|
||||
|
||||
ishared1_clear(p2);
|
||||
|
||||
struct ishared_s *x = malloc(sizeof (struct ishared_s));
|
||||
struct ishared_s *x = (struct ishared_s *) malloc(sizeof (struct ishared_s));
|
||||
assert(x != NULL);
|
||||
ishared_init_data(x);
|
||||
p1 = ishared1_init(x);
|
||||
@@ -85,7 +85,11 @@ static void test_single(void)
|
||||
ishared1_clear(p1);
|
||||
}
|
||||
|
||||
static struct ishared_s g_var = {ISHARED_PTR_STATIC_INIT(ishared2, struct ishared_s) };
|
||||
static struct ishared_s g_var = {
|
||||
ISHARED_PTR_STATIC_INIT(ishared1, struct ishared_s),
|
||||
ISHARED_PTR_STATIC_INIT(ishared2, struct ishared_s),
|
||||
{}
|
||||
};
|
||||
|
||||
static void test_static(void)
|
||||
{
|
||||
@@ -105,7 +109,7 @@ static void test_static(void)
|
||||
#define MAX_THREAD 256
|
||||
#define MAX_VAR 5
|
||||
|
||||
#define VAL(x) { ISHARED_PTR_STATIC_INIT(ishared2, struct ishared_s) }
|
||||
#define VAL(x) { ISHARED_PTR_STATIC_INIT(ishared1, struct ishared_s), ISHARED_PTR_STATIC_INIT(ishared2, struct ishared_s), {} }
|
||||
static struct ishared_s g_tab[MAX_VAR] = {
|
||||
M_MAP_C(VAL, M_SEQ(1, MAX_VAR))
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user