X-Git-Url: https://git.liburcu.org/?p=urcu.git;a=blobdiff_plain;f=urcu-static.h;h=f819e6fc9aa07e9f4e58329661bf5a494936bb25;hp=0c6891e77ca0871f85cd1461333c0facd95bcf13;hb=4d1ce26fea0296ff67791c881836393fdd020cf9;hpb=5eb3201d7a7dc40f01269eefa23a681473579ebc;ds=sidebyside diff --git a/urcu-static.h b/urcu-static.h index 0c6891e..f819e6f 100644 --- a/urcu-static.h +++ b/urcu-static.h @@ -276,6 +276,22 @@ static inline void _rcu_read_unlock(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