X-Git-Url: https://git.liburcu.org/?p=urcu.git;a=blobdiff_plain;f=urcu-qsbr-static.h;h=c0467cd0e1606c87a522e56d2299716cf6402b3e;hp=22a93b2fd7a823d21c76cbbd1ad5c6bf3b0495e4;hb=4d1ce26fea0296ff67791c881836393fdd020cf9;hpb=5eb3201d7a7dc40f01269eefa23a681473579ebc diff --git a/urcu-qsbr-static.h b/urcu-qsbr-static.h index 22a93b2..c0467cd 100644 --- a/urcu-qsbr-static.h +++ b/urcu-qsbr-static.h @@ -244,6 +244,22 @@ static inline void _rcu_thread_online(void) STORE_SHARED(p, v); \ }) +/** + * _rcu_cmpxchg_pointer - same as rcu_assign_pointer, but tests if the pointer + * is as expected by "old". If succeeds, returns the previous pointer to the + * data structure, which can be safely freed after waiting for a quiescent state + * using synchronize_rcu(). If fails (unexpected value), returns old (which + * should not be freed !). + */ + +#define _rcu_cmpxchg_pointer(p, old, _new) \ + ({ \ + if (!__builtin_constant_p(_new) || \ + ((_new) != NULL)) \ + wmb(); \ + cmpxchg(p, old, _new); \ + }) + /** * _rcu_xchg_pointer - same as rcu_assign_pointer, but returns the previous * pointer to the data structure, which can be safely freed after waiting for a