-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lib: make atomlist code C++ compatible #6268
lib: make atomlist code C++ compatible #6268
Conversation
... by using `atomic_atomptr_t`. Other ideas seemed worse. Signed-off-by: David Lamparter <equinox@diac24.net>
... by dropping seqlock.h from the header's includes; it's only needed in the C code in frrcu.c. Signed-off-by: David Lamparter <equinox@diac24.net>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution to FRR!
Click for style suggestions
To apply these suggestions:
curl -s https://gist.githubusercontent.com/polychaeta/f23d707e154384f631abf248fe7cb230/raw/712c987efc49611fb6e7c327589660c3e08db190/cr_6268_1587498029.diff | git apply
diff --git a/lib/atomlist.h b/lib/atomlist.h
index 96476c2cd..371f0959a 100644
--- a/lib/atomlist.h
+++ b/lib/atomlist.h
@@ -36,8 +36,8 @@
*/
/* atomic_atomptr_t may look a bit odd, it's for the sake of C++ compat */
-typedef uintptr_t atomptr_t;
-typedef atomic_uintptr_t atomic_atomptr_t;
+typedef uintptr_t atomptr_t;
+typedef atomic_uintptr_t atomic_atomptr_t;
#define ATOMPTR_MASK (UINTPTR_MAX - 3)
#define ATOMPTR_LOCK (1)
@@ -132,41 +132,63 @@ struct prefix ## _item { struct atomlist_item ai; };
#define INIT_ATOMLIST(var) { }
#define DECLARE_ATOMLIST(prefix, type, field) \
-macro_inline void prefix ## _add_head(struct prefix##_head *h, type *item) \
-{ atomlist_add_head(&h->ah, &item->field.ai); } \
-macro_inline void prefix ## _add_tail(struct prefix##_head *h, type *item) \
-{ atomlist_add_tail(&h->ah, &item->field.ai); } \
-macro_inline void prefix ## _del_hint(struct prefix##_head *h, type *item, \
- atomic_atomptr_t *hint) \
-{ atomlist_del_hint(&h->ah, &item->field.ai, hint); } \
-macro_inline type *prefix ## _del(struct prefix##_head *h, type *item) \
-{ atomlist_del_hint(&h->ah, &item->field.ai, NULL); \
- /* TODO: Return NULL if not found */ \
- return item; } \
-macro_inline type *prefix ## _pop(struct prefix##_head *h) \
-{ char *p = (char *)atomlist_pop(&h->ah); \
- return p ? (type *)(p - offsetof(type, field)) : NULL; } \
-macro_inline type *prefix ## _first(struct prefix##_head *h) \
-{ char *p = atomptr_p(atomic_load_explicit(&h->ah.first, \
- memory_order_acquire)); \
- return p ? (type *)(p - offsetof(type, field)) : NULL; } \
-macro_inline type *prefix ## _next(struct prefix##_head *h, type *item) \
-{ char *p = atomptr_p(atomic_load_explicit(&item->field.ai.next, \
- memory_order_acquire)); \
- return p ? (type *)(p - offsetof(type, field)) : NULL; } \
-macro_inline type *prefix ## _next_safe(struct prefix##_head *h, type *item) \
-{ return item ? prefix##_next(h, item) : NULL; } \
-macro_inline size_t prefix ## _count(struct prefix##_head *h) \
-{ return atomic_load_explicit(&h->ah.count, memory_order_relaxed); } \
-macro_inline void prefix ## _init(struct prefix##_head *h) \
-{ \
- memset(h, 0, sizeof(*h)); \
-} \
-macro_inline void prefix ## _fini(struct prefix##_head *h) \
-{ \
- assert(prefix ## _count(h) == 0); \
- memset(h, 0, sizeof(*h)); \
-} \
+ macro_inline void prefix##_add_head(struct prefix##_head *h, \
+ type *item) \
+ { \
+ atomlist_add_head(&h->ah, &item->field.ai); \
+ } \
+ macro_inline void prefix##_add_tail(struct prefix##_head *h, \
+ type *item) \
+ { \
+ atomlist_add_tail(&h->ah, &item->field.ai); \
+ } \
+ macro_inline void prefix##_del_hint( \
+ struct prefix##_head *h, type *item, atomic_atomptr_t *hint) \
+ { \
+ atomlist_del_hint(&h->ah, &item->field.ai, hint); \
+ } \
+ macro_inline type *prefix##_del(struct prefix##_head *h, type *item) \
+ { \
+ atomlist_del_hint(&h->ah, &item->field.ai, NULL); \
+ /* TODO: Return NULL if not found */ \
+ return item; \
+ } \
+ macro_inline type *prefix##_pop(struct prefix##_head *h) \
+ { \
+ char *p = (char *)atomlist_pop(&h->ah); \
+ return p ? (type *)(p - offsetof(type, field)) : NULL; \
+ } \
+ macro_inline type *prefix##_first(struct prefix##_head *h) \
+ { \
+ char *p = atomptr_p(atomic_load_explicit( \
+ &h->ah.first, memory_order_acquire)); \
+ return p ? (type *)(p - offsetof(type, field)) : NULL; \
+ } \
+ macro_inline type *prefix##_next(struct prefix##_head *h, type *item) \
+ { \
+ char *p = atomptr_p(atomic_load_explicit( \
+ &item->field.ai.next, memory_order_acquire)); \
+ return p ? (type *)(p - offsetof(type, field)) : NULL; \
+ } \
+ macro_inline type *prefix##_next_safe(struct prefix##_head *h, \
+ type *item) \
+ { \
+ return item ? prefix##_next(h, item) : NULL; \
+ } \
+ macro_inline size_t prefix##_count(struct prefix##_head *h) \
+ { \
+ return atomic_load_explicit(&h->ah.count, \
+ memory_order_relaxed); \
+ } \
+ macro_inline void prefix##_init(struct prefix##_head *h) \
+ { \
+ memset(h, 0, sizeof(*h)); \
+ } \
+ macro_inline void prefix##_fini(struct prefix##_head *h) \
+ { \
+ assert(prefix##_count(h) == 0); \
+ memset(h, 0, sizeof(*h)); \
+ } \
/* ... */
/* add_head:
@@ -193,7 +215,7 @@ void atomlist_add_tail(struct atomlist_head *h, struct atomlist_item *item);
* reads starting later.
*/
void atomlist_del_hint(struct atomlist_head *h, struct atomlist_item *item,
- atomic_atomptr_t *hint);
+ atomic_atomptr_t *hint);
/* pop:
*
@@ -223,78 +245,78 @@ struct prefix ## _item { struct atomsort_item ai; };
#define INIT_ATOMSORT_NONUNIQ(var) { }
#define _DECLARE_ATOMSORT(prefix, type, field, cmpfn_nuq, cmpfn_uq) \
-macro_inline void prefix ## _init(struct prefix##_head *h) \
-{ \
- memset(h, 0, sizeof(*h)); \
-} \
-macro_inline void prefix ## _fini(struct prefix##_head *h) \
-{ \
- assert(h->ah.count == 0); \
- memset(h, 0, sizeof(*h)); \
-} \
-macro_inline type *prefix ## _add(struct prefix##_head *h, type *item) \
-{ \
- struct atomsort_item *p; \
- p = atomsort_add(&h->ah, &item->field.ai, cmpfn_uq); \
- return container_of_null(p, type, field.ai); \
-} \
-macro_inline type *prefix ## _first(struct prefix##_head *h) \
-{ \
- struct atomsort_item *p; \
- p = atomptr_p(atomic_load_explicit(&h->ah.first, \
- memory_order_acquire)); \
- return container_of_null(p, type, field.ai); \
-} \
-macro_inline type *prefix ## _next(struct prefix##_head *h, type *item) \
-{ \
- struct atomsort_item *p; \
- p = atomptr_p(atomic_load_explicit(&item->field.ai.next, \
- memory_order_acquire)); \
- return container_of_null(p, type, field.ai); \
-} \
-macro_inline type *prefix ## _next_safe(struct prefix##_head *h, type *item) \
-{ \
- return item ? prefix##_next(h, item) : NULL; \
-} \
-atomic_find_warn \
-macro_inline type *prefix ## _find_gteq(struct prefix##_head *h, \
- const type *item) \
-{ \
- type *p = prefix ## _first(h); \
- while (p && cmpfn_nuq(&p->field.ai, &item->field.ai) < 0) \
- p = prefix ## _next(h, p); \
- return p; \
-} \
-atomic_find_warn \
-macro_inline type *prefix ## _find_lt(struct prefix##_head *h, \
- const type *item) \
-{ \
- type *p = prefix ## _first(h), *prev = NULL; \
- while (p && cmpfn_nuq(&p->field.ai, &item->field.ai) < 0) \
- p = prefix ## _next(h, (prev = p)); \
- return prev; \
-} \
-macro_inline void prefix ## _del_hint(struct prefix##_head *h, type *item, \
- atomic_atomptr_t *hint) \
-{ \
- atomsort_del_hint(&h->ah, &item->field.ai, hint); \
-} \
-macro_inline type *prefix ## _del(struct prefix##_head *h, type *item) \
-{ \
- atomsort_del_hint(&h->ah, &item->field.ai, NULL); \
- /* TODO: Return NULL if not found */ \
- return item; \
-} \
-macro_inline size_t prefix ## _count(struct prefix##_head *h) \
-{ \
- return atomic_load_explicit(&h->ah.count, memory_order_relaxed); \
-} \
-macro_inline type *prefix ## _pop(struct prefix##_head *h) \
-{ \
- struct atomsort_item *p = atomsort_pop(&h->ah); \
- return p ? container_of(p, type, field.ai) : NULL; \
-} \
-/* ... */
+ macro_inline void prefix##_init(struct prefix##_head *h) \
+ { \
+ memset(h, 0, sizeof(*h)); \
+ } \
+ macro_inline void prefix##_fini(struct prefix##_head *h) \
+ { \
+ assert(h->ah.count == 0); \
+ memset(h, 0, sizeof(*h)); \
+ } \
+ macro_inline type *prefix##_add(struct prefix##_head *h, type *item) \
+ { \
+ struct atomsort_item *p; \
+ p = atomsort_add(&h->ah, &item->field.ai, cmpfn_uq); \
+ return container_of_null(p, type, field.ai); \
+ } \
+ macro_inline type *prefix##_first(struct prefix##_head *h) \
+ { \
+ struct atomsort_item *p; \
+ p = atomptr_p(atomic_load_explicit(&h->ah.first, \
+ memory_order_acquire)); \
+ return container_of_null(p, type, field.ai); \
+ } \
+ macro_inline type *prefix##_next(struct prefix##_head *h, type *item) \
+ { \
+ struct atomsort_item *p; \
+ p = atomptr_p(atomic_load_explicit(&item->field.ai.next, \
+ memory_order_acquire)); \
+ return container_of_null(p, type, field.ai); \
+ } \
+ macro_inline type *prefix##_next_safe(struct prefix##_head *h, \
+ type *item) \
+ { \
+ return item ? prefix##_next(h, item) : NULL; \
+ } \
+ atomic_find_warn macro_inline type *prefix##_find_gteq( \
+ struct prefix##_head *h, const type *item) \
+ { \
+ type *p = prefix##_first(h); \
+ while (p && cmpfn_nuq(&p->field.ai, &item->field.ai) < 0) \
+ p = prefix##_next(h, p); \
+ return p; \
+ } \
+ atomic_find_warn macro_inline type *prefix##_find_lt( \
+ struct prefix##_head *h, const type *item) \
+ { \
+ type *p = prefix##_first(h), *prev = NULL; \
+ while (p && cmpfn_nuq(&p->field.ai, &item->field.ai) < 0) \
+ p = prefix##_next(h, (prev = p)); \
+ return prev; \
+ } \
+ macro_inline void prefix##_del_hint( \
+ struct prefix##_head *h, type *item, atomic_atomptr_t *hint) \
+ { \
+ atomsort_del_hint(&h->ah, &item->field.ai, hint); \
+ } \
+ macro_inline type *prefix##_del(struct prefix##_head *h, type *item) \
+ { \
+ atomsort_del_hint(&h->ah, &item->field.ai, NULL); \
+ /* TODO: Return NULL if not found */ \
+ return item; \
+ } \
+ macro_inline size_t prefix##_count(struct prefix##_head *h) \
+ { \
+ return atomic_load_explicit(&h->ah.count, \
+ memory_order_relaxed); \
+ } \
+ macro_inline type *prefix##_pop(struct prefix##_head *h) \
+ { \
+ struct atomsort_item *p = atomsort_pop(&h->ah); \
+ return p ? container_of(p, type, field.ai) : NULL; \
+ } \
+ /* ... */
#define PREDECL_ATOMSORT_UNIQ(prefix) \
_PREDECL_ATOMSORT(prefix)
@@ -356,8 +378,8 @@ struct atomsort_item *atomsort_add(struct atomsort_head *h,
const struct atomsort_item *,
const struct atomsort_item *));
-void atomsort_del_hint(struct atomsort_head *h,
- struct atomsort_item *item, atomic_atomptr_t *hint);
+void atomsort_del_hint(struct atomsort_head *h, struct atomsort_item *item,
+ atomic_atomptr_t *hint);
struct atomsort_item *atomsort_pop(struct atomsort_head *h);
diff --git a/lib/frratomic.h b/lib/frratomic.h
index bafc6445e..f5faa6a41 100644
--- a/lib/frratomic.h
+++ b/lib/frratomic.h
@@ -41,7 +41,7 @@ using std::memory_order_seq_cst;
typedef std::atomic<bool> atomic_bool;
typedef std::atomic<size_t> atomic_size_t;
typedef std::atomic<uint_fast32_t> atomic_uint_fast32_t;
-typedef std::atomic<uintptr_t> atomic_uintptr_t;
+typedef std::atomic<uintptr_t> atomic_uintptr_t;
#elif defined(HAVE_STDATOMIC_H)
#include <stdatomic.h>
@@ -231,7 +231,7 @@ typedef std::atomic<uintptr_t> atomic_uintptr_t;
typedef _Atomic bool atomic_bool;
typedef _Atomic size_t atomic_size_t;
typedef _Atomic uint_fast32_t atomic_uint_fast32_t;
-typedef _Atomic uintptr_t atomic_uintptr_t;
+typedef _Atomic uintptr_t atomic_uintptr_t;
#endif
#endif /* _FRRATOMIC_H */
If you are a new contributor to FRR, please see our contributing guidelines.
Continuous Integration Result: SUCCESSFULCongratulations, this patch passed basic tests Tested-by: NetDEF / OpenSourceRouting.org CI System CI System Testrun URL: https://ci1.netdef.org/browse/FRR-FRRPULLREQ-11978/ This is a comment from an automated CI system. Warnings Generated during build:Checkout code: Successful with additional warnings
Warnings Generated during build:Debian 10 amd64 build: Successful with additional warningsDebian Package lintian failed for Debian 10 amd64 build:
|
💚 Basic BGPD CI results: SUCCESS, 0 tests failedResults table
For details, please contact louberger |
since the cleaned-up/rewritten logging code uses atomlist.h, it preferably be C++ compatible... lest we not be able to log anything from C++ :)