Skip to content
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

Merged
merged 2 commits into from
Apr 22, 2020

Conversation

eqvinox
Copy link
Contributor

@eqvinox eqvinox commented Apr 21, 2020

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++ :)

eqvinox added 2 commits April 21, 2020 21:38
... 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>
Copy link

@polychaeta polychaeta left a 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.

@NetDEF-CI
Copy link
Collaborator

Continuous Integration Result: SUCCESSFUL

Congratulations, 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.
For questions and feedback in regards to this CI system, please feel free to email
Martin Winter - mwinter (at) opensourcerouting.org.

Warnings Generated during build:

Checkout code: Successful with additional warnings
Report for atomlist.h | 2 issues
===============================================
< WARNING: do not add new typedefs
< #40: FILE: /tmp/f1-30323/atomlist.h:40:
Report for frratomic.h | 8 issues
===============================================
< WARNING: do not add new typedefs
< #44: FILE: /tmp/f1-30323/frratomic.h:44:
< ERROR: spaces required around that '<' (ctx:VxV)
< #44: FILE: /tmp/f1-30323/frratomic.h:44:
< ERROR: spaces required around that '>' (ctx:VxW)
< #44: FILE: /tmp/f1-30323/frratomic.h:44:
< WARNING: do not add new typedefs
< #234: FILE: /tmp/f1-30323/frratomic.h:234:

Warnings Generated during build:

Debian 10 amd64 build: Successful with additional warnings

Debian Package lintian failed for Debian 10 amd64 build:
(see full package build log at https://ci1.netdef.org/browse/FRR-FRRPULLREQ-11978/artifact/DEB10BUILD/ErrorLog/log_lintian.txt)

W: frr source: pkg-js-tools-test-is-missing
W: frr source: newer-standards-version 4.4.1 (current is 4.3.0)
W: frr source: pkg-js-tools-test-is-missing
W: frr source: newer-standards-version 4.4.1 (current is 4.3.0)
W: frr-rpki-rtrlib: changelog-file-missing-explicit-entry 6.0-2 -> 7.4-dev-20200421-08-g6127ec975-0 (missing) -> 7.4-dev-20200421-08-g6127ec975-0~deb10u1
W: frr: changelog-file-missing-explicit-entry 6.0-2 -> 7.4-dev-20200421-08-g6127ec975-0 (missing) -> 7.4-dev-20200421-08-g6127ec975-0~deb10u1
W: frr-pythontools: changelog-file-missing-explicit-entry 6.0-2 -> 7.4-dev-20200421-08-g6127ec975-0 (missing) -> 7.4-dev-20200421-08-g6127ec975-0~deb10u1
W: frr-snmp: changelog-file-missing-explicit-entry 6.0-2 -> 7.4-dev-20200421-08-g6127ec975-0 (missing) -> 7.4-dev-20200421-08-g6127ec975-0~deb10u1
W: frr-doc: changelog-file-missing-explicit-entry 6.0-2 -> 7.4-dev-20200421-08-g6127ec975-0 (missing) -> 7.4-dev-20200421-08-g6127ec975-0~deb10u1

@LabN-CI
Copy link
Collaborator

LabN-CI commented Apr 21, 2020

💚 Basic BGPD CI results: SUCCESS, 0 tests failed

Results table
_ _
Result SUCCESS git merge/6268 6127ec9
Date 04/21/2020
Start 16:56:31
Finish 17:22:27
Run-Time 25:56
Total 1815
Pass 1815
Fail 0
Valgrind-Errors 0
Valgrind-Loss 0
Details vncregress-2020-04-21-16:56:31.txt
Log autoscript-2020-04-21-16:57:28.log.bz2
Memory 494 485 425

For details, please contact louberger

@donaldsharp donaldsharp merged commit 7952857 into FRRouting:master Apr 22, 2020
@eqvinox eqvinox deleted the atomlist-cxx-compat branch April 18, 2021 07:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants