From e462817ecdce42b00f0cb0825e2425b08943105b Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Mon, 9 Feb 2009 00:29:58 -0500 Subject: [PATCH] Add rcu_assign_pointer rcu_assign_pointer has a memory barrier which lets the writer make sure the data has been properly written to memory before setting the pointer. Signed-off-by: Mathieu Desnoyers --- Makefile | 4 ++++ urcu.c | 2 +- urcu.h | 22 ++++++++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 8c343cc..8224567 100644 --- a/Makefile +++ b/Makefile @@ -33,6 +33,10 @@ urcu-asm.S: urcu-asm.c urcu.h urcu-asm.o: urcu-asm.c urcu.h $(CC) ${CFLAGS} -c -o $@ $(SRC_DEP) +#in progress... +urcutorture.o: urcutorture.c urcu.o urcu.h rcutorture.h + $(CC) ${CFLAGS} $(LDFLAGS) -o $@ $(SRC_DEP) + .PHONY: clean clean: diff --git a/urcu.c b/urcu.c index 31cdf6f..23a985b 100644 --- a/urcu.c +++ b/urcu.c @@ -174,7 +174,7 @@ void *urcu_publish_content(void **ptr, void *new) */ oldptr = *ptr; debug_yield_write(); - *ptr = new; + rcu_assign_pointer(*ptr, new); debug_yield_write(); switch_qparity(); diff --git a/urcu.h b/urcu.h index 01a4c68..27695d4 100644 --- a/urcu.h +++ b/urcu.h @@ -169,7 +169,29 @@ static inline void rcu_read_unlock(void) debug_yield_read(); } +/** + * rcu_assign_pointer - assign (publicize) a pointer to a newly + * initialized structure that will be dereferenced by RCU read-side + * critical sections. Returns the value assigned. + * + * Inserts memory barriers on architectures that require them + * (pretty much all of them other than x86), and also prevents + * the compiler from reordering the code that initializes the + * structure after the pointer assignment. More importantly, this + * call documents which pointers will be dereferenced by RCU read-side + * code. + */ + +#define rcu_assign_pointer(p, v) \ + ({ \ + if (!__builtin_constant_p(v) || \ + ((v) != NULL)) \ + wmb(); \ + (p) = (v); \ + }) + extern void *urcu_publish_content(void **ptr, void *new); +extern void synchronize_rcu(void); /* * Reader thread registration. -- 2.34.1