*
* Userspace RCU header. Operations on pointers.
*
- * Copyright (c) 2009 Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
+ * Copyright (c) 2009 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
* Copyright (c) 2009 Paul E. McKenney, IBM Corporation.
*
* This library is free software; you can redistribute it and/or
#include <urcu/compiler.h>
#include <urcu/arch.h>
-#include <urcu/arch_uatomic.h>
+#include <urcu/uatomic.h>
+#include <urcu/urcu-checker.h>
-#ifdef _LGPL_SOURCE
+#ifdef __cplusplus
+extern "C" {
+#endif
-#include <urcu-pointer-static.h>
+#if defined(_LGPL_SOURCE) || defined(URCU_INLINE_SMALL_FUNCTIONS)
+
+#include <urcu/static/urcu-pointer.h>
/*
* rcu_dereference(ptr)
* Fetch a RCU-protected pointer. Typically used to copy the variable ptr to a
* local variable.
*/
-#define rcu_dereference _rcu_dereference
+#define rcu_dereference(p) \
+ ({ \
+ rcu_read_ongoing_check_debug(__func__); \
+ _rcu_dereference(p); \
+ })
/*
- * rcu_cmpxchg_pointer(type **ptr, type *new, type *old)
+ * type *rcu_cmpxchg_pointer(type **ptr, type *new, type *old)
* type *rcu_xchg_pointer(type **ptr, type *new)
- * type *rcu_set_pointer(type **ptr, type *new)
+ * void rcu_set_pointer(type **ptr, type *new)
*
* RCU pointer updates.
* @ptr: address of the pointer to modify
#define rcu_xchg_pointer _rcu_xchg_pointer
#define rcu_set_pointer _rcu_set_pointer
-/*
- * type *rcu_publish_content(type **ptr, type *new)
- *
- * Exchanges the pointer and waits for quiescent state. The pointer returned
- * can be freed. You are encouraged to use either
- * - rcu_cmpxchg_pointer
- * - rcu_xchg_pointer
- * - rcu_set_pointer
- * with call_rcu(free, ptr) instead to deal with reclamation more efficiently.
- */
-#define rcu_publish_content _rcu_publish_content
-
-#else /* !_LGPL_SOURCE */
+#else /* !(defined(_LGPL_SOURCE) || defined(URCU_INLINE_SMALL_FUNCTIONS)) */
-extern void *rcu_dereference(void *p);
+extern void *rcu_dereference_sym(void *p);
+#define rcu_dereference(p) \
+ ({ \
+ __typeof__(p) _________p1 = URCU_FORCE_CAST(__typeof__(p), \
+ rcu_dereference_sym(URCU_FORCE_CAST(void *, p))); \
+ (_________p1); \
+ })
extern void *rcu_cmpxchg_pointer_sym(void **p, void *old, void *_new);
-#define rcu_cmpxchg_pointer(p, old, _new) \
- rcu_cmpxchg_pointer_sym((void **)(p), (old), (_new))
+#define rcu_cmpxchg_pointer(p, old, _new) \
+ ({ \
+ __typeof__(*(p)) _________pold = (old); \
+ __typeof__(*(p)) _________pnew = (_new); \
+ __typeof__(*(p)) _________p1 = URCU_FORCE_CAST(__typeof__(*(p)), \
+ rcu_cmpxchg_pointer_sym(URCU_FORCE_CAST(void **, p), \
+ _________pold, \
+ _________pnew)); \
+ (_________p1); \
+ })
extern void *rcu_xchg_pointer_sym(void **p, void *v);
-#define rcu_xchg_pointer(p, v) \
- rcu_xchg_pointer_sym((void **)(p), (v))
+#define rcu_xchg_pointer(p, v) \
+ ({ \
+ __typeof__(*(p)) _________pv = (v); \
+ __typeof__(*(p)) _________p1 = URCU_FORCE_CAST(__typeof__(*(p)), \
+ rcu_xchg_pointer_sym(URCU_FORCE_CAST(void **, p), \
+ _________pv)); \
+ (_________p1); \
+ })
+/*
+ * Note: rcu_set_pointer_sym returns @v because we don't want to break
+ * the ABI. At the API level, rcu_set_pointer() now returns void. Use of
+ * the return value is therefore deprecated, and will cause a build
+ * error.
+ */
extern void *rcu_set_pointer_sym(void **p, void *v);
-#define rcu_set_pointer(p, v) \
- rcu_set_pointer_sym((void **)(p), (v))
-
-extern void *rcu_publish_content_sym(void **p, void *v);
-#define rcu_publish_content(p, v) \
- rcu_publish_content_sym((void **)(p), (v))
+#define rcu_set_pointer(p, v) \
+ do { \
+ __typeof__(*(p)) _________pv = (v); \
+ (void) rcu_set_pointer_sym(URCU_FORCE_CAST(void **, p), \
+ _________pv); \
+ } while (0)
-extern void *rcu_assign_pointer_sym(void **p, void *v);
-
-#endif /* !_LGPL_SOURCE */
+#endif /* !(defined(_LGPL_SOURCE) || defined(URCU_INLINE_SMALL_FUNCTIONS)) */
/*
- * rcu_assign_pointer(type *ptr, type *new)
+ * void rcu_assign_pointer(type *ptr, type *new)
*
* Same as rcu_set_pointer, but takes the pointer to assign to rather than its
* address as first parameter. Provided for compatibility with the Linux kernel
*/
#define rcu_assign_pointer(p, v) rcu_set_pointer((&p), (v))
+#ifdef __cplusplus
+}
+#endif
+
#endif /* _URCU_POINTER_H */