From 16fe54738a808bdbd44083012460b6180a485e44 Mon Sep 17 00:00:00 2001 From: Carlos Guimaraes Date: Fri, 17 Nov 2023 18:08:06 +0100 Subject: [PATCH 1/4] Remove 'using namespace std' statement. Fixes #276 --- include/zenoh-pico/collections/pointer.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/include/zenoh-pico/collections/pointer.h b/include/zenoh-pico/collections/pointer.h index 8105be5be..d14195d84 100644 --- a/include/zenoh-pico/collections/pointer.h +++ b/include/zenoh-pico/collections/pointer.h @@ -26,7 +26,12 @@ #else #include #define z_atomic(X) std::atomic -using namespace std; +#define atomic_store_explicit std::atomic_store_explicit +#define atomic_fetch_add_explicit std::atomic_fetch_add_explicit +#define atomic_fetch_sub_explicit std::atomic_fetch_sub_explicit +#define memory_order_acquire std::memory_order_acquire +#define memory_order_release std::memory_order_release +#define memory_order_relaxed std::memory_order_relaxed #endif /*------------------ Internal Array Macros ------------------*/ From 244715f1990920d5e5efa608339ff28e7ae9450e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Guimar=C3=A3es?= Date: Tue, 21 Nov 2023 17:45:42 +0100 Subject: [PATCH 2/4] Avoid reusing the same naming as std --- include/zenoh-pico/collections/pointer.h | 28 ++++++++++++++---------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/include/zenoh-pico/collections/pointer.h b/include/zenoh-pico/collections/pointer.h index d14195d84..3b1fd13ca 100644 --- a/include/zenoh-pico/collections/pointer.h +++ b/include/zenoh-pico/collections/pointer.h @@ -23,15 +23,21 @@ #ifndef __cplusplus #include #define z_atomic(X) _Atomic X +#define _z_atomic_store_explicit atomic_store_explicit +#define _z_atomic_fetch_add_explicit atomic_fetch_add_explicit +#define _z_atomic_fetch_sub_explicit atomic_fetch_sub_explicit +#define _z_memory_order_acquire memory_order_acquire +#define _z_memory_order_release memory_order_release +#define _z_memory_order_relaxed memory_order_relaxed #else #include #define z_atomic(X) std::atomic -#define atomic_store_explicit std::atomic_store_explicit -#define atomic_fetch_add_explicit std::atomic_fetch_add_explicit -#define atomic_fetch_sub_explicit std::atomic_fetch_sub_explicit -#define memory_order_acquire std::memory_order_acquire -#define memory_order_release std::memory_order_release -#define memory_order_relaxed std::memory_order_relaxed +#define _z_atomic_store_explicit std::atomic_store_explicit +#define _z_atomic_fetch_add_explicit std::atomic_fetch_add_explicit +#define _z_atomic_fetch_sub_explicit std::atomic_fetch_sub_explicit +#define _z_memory_order_acquire std::memory_order_acquire +#define _z_memory_order_release std::memory_order_release +#define _z_memory_order_relaxed std::memory_order_relaxed #endif /*------------------ Internal Array Macros ------------------*/ @@ -47,7 +53,7 @@ p._cnt = (z_atomic(unsigned int) *)z_malloc(sizeof(z_atomic(unsigned int) *)); \ if (p._cnt != NULL) { \ *p.ptr = val; \ - atomic_store_explicit(p._cnt, 1, memory_order_relaxed); \ + _z_atomic_store_explicit(p._cnt, 1, _z_memory_order_relaxed); \ } else { \ z_free(p.ptr); \ } \ @@ -58,7 +64,7 @@ name##_sptr_t c; \ c._cnt = p->_cnt; \ c.ptr = p->ptr; \ - atomic_fetch_add_explicit(p->_cnt, 1, memory_order_relaxed); \ + _z_atomic_fetch_add_explicit(p->_cnt, 1, _z_memory_order_relaxed); \ return c; \ } \ static inline name##_sptr_t *name##_sptr_clone_as_ptr(name##_sptr_t *p) { \ @@ -66,7 +72,7 @@ if (c != NULL) { \ c->_cnt = p->_cnt; \ c->ptr = p->ptr; \ - atomic_fetch_add_explicit(p->_cnt, 1, memory_order_relaxed); \ + _z_atomic_fetch_add_explicit(p->_cnt, 1, _z_memory_order_relaxed); \ } \ return c; \ } \ @@ -76,10 +82,10 @@ static inline _Bool name##_sptr_drop(name##_sptr_t *p) { \ _Bool dropped = false; \ if (p->_cnt != NULL) { \ - unsigned int c = atomic_fetch_sub_explicit(p->_cnt, 1, memory_order_release); \ + unsigned int c = _z_atomic_fetch_sub_explicit(p->_cnt, 1, _z_memory_order_release); \ dropped = c == 1; \ if (dropped == true) { \ - atomic_thread_fence(memory_order_acquire); \ + _z_atomic_thread_fence(_z_memory_order_acquire); \ if (p->ptr != NULL) { \ type##_clear(p->ptr); \ z_free(p->ptr); \ From 177172c00ccf4f4565c72fb15ccae3e3e91671c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Guimar=C3=A3es?= Date: Tue, 21 Nov 2023 17:50:21 +0100 Subject: [PATCH 3/4] Avoid reusing the same naming as std --- include/zenoh-pico/collections/pointer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/zenoh-pico/collections/pointer.h b/include/zenoh-pico/collections/pointer.h index 3b1fd13ca..fecbbb412 100644 --- a/include/zenoh-pico/collections/pointer.h +++ b/include/zenoh-pico/collections/pointer.h @@ -85,7 +85,7 @@ unsigned int c = _z_atomic_fetch_sub_explicit(p->_cnt, 1, _z_memory_order_release); \ dropped = c == 1; \ if (dropped == true) { \ - _z_atomic_thread_fence(_z_memory_order_acquire); \ + atomic_thread_fence(_z_memory_order_acquire); \ if (p->ptr != NULL) { \ type##_clear(p->ptr); \ z_free(p->ptr); \ From a4cc939ab3b2fafc3f317a778ec8aff83e8e7c85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Guimar=C3=A3es?= Date: Tue, 21 Nov 2023 17:54:16 +0100 Subject: [PATCH 4/4] Fix clang format --- include/zenoh-pico/collections/pointer.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/zenoh-pico/collections/pointer.h b/include/zenoh-pico/collections/pointer.h index fecbbb412..8e1fd54e0 100644 --- a/include/zenoh-pico/collections/pointer.h +++ b/include/zenoh-pico/collections/pointer.h @@ -64,7 +64,7 @@ name##_sptr_t c; \ c._cnt = p->_cnt; \ c.ptr = p->ptr; \ - _z_atomic_fetch_add_explicit(p->_cnt, 1, _z_memory_order_relaxed); \ + _z_atomic_fetch_add_explicit(p->_cnt, 1, _z_memory_order_relaxed); \ return c; \ } \ static inline name##_sptr_t *name##_sptr_clone_as_ptr(name##_sptr_t *p) { \ @@ -85,7 +85,7 @@ unsigned int c = _z_atomic_fetch_sub_explicit(p->_cnt, 1, _z_memory_order_release); \ dropped = c == 1; \ if (dropped == true) { \ - atomic_thread_fence(_z_memory_order_acquire); \ + atomic_thread_fence(_z_memory_order_acquire); \ if (p->ptr != NULL) { \ type##_clear(p->ptr); \ z_free(p->ptr); \