Rewrite the prototype of intrusive shared object
to be more clear when there is a shared pointer and when there is not.
This commit is contained in:
1 parent
171402f99f
commit
0295eea145
2 files changed
+20
-15
No files matched your search
@@ -2379,25 +2379,30 @@ Example:
|
|||||||
|
|
||||||
The following methods are automatically and properly created by the previous macros. In the following methods, name stands for the name given to the macro which is used to identify the type.
|
The following methods are automatically and properly created by the previous macros. In the following methods, name stands for the name given to the macro which is used to identify the type.
|
||||||
|
|
||||||
##### type *name\_init(type *object)
|
##### typedef type *name_t
|
||||||
|
|
||||||
|
It will define name_t as a pointer to shared counted object.
|
||||||
|
This is a synonymous to a pointer to the object.
|
||||||
|
|
||||||
|
##### name_t name\_init(type *object)
|
||||||
|
|
||||||
Return a shared pointer to 'object' with one user counter.
|
Return a shared pointer to 'object' with one user counter.
|
||||||
The shared pointer part of 'object' shall not have been initialized.
|
The shared pointer part of 'object' shall not have been initialized.
|
||||||
This function is not thread safe.
|
This function is not thread safe.
|
||||||
|
|
||||||
##### type *name\_init\_set(type *shared)
|
##### name_t name\_init\_set(name_t shared)
|
||||||
|
|
||||||
Return a new shared pointer to the same object than the one pointed by 'shared',
|
Return a new shared pointer to the same object than the one pointed by 'shared',
|
||||||
incrementing the user counter to it.
|
incrementing the user counter to it.
|
||||||
This function is thread safe.
|
This function is thread safe.
|
||||||
|
|
||||||
##### void name\_init\_set2(type **ptr, type *shared)
|
##### void name\_init\_set2(name_t *ptr, name_t shared)
|
||||||
|
|
||||||
Set '*ptr' to a new shared pointer to 'shared',
|
Set '*ptr' to a new shared pointer to 'shared',
|
||||||
incrementing the user counter to the object pointed by 'shared'.
|
incrementing the user counter to the object pointed by 'shared'.
|
||||||
This function is thread safe (providing the ptr address is local to a thread).
|
This function is thread safe (providing the ptr address is local to a thread).
|
||||||
|
|
||||||
##### type *name\_init\_new(void)
|
##### name_t name\_init\_new(void)
|
||||||
|
|
||||||
Allocate a new object, initialize it and return an initialized shared pointer to it.
|
Allocate a new object, initialize it and return an initialized shared pointer to it.
|
||||||
This function is thread safe if the allocator and the initialize function is.
|
This function is thread safe if the allocator and the initialize function is.
|
||||||
@@ -2406,13 +2411,13 @@ The used allocation function is the ALLOC operator.
|
|||||||
In this case, it is assumed that the DEL operator has not been disabled.
|
In this case, it is assumed that the DEL operator has not been disabled.
|
||||||
|
|
||||||
|
|
||||||
##### void name\_clear(type * shared)
|
##### void name\_clear(name_t shared)
|
||||||
|
|
||||||
Clear the shared pointer, destroying the shared object if no longer
|
Clear the shared pointer, destroying the shared object if no longer
|
||||||
any other shared pointers point to the object.
|
any other shared pointers point to the object.
|
||||||
This function is thread safe.
|
This function is thread safe.
|
||||||
|
|
||||||
##### void name\_set(type **shared1, type *shared2)
|
##### void name\_set(name_t *shared1, name_t shared2)
|
||||||
|
|
||||||
Update the shared pointer '*shared1' to point to the same object than
|
Update the shared pointer '*shared1' to point to the same object than
|
||||||
the shared pointer 'shared2'.
|
the shared pointer 'shared2'.
|
||||||
|
|||||||
+9
-9
@@ -75,7 +75,7 @@
|
|||||||
typedef type *M_C(name,_t); \
|
typedef type *M_C(name,_t); \
|
||||||
typedef type M_C(name, _type_t); \
|
typedef type M_C(name, _type_t); \
|
||||||
\
|
\
|
||||||
static inline type * \
|
static inline M_C(name,_t) \
|
||||||
M_C(name, _init)(type *ptr) \
|
M_C(name, _init)(type *ptr) \
|
||||||
{ \
|
{ \
|
||||||
if (M_LIKELY (ptr != NULL)) \
|
if (M_LIKELY (ptr != NULL)) \
|
||||||
@@ -83,8 +83,8 @@
|
|||||||
return ptr; \
|
return ptr; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline type * \
|
static inline M_C(name,_t) \
|
||||||
M_C(name, _init_set)(type *shared) \
|
M_C(name, _init_set)(M_C(name,_t) shared) \
|
||||||
{ \
|
{ \
|
||||||
if (M_LIKELY (shared != NULL)) { \
|
if (M_LIKELY (shared != NULL)) { \
|
||||||
int n = atomic_fetch_add(&(shared->M_C(name, _cpt)), 1); \
|
int n = atomic_fetch_add(&(shared->M_C(name, _cpt)), 1); \
|
||||||
@@ -94,14 +94,14 @@
|
|||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline void \
|
static inline void \
|
||||||
M_C(name, _init_set2)(type ** ptr, type *shared) \
|
M_C(name, _init_set2)(M_C(name,_t) *ptr, M_C(name,_t) shared) \
|
||||||
{ \
|
{ \
|
||||||
assert (ptr != NULL); \
|
assert (ptr != NULL); \
|
||||||
*ptr = M_C(name, _init_set)(shared); \
|
*ptr = M_C(name, _init_set)(shared); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline type * \
|
static inline M_C(name,_t) \
|
||||||
M_C(name, _init_new)(void) \
|
M_C(name, _init_new)(void) \
|
||||||
{ \
|
{ \
|
||||||
type *ptr = M_GET_NEW oplist (type); \
|
type *ptr = M_GET_NEW oplist (type); \
|
||||||
if (ptr == NULL) { \
|
if (ptr == NULL) { \
|
||||||
@@ -114,7 +114,7 @@
|
|||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline void \
|
static inline void \
|
||||||
M_C(name, _clear)(type *shared) \
|
M_C(name, _clear)(M_C(name,_t) shared) \
|
||||||
{ \
|
{ \
|
||||||
if (shared != NULL) { \
|
if (shared != NULL) { \
|
||||||
if (atomic_fetch_sub(&(shared->M_C(name, _cpt)), 1) == 1) { \
|
if (atomic_fetch_sub(&(shared->M_C(name, _cpt)), 1) == 1) { \
|
||||||
@@ -125,14 +125,14 @@
|
|||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline void \
|
static inline void \
|
||||||
M_C(name, _clean)(type **shared) \
|
M_C(name, _clean)(M_C(name,_t) *shared) \
|
||||||
{ \
|
{ \
|
||||||
M_C(name, _clear)(*shared); \
|
M_C(name, _clear)(*shared); \
|
||||||
*shared = NULL; \
|
*shared = NULL; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline void \
|
static inline void \
|
||||||
M_C(name, _set)(type ** ptr, type *shared) \
|
M_C(name, _set)(M_C(name,_t) *ptr, M_C(name,_t)shared) \
|
||||||
{ \
|
{ \
|
||||||
assert (ptr != NULL); \
|
assert (ptr != NULL); \
|
||||||
if (M_LIKELY (*ptr != shared)) { \
|
if (M_LIKELY (*ptr != shared)) { \
|
||||||
|
|||||||
Reference in new issue
Block a user