]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/xen.git/commitdiff
atomic: replace atomic_compareandswap() with atomic_cmpxchg()
authorDavid Vrabel <david.vrabel@citrix.com>
Fri, 29 Jan 2016 16:51:15 +0000 (17:51 +0100)
committerJan Beulich <jbeulich@suse.com>
Fri, 29 Jan 2016 16:51:15 +0000 (17:51 +0100)
atomic_compareandswap() used atomic_t as the new, old and returned
values which is less convenient than using just int.

Signed-off-by: David Vrabel <david.vrabel@citrix.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
xen/common/domain.c
xen/include/asm-arm/atomic.h
xen/include/asm-x86/atomic.h
xen/include/xen/sched.h

index 603b7188ad78b919fae46152fe500eb0c14b576f..425767c133bd53cfdcb49be330d9bd06101f37b6 100644 (file)
@@ -857,14 +857,11 @@ static void complete_domain_destroy(struct rcu_head *head)
 void domain_destroy(struct domain *d)
 {
     struct domain **pd;
-    atomic_t old = ATOMIC_INIT(0);
-    atomic_t new = ATOMIC_INIT(DOMAIN_DESTROYED);
 
     BUG_ON(!d->is_dying);
 
     /* May be already destroyed, or get_domain() can race us. */
-    old = atomic_compareandswap(old, new, &d->refcnt);
-    if ( _atomic_read(old) != 0 )
+    if ( atomic_cmpxchg(&d->refcnt, 0, DOMAIN_DESTROYED) != 0 )
         return;
 
     cpupool_rm_domain(d);
index 5a38c67fbd5cf2b4544bd785b2603063b31b0240..29ab265f001585782fbcd76ea2a25ee24c9ff7c7 100644 (file)
@@ -138,14 +138,6 @@ static inline void _atomic_set(atomic_t *v, int i)
 # error "unknown ARM variant"
 #endif
 
-static inline atomic_t atomic_compareandswap(
-    atomic_t old, atomic_t new, atomic_t *v)
-{
-    atomic_t rc;
-    rc.counter = __cmpxchg(&v->counter, old.counter, new.counter, sizeof(int));
-    return rc;
-}
-
 #endif /* __ARCH_ARM_ATOMIC__ */
 /*
  * Local variables:
index 2b8c8773ca11d701c78f283450eb07da766fba20..d246b70473fb449290e0b285a6a8ad20edd8cfad 100644 (file)
@@ -135,6 +135,10 @@ static inline void _atomic_set(atomic_t *v, int i)
     v->counter = i;
 }
 
+static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
+{
+    return cmpxchg(&v->counter, old, new);
+}
 
 /**
  * atomic_add - add integer to atomic variable
@@ -151,6 +155,18 @@ static inline void atomic_add(int i, atomic_t *v)
         : "ir" (i), "m" (*(volatile int *)&v->counter) );
 }
 
+/**
+ * atomic_add_return - add integer and return
+ * @i: integer value to add
+ * @v: pointer of type atomic_t
+ *
+ * Atomically adds @i to @v and returns @i + @v
+ */
+static inline int atomic_add_return(int i, atomic_t *v)
+{
+    return i + arch_fetch_and_add(&v->counter, i);
+}
+
 /**
  * atomic_sub - subtract the atomic variable
  * @i: integer value to subtract
@@ -272,12 +288,4 @@ static inline int atomic_add_negative(int i, atomic_t *v)
     return c;
 }
 
-static inline atomic_t atomic_compareandswap(
-    atomic_t old, atomic_t new, atomic_t *v)
-{
-    atomic_t rc;
-    rc.counter = __cmpxchg(&v->counter, old.counter, new.counter, sizeof(int));
-    return rc;
-}
-
 #endif /* __ARCH_X86_ATOMIC__ */
index 82b6dd1527434b7df681f932e98a8695330d9a3b..587074574d1a1ff22b14ce3f755424e8ad180569 100644 (file)
@@ -483,16 +483,15 @@ extern struct vcpu *idle_vcpu[NR_CPUS];
  */
 static always_inline int get_domain(struct domain *d)
 {
-    atomic_t old, new, seen = d->refcnt;
+    int old, seen = atomic_read(&d->refcnt);
     do
     {
         old = seen;
-        if ( unlikely(_atomic_read(old) & DOMAIN_DESTROYED) )
+        if ( unlikely(old & DOMAIN_DESTROYED) )
             return 0;
-        _atomic_set(&new, _atomic_read(old) + 1);
-        seen = atomic_compareandswap(old, new, &d->refcnt);
+        seen = atomic_cmpxchg(&d->refcnt, old, old + 1);
     }
-    while ( unlikely(_atomic_read(seen) != _atomic_read(old)) );
+    while ( unlikely(seen != old) );
     return 1;
 }