assert(uatomic_read(ptr) == 122); \
v = uatomic_sub_return(ptr, 1); \
assert(v == 121); \
+ uatomic_sub(ptr, (unsigned int) 2); \
+ assert(uatomic_read(ptr) == 119); \
+ uatomic_inc(ptr); \
+ uatomic_inc(ptr); \
assert(uatomic_read(ptr) == 121); \
uatomic_and(ptr, 129); \
assert(uatomic_read(ptr) == 1); \
#define URCU_FORCE_CAST(type, arg) ((type) (arg))
#endif
+#define caa_is_signed_type(type) (((type) (-1)) < 0)
+
+#define caa_cast_long_keep_sign(v) \
+ (caa_is_signed_type(__typeof__(v)) ? (long) (v) : (unsigned long) (v))
+
#endif /* _URCU_COMPILER_H */
}
-#define uatomic_cmpxchg(addr, old, _new) \
- ((__typeof__(*(addr))) _uatomic_cmpxchg((addr), (unsigned long)(old),\
- (unsigned long)(_new), \
+#define uatomic_cmpxchg(addr, old, _new) \
+ ((__typeof__(*(addr))) _uatomic_cmpxchg((addr), \
+ caa_cast_long_keep_sign(old), \
+ caa_cast_long_keep_sign(_new),\
sizeof(*(addr))))
#define uatomic_and(addr, v) \
(_uatomic_and((addr), \
- (unsigned long)(v), \
- sizeof(*(addr))))
+ caa_cast_long_keep_sign(v), \
+ sizeof(*(addr))))
#endif
/* uatomic_or */
#define uatomic_or(addr, v) \
(_uatomic_or((addr), \
- (unsigned long)(v), \
- sizeof(*(addr))))
+ caa_cast_long_keep_sign(v), \
+ sizeof(*(addr))))
#endif
/* uatomic_add_return */
}
-#define uatomic_add_return(addr, v) \
- ((__typeof__(*(addr))) _uatomic_add_return((addr), \
- (unsigned long)(v), \
- sizeof(*(addr))))
+#define uatomic_add_return(addr, v) \
+ ((__typeof__(*(addr))) _uatomic_add_return((addr), \
+ caa_cast_long_keep_sign(v), \
+ sizeof(*(addr))))
#endif /* #ifndef uatomic_add_return */
#ifndef uatomic_xchg
}
#define uatomic_xchg(addr, v) \
- ((__typeof__(*(addr))) _uatomic_exchange((addr), (unsigned long)(v), \
+ ((__typeof__(*(addr))) _uatomic_exchange((addr), \
+ caa_cast_long_keep_sign(v), \
sizeof(*(addr))))
#endif /* #ifndef uatomic_xchg */
_uatomic_link_error();
}
-#define uatomic_and(addr, v) \
- (_uatomic_and((addr), \
- (unsigned long)(v), \
- sizeof(*(addr))))
+#define uatomic_and(addr, v) \
+ (_uatomic_and((addr), \
+ caa_cast_long_keep_sign(v), \
+ sizeof(*(addr))))
#endif /* #ifndef uatomic_and */
#ifndef uatomic_or
_uatomic_link_error();
}
-#define uatomic_or(addr, v) \
- (_uatomic_or((addr), \
- (unsigned long)(v),\
- sizeof(*(addr))))
+#define uatomic_or(addr, v) \
+ (_uatomic_or((addr), \
+ caa_cast_long_keep_sign(v), \
+ sizeof(*(addr))))
#endif /* #ifndef uatomic_or */
#ifndef uatomic_add_return
return 0;
}
-#define uatomic_add_return(addr, v) \
- ((__typeof__(*(addr))) _uatomic_add_return((addr), \
- (unsigned long)(v), \
- sizeof(*(addr))))
+#define uatomic_add_return(addr, v) \
+ ((__typeof__(*(addr))) _uatomic_add_return((addr), \
+ caa_cast_long_keep_sign(v), \
+ sizeof(*(addr))))
#endif /* #ifndef uatomic_add_return */
#ifndef uatomic_xchg
}
#define uatomic_xchg(addr, v) \
- ((__typeof__(*(addr))) _uatomic_exchange((addr), (unsigned long)(v), \
+ ((__typeof__(*(addr))) _uatomic_exchange((addr), \
+ caa_cast_long_keep_sign(v), \
sizeof(*(addr))))
#endif /* #ifndef uatomic_xchg */
#define uatomic_add(addr, v) (void)uatomic_add_return((addr), (v))
#endif
-#define uatomic_sub_return(addr, v) uatomic_add_return((addr), -(v))
-#define uatomic_sub(addr, v) uatomic_add((addr), -(v))
+#define uatomic_sub_return(addr, v) \
+ uatomic_add_return((addr), -(caa_cast_long_keep_sign(v)))
+#define uatomic_sub(addr, v) \
+ uatomic_add((addr), -(caa_cast_long_keep_sign(v)))
#ifndef uatomic_inc
#define uatomic_inc(addr) uatomic_add((addr), 1)
}
#define uatomic_xchg(addr, v) \
- ((__typeof__(*(addr))) _uatomic_exchange((addr), (unsigned long)(v), \
+ ((__typeof__(*(addr))) _uatomic_exchange((addr), \
+ caa_cast_long_keep_sign(v), \
sizeof(*(addr))))
/* cmpxchg */
}
-#define uatomic_cmpxchg(addr, old, _new) \
- ((__typeof__(*(addr))) _uatomic_cmpxchg((addr), (unsigned long)(old),\
- (unsigned long)(_new), \
+#define uatomic_cmpxchg(addr, old, _new) \
+ ((__typeof__(*(addr))) _uatomic_cmpxchg((addr), \
+ caa_cast_long_keep_sign(old), \
+ caa_cast_long_keep_sign(_new),\
sizeof(*(addr))))
/* uatomic_add_return */
}
-#define uatomic_add_return(addr, v) \
- ((__typeof__(*(addr))) _uatomic_add_return((addr), \
- (unsigned long)(v), \
- sizeof(*(addr))))
+#define uatomic_add_return(addr, v) \
+ ((__typeof__(*(addr))) _uatomic_add_return((addr), \
+ caa_cast_long_keep_sign(v), \
+ sizeof(*(addr))))
#ifdef __cplusplus
}
}
#define uatomic_xchg(addr, v) \
- (__typeof__(*(addr))) _uatomic_exchange((addr), (unsigned long)(v), \
- sizeof(*(addr)))
+ (__typeof__(*(addr))) _uatomic_exchange((addr), \
+ caa_cast_long_keep_sign(v), \
+ sizeof(*(addr)))
/* cmpxchg */
return 0;
}
-#define uatomic_cmpxchg(addr, old, _new) \
- (__typeof__(*(addr))) _uatomic_cmpxchg((addr), \
- (unsigned long)(old), \
- (unsigned long)(_new), \
+#define uatomic_cmpxchg(addr, old, _new) \
+ (__typeof__(*(addr))) _uatomic_cmpxchg((addr), \
+ caa_cast_long_keep_sign(old), \
+ caa_cast_long_keep_sign(_new),\
sizeof(*(addr)))
#ifdef __cplusplus
}
-#define uatomic_cmpxchg(addr, old, _new) \
- ((__typeof__(*(addr))) _uatomic_cmpxchg((addr), (unsigned long)(old),\
- (unsigned long)(_new), \
+#define uatomic_cmpxchg(addr, old, _new) \
+ ((__typeof__(*(addr))) _uatomic_cmpxchg((addr), \
+ caa_cast_long_keep_sign(old), \
+ caa_cast_long_keep_sign(_new), \
sizeof(*(addr))))
#ifdef __cplusplus
}
#define _uatomic_cmpxchg(addr, old, _new) \
- ((__typeof__(*(addr))) __uatomic_cmpxchg((addr), (unsigned long)(old),\
- (unsigned long)(_new), \
+ ((__typeof__(*(addr))) __uatomic_cmpxchg((addr), \
+ caa_cast_long_keep_sign(old), \
+ caa_cast_long_keep_sign(_new),\
sizeof(*(addr))))
/* xchg */
}
#define _uatomic_xchg(addr, v) \
- ((__typeof__(*(addr))) __uatomic_exchange((addr), (unsigned long)(v), \
+ ((__typeof__(*(addr))) __uatomic_exchange((addr), \
+ caa_cast_long_keep_sign(v), \
sizeof(*(addr))))
/* uatomic_add_return */
return 0;
}
-#define _uatomic_add_return(addr, v) \
- ((__typeof__(*(addr))) __uatomic_add_return((addr), \
- (unsigned long)(v), \
- sizeof(*(addr))))
+#define _uatomic_add_return(addr, v) \
+ ((__typeof__(*(addr))) __uatomic_add_return((addr), \
+ caa_cast_long_keep_sign(v), \
+ sizeof(*(addr))))
/* uatomic_and */
}
#define _uatomic_and(addr, v) \
- (__uatomic_and((addr), (unsigned long)(v), sizeof(*(addr))))
+ (__uatomic_and((addr), caa_cast_long_keep_sign(v), sizeof(*(addr))))
/* uatomic_or */
}
#define _uatomic_or(addr, v) \
- (__uatomic_or((addr), (unsigned long)(v), sizeof(*(addr))))
+ (__uatomic_or((addr), caa_cast_long_keep_sign(v), sizeof(*(addr))))
/* uatomic_add */
}
#define _uatomic_add(addr, v) \
- (__uatomic_add((addr), (unsigned long)(v), sizeof(*(addr))))
+ (__uatomic_add((addr), caa_cast_long_keep_sign(v), sizeof(*(addr))))
/* uatomic_inc */
unsigned long _new, int len);
#define compat_uatomic_set(addr, _new) \
((__typeof__(*(addr))) _compat_uatomic_set((addr), \
- (unsigned long)(_new), \
+ caa_cast_long_keep_sign(_new), \
sizeof(*(addr))))
unsigned long _new, int len);
#define compat_uatomic_xchg(addr, _new) \
((__typeof__(*(addr))) _compat_uatomic_xchg((addr), \
- (unsigned long)(_new), \
+ caa_cast_long_keep_sign(_new), \
sizeof(*(addr))))
extern unsigned long _compat_uatomic_cmpxchg(void *addr, unsigned long old,
unsigned long _new, int len);
#define compat_uatomic_cmpxchg(addr, old, _new) \
((__typeof__(*(addr))) _compat_uatomic_cmpxchg((addr), \
- (unsigned long)(old), \
- (unsigned long)(_new), \
+ caa_cast_long_keep_sign(old), \
+ caa_cast_long_keep_sign(_new), \
sizeof(*(addr))))
extern void _compat_uatomic_and(void *addr, unsigned long _new, int len);
#define compat_uatomic_and(addr, v) \
(_compat_uatomic_and((addr), \
- (unsigned long)(v), \
+ caa_cast_long_keep_sign(v), \
sizeof(*(addr))))
extern void _compat_uatomic_or(void *addr, unsigned long _new, int len);
#define compat_uatomic_or(addr, v) \
(_compat_uatomic_or((addr), \
- (unsigned long)(v), \
+ caa_cast_long_keep_sign(v), \
sizeof(*(addr))))
extern unsigned long _compat_uatomic_add_return(void *addr,
unsigned long _new, int len);
-#define compat_uatomic_add_return(addr, v) \
- ((__typeof__(*(addr))) _compat_uatomic_add_return((addr), \
- (unsigned long)(v), \
- sizeof(*(addr))))
+#define compat_uatomic_add_return(addr, v) \
+ ((__typeof__(*(addr))) _compat_uatomic_add_return((addr), \
+ caa_cast_long_keep_sign(v), \
+ sizeof(*(addr))))
#define compat_uatomic_add(addr, v) \
((void)compat_uatomic_add_return((addr), (v)))