From 2b5554c9169ea1ef93dffacb7671a00f9e7de511 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Mon, 5 Oct 2009 18:05:31 -0400 Subject: [PATCH] urcu-pointer: add more type checking Signed-off-by: Mathieu Desnoyers --- urcu-pointer-static.h | 20 ++++++++++++-------- urcu-pointer.h | 11 ++++++++--- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/urcu-pointer-static.h b/urcu-pointer-static.h index 06b8881..0a01f1f 100644 --- a/urcu-pointer-static.h +++ b/urcu-pointer-static.h @@ -71,12 +71,14 @@ * should not be freed !). */ -#define _rcu_cmpxchg_pointer(p, old, _new) \ - ({ \ - if (!__builtin_constant_p(_new) || \ - ((_new) != NULL)) \ - wmb(); \ - uatomic_cmpxchg(p, old, _new); \ +#define _rcu_cmpxchg_pointer(p, old, _new) \ + ({ \ + typeof(*p) _________pold = (old); \ + typeof(*p) _________pnew = (_new); \ + if (!__builtin_constant_p(_new) || \ + ((_new) != NULL)) \ + wmb(); \ + uatomic_cmpxchg(p, _________pold, _________pnew); \ }) /** @@ -87,19 +89,21 @@ #define _rcu_xchg_pointer(p, v) \ ({ \ + typeof(*p) _________pv = (v); \ if (!__builtin_constant_p(v) || \ ((v) != NULL)) \ wmb(); \ - uatomic_xchg(p, v); \ + uatomic_xchg(p, _________pv); \ }) #define _rcu_set_pointer(p, v) \ ({ \ + typeof(*p) _________pv = (v); \ if (!__builtin_constant_p(v) || \ ((v) != NULL)) \ wmb(); \ - STORE_SHARED(*(p), v); \ + STORE_SHARED(*(p), _________pv); \ }) /** diff --git a/urcu-pointer.h b/urcu-pointer.h index d3718b0..b10aa13 100644 --- a/urcu-pointer.h +++ b/urcu-pointer.h @@ -71,24 +71,29 @@ extern void *rcu_dereference_sym(void *p); extern void *rcu_cmpxchg_pointer_sym(void **p, void *old, void *_new); #define rcu_cmpxchg_pointer(p, old, _new) \ ({ \ + typeof(*p) _________pold = (old); \ + typeof(*p) _________pnew = (_new); \ typeof(*p) _________p1 = \ - rcu_cmpxchg_pointer_sym((void **)(p), (old), (_new));\ + rcu_cmpxchg_pointer_sym((void **)(p), _________pold, \ + _________pnew); \ (_________p1); \ }) extern void *rcu_xchg_pointer_sym(void **p, void *v); #define rcu_xchg_pointer(p, v) \ ({ \ + typeof(*p) _________pv = (v); \ typeof(*p) _________p1 = \ - rcu_xchg_pointer_sym((void **)(p), (v)); \ + rcu_xchg_pointer_sym((void **)(p), _________pv); \ (_________p1); \ }) extern void *rcu_set_pointer_sym(void **p, void *v); #define rcu_set_pointer(p, v) \ ({ \ + typeof(*p) _________pv = (v); \ typeof(*p) _________p1 = \ - rcu_set_pointer_sym((void **)(p), (v)); \ + rcu_set_pointer_sym((void **)(p), _________pv); \ }) #endif /* !_LGPL_SOURCE */ -- 2.34.1