From: Haomai Wang Date: Thu, 30 Apr 2015 14:20:09 +0000 (+0800) Subject: Atomic: Add CAS primitive support X-Git-Tag: v9.0.1~29^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=dd3a3b96a6d45913eb66088a8baec191ded327fd;p=ceph.git Atomic: Add CAS primitive support Signed-off-by: Haomai Wang --- diff --git a/src/include/atomic.h b/src/include/atomic.h index 960123e6e367..7fcfb311c13f 100644 --- a/src/include/atomic.h +++ b/src/include/atomic.h @@ -70,6 +70,17 @@ namespace ceph { ceph_spin_unlock(&lock); return ret; } + int cas(T o, T n) { + int success = 0; + ceph_spin_lock(&lock); + if (val == o) { + success = 1; + val = n; + } + ceph_spin_unlock(&lock); + return success; + } + private: // forbid copying atomic_spinlock_t(const atomic_spinlock_t &other); @@ -113,6 +124,10 @@ namespace ceph { // at some point. this hack can go away someday... return AO_load_full((AO_t *)&val); } + int cas(AO_t o, AO_t n) { + return AO_compare_and_swap(&val, o, n); + } + private: // forbid copying atomic_t(const atomic_t &other);