lib/ovs-atomic: Add ovs_refcount_unref_relaxed(), ovs_refcount_try_ref_rcu().
authorJarno Rajahalme <jrajahalme@nicira.com>
Mon, 7 Jul 2014 20:18:46 +0000 (13:18 -0700)
committerJarno Rajahalme <jrajahalme@nicira.com>
Mon, 7 Jul 2014 20:20:04 +0000 (13:20 -0700)
commit6969766b7557b33e7588abe5956c21c23450110c
tree80a097c558c5aecda8417d27541298491e383ef5
parent25045d755e1161fd6d0097db683a91d9bd5d2913
lib/ovs-atomic: Add ovs_refcount_unref_relaxed(), ovs_refcount_try_ref_rcu().

When a reference counted object is also RCU protected the deletion of
the object's memory is always postponed.  This allows
memory_order_relaxed to be used also for unreferencing, as RCU
quiescing provides a full memory barrier (it has to, or otherwise
there could be lingering accesses to objects after they are recycled).

Also, when access to the reference counted object is protected via a
mutex or a lock, the locking primitives provide the required memory
barrier functionality.

Also, add ovs_refcount_try_ref_rcu(), which takes a reference only if
the refcount is non-zero and returns true if a reference was taken,
false otherwise.  This can be used in combined RCU/refcount scenarios
where we have an RCU protected reference to an refcounted object, but
which may be unref'ed at any time.  If ovs_refcount_try_ref_rcu()
fails, the object may still be safely used until the current thread
quiesces.

Signed-off-by: Jarno Rajahalme <jrajahalme@nicira.com>
Acked-by: Ben Pfaff <blp@nicira.com>
lib/ovs-atomic.h
lib/ovs-rcu.c