From 3e42741a7b41b45061f6052bd71ea8dd3b2938f7 Mon Sep 17 00:00:00 2001 From: Luca Cominardi Date: Mon, 25 Mar 2024 11:50:17 +0100 Subject: [PATCH] Fix refcount cast (#384) --- include/zenoh-pico/collections/refcount.h | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/include/zenoh-pico/collections/refcount.h b/include/zenoh-pico/collections/refcount.h index 7660fdb31..76e186f74 100644 --- a/include/zenoh-pico/collections/refcount.h +++ b/include/zenoh-pico/collections/refcount.h @@ -45,7 +45,8 @@ #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 @@ -53,11 +54,11 @@ // 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 @@ -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