Skip to content

Commit 4b54b5e

Browse files
authored
Merge pull request #281 from cguimaraes/fix-276
Remove 'using namespace std' statement. Fixes #276
2 parents b5483d7 + a4cc939 commit 4b54b5e

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

include/zenoh-pico/collections/pointer.h

+17-6
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,21 @@
2323
#ifndef __cplusplus
2424
#include <stdatomic.h>
2525
#define z_atomic(X) _Atomic X
26+
#define _z_atomic_store_explicit atomic_store_explicit
27+
#define _z_atomic_fetch_add_explicit atomic_fetch_add_explicit
28+
#define _z_atomic_fetch_sub_explicit atomic_fetch_sub_explicit
29+
#define _z_memory_order_acquire memory_order_acquire
30+
#define _z_memory_order_release memory_order_release
31+
#define _z_memory_order_relaxed memory_order_relaxed
2632
#else
2733
#include <atomic>
2834
#define z_atomic(X) std::atomic<X>
29-
using namespace std;
35+
#define _z_atomic_store_explicit std::atomic_store_explicit
36+
#define _z_atomic_fetch_add_explicit std::atomic_fetch_add_explicit
37+
#define _z_atomic_fetch_sub_explicit std::atomic_fetch_sub_explicit
38+
#define _z_memory_order_acquire std::memory_order_acquire
39+
#define _z_memory_order_release std::memory_order_release
40+
#define _z_memory_order_relaxed std::memory_order_relaxed
3041
#endif
3142

3243
/*------------------ Internal Array Macros ------------------*/
@@ -42,7 +53,7 @@ using namespace std;
4253
p._cnt = (z_atomic(unsigned int) *)z_malloc(sizeof(z_atomic(unsigned int) *)); \
4354
if (p._cnt != NULL) { \
4455
*p.ptr = val; \
45-
atomic_store_explicit(p._cnt, 1, memory_order_relaxed); \
56+
_z_atomic_store_explicit(p._cnt, 1, _z_memory_order_relaxed); \
4657
} else { \
4758
z_free(p.ptr); \
4859
} \
@@ -53,15 +64,15 @@ using namespace std;
5364
name##_sptr_t c; \
5465
c._cnt = p->_cnt; \
5566
c.ptr = p->ptr; \
56-
atomic_fetch_add_explicit(p->_cnt, 1, memory_order_relaxed); \
67+
_z_atomic_fetch_add_explicit(p->_cnt, 1, _z_memory_order_relaxed); \
5768
return c; \
5869
} \
5970
static inline name##_sptr_t *name##_sptr_clone_as_ptr(name##_sptr_t *p) { \
6071
name##_sptr_t *c = (name##_sptr_t *)z_malloc(sizeof(name##_sptr_t)); \
6172
if (c != NULL) { \
6273
c->_cnt = p->_cnt; \
6374
c->ptr = p->ptr; \
64-
atomic_fetch_add_explicit(p->_cnt, 1, memory_order_relaxed); \
75+
_z_atomic_fetch_add_explicit(p->_cnt, 1, _z_memory_order_relaxed); \
6576
} \
6677
return c; \
6778
} \
@@ -71,10 +82,10 @@ using namespace std;
7182
static inline _Bool name##_sptr_drop(name##_sptr_t *p) { \
7283
_Bool dropped = false; \
7384
if (p->_cnt != NULL) { \
74-
unsigned int c = atomic_fetch_sub_explicit(p->_cnt, 1, memory_order_release); \
85+
unsigned int c = _z_atomic_fetch_sub_explicit(p->_cnt, 1, _z_memory_order_release); \
7586
dropped = c == 1; \
7687
if (dropped == true) { \
77-
atomic_thread_fence(memory_order_acquire); \
88+
atomic_thread_fence(_z_memory_order_acquire); \
7889
if (p->ptr != NULL) { \
7990
type##_clear(p->ptr); \
8091
z_free(p->ptr); \

0 commit comments

Comments
 (0)