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

Fix refcount cast #384

Merged
merged 1 commit into from
Mar 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions include/zenoh-pico/collections/refcount.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,20 @@
#define _ZP_RC_CNT_TYPE _z_atomic(unsigned int)
#define _ZP_RC_OP_INIT_CNT _z_atomic_store_explicit(&p.in->_cnt, (unsigned int)1, _z_memory_order_relaxed);
#define _ZP_RC_OP_INCR_CNT _z_atomic_fetch_add_explicit(&p->in->_cnt, (unsigned int)1, _z_memory_order_relaxed);
#define _ZP_RC_OP_DECR_AND_CMP _z_atomic_fetch_sub_explicit(&p->in->_cnt, (unsigned int)1, _z_memory_order_release) > 1
#define _ZP_RC_OP_DECR_AND_CMP \
_z_atomic_fetch_sub_explicit(&p->in->_cnt, (unsigned int)1, _z_memory_order_release) > (unsigned int)1
#define _ZP_RC_OP_SYNC atomic_thread_fence(_z_memory_order_acquire);

#else // ZENOH_C_STANDARD == 99
#ifdef ZENOH_COMPILER_GCC

// c99 gcc sync builtin variant
#define _ZP_RC_CNT_TYPE unsigned int
#define _ZP_RC_OP_INIT_CNT \
__sync_fetch_and_and(&p.in->_cnt, 0); \
__sync_fetch_and_add(&p.in->_cnt, 1);
#define _ZP_RC_OP_INCR_CNT __sync_fetch_and_add(&p->in->_cnt, 1);
#define _ZP_RC_OP_DECR_AND_CMP __sync_fetch_and_sub(&p->in->_cnt, 1) > 1
#define _ZP_RC_OP_INIT_CNT \
__sync_fetch_and_and(&p.in->_cnt, (unsigned int)0); \
__sync_fetch_and_add(&p.in->_cnt, (unsigned int)1);
#define _ZP_RC_OP_INCR_CNT __sync_fetch_and_add(&p->in->_cnt, (unsigned int)1);
#define _ZP_RC_OP_DECR_AND_CMP __sync_fetch_and_sub(&p->in->_cnt, (unsigned int)1) > (unsigned int)1
#define _ZP_RC_OP_SYNC __sync_synchronize();

#else // !ZENOH_COMPILER_GCC
Expand All @@ -76,9 +77,9 @@

// Single thread variant
#define _ZP_RC_CNT_TYPE unsigned int
#define _ZP_RC_OP_INIT_CNT p.in->_cnt = 1;
#define _ZP_RC_OP_INCR_CNT p->in->_cnt += 1;
#define _ZP_RC_OP_DECR_AND_CMP p->in->_cnt-- > 1
#define _ZP_RC_OP_INIT_CNT p.in->_cnt = (unsigned int)1;
#define _ZP_RC_OP_INCR_CNT p->in->_cnt += (unsigned int)1;
#define _ZP_RC_OP_DECR_AND_CMP p->in->_cnt-- > (unsigned int)1
#define _ZP_RC_OP_SYNC

#endif // Z_FEATURE_MULTI_THREAD == 1
Expand Down
Loading