Skip to content

Commit

Permalink
Merge pull request #281 from cguimaraes/fix-276
Browse files Browse the repository at this point in the history
Remove 'using namespace std' statement. Fixes #276
  • Loading branch information
p-avital authored Nov 28, 2023
2 parents b5483d7 + a4cc939 commit 4b54b5e
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions include/zenoh-pico/collections/pointer.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,21 @@
#ifndef __cplusplus
#include <stdatomic.h>
#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 <atomic>
#define z_atomic(X) std::atomic<X>
using namespace std;
#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 ------------------*/
Expand All @@ -42,7 +53,7 @@ using namespace std;
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); \
} \
Expand All @@ -53,15 +64,15 @@ using namespace std;
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) { \
name##_sptr_t *c = (name##_sptr_t *)z_malloc(sizeof(name##_sptr_t)); \
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; \
} \
Expand All @@ -71,10 +82,10 @@ using namespace std;
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); \
atomic_thread_fence(_z_memory_order_acquire); \
if (p->ptr != NULL) { \
type##_clear(p->ptr); \
z_free(p->ptr); \
Expand Down

0 comments on commit 4b54b5e

Please sign in to comment.