]> granicus.if.org Git - spl/commitdiff
Correctly implement atomic_cas_ptr() function. Ideally all of these
authorbehlendo <behlendo@7e1ea52c-4ff2-0310-8f11-9dd32ca42a1c>
Thu, 3 Apr 2008 21:48:57 +0000 (21:48 +0000)
committerbehlendo <behlendo@7e1ea52c-4ff2-0310-8f11-9dd32ca42a1c>
Thu, 3 Apr 2008 21:48:57 +0000 (21:48 +0000)
atomic operations will be rewritten anyway with the correct arch
specific assembly.  But not today.

git-svn-id: https://outreach.scidac.gov/svn/spl/trunk@65 7e1ea52c-4ff2-0310-8f11-9dd32ca42a1c

include/sys/atomic.h
modules/spl/spl-atomic.c

index 647d0db9a037f85e869252bdc620b4a1c84a055a..c04a5b6b47c20691524b9d8709ce200ce9ca87ce 100644 (file)
@@ -16,7 +16,6 @@ extern "C" {
  */
 extern spinlock_t atomic64_lock;
 extern spinlock_t atomic32_lock;
-extern spinlock_t atomic_lock;
 
 static __inline__ uint32_t
 atomic_add_32(volatile uint32_t *target, int32_t delta)
@@ -94,7 +93,7 @@ atomic_sub_64_nv(volatile uint64_t *target, uint64_t delta)
 }
 
 static __inline__ uint64_t
-atomic_cas_64(volatile uint64_t  *target,  uint64_t cmp,
+atomic_cas_64(volatile uint64_t *target,  uint64_t cmp,
                uint64_t newval)
 {
        uint64_t rc;
@@ -108,19 +107,18 @@ atomic_cas_64(volatile uint64_t  *target,  uint64_t cmp,
        return rc;
 }
 
+#if defined(__x86_64__)
+/* XXX: Implement atomic_cas_ptr() in terms of uint64'ts.  This
+ * is of course only safe and correct for 64 bit arches...  but
+ * for now I'm OK with that.
+ */
 static __inline__ void *
-atomic_cas_ptr(volatile void  *target,  void *cmp, void *newval)
+atomic_cas_ptr(volatile void *target,  void *cmp, void *newval)
 {
-       void *rc;
-
-       spin_lock(&atomic_lock);
-       rc = (void *)target;
-       if (target == cmp)
-               target = newval;
-       spin_unlock(&atomic_lock);
-
-       return rc;
+       return (void *)atomic_cas_64((volatile uint64_t *)target,
+                                    (uint64_t)cmp, (uint64_t)newval);
 }
+#endif
 
 #ifdef  __cplusplus
 }
index fb161c52078da850064cba2f4355a0e58e6071ef..3efa6c133bccd74f61a7f387a44914268b85e656 100644 (file)
@@ -3,8 +3,6 @@
 /* Global atomic lock declarations */
 spinlock_t atomic64_lock = SPIN_LOCK_UNLOCKED;
 spinlock_t atomic32_lock = SPIN_LOCK_UNLOCKED;
-spinlock_t atomic_lock   = SPIN_LOCK_UNLOCKED;
 
 EXPORT_SYMBOL(atomic64_lock);
 EXPORT_SYMBOL(atomic32_lock);
-EXPORT_SYMBOL(atomic_lock);