aboutsummaryrefslogtreecommitdiffstats
path: root/arch/sparc/lib/atomic32.c
diff options
context:
space:
mode:
authorNick Piggin <nickpiggin@yahoo.com.au>2005-11-13 19:07:24 -0500
committerLinus Torvalds <torvalds@g5.osdl.org>2005-11-13 21:14:16 -0500
commit4a6dae6d382e9edf3ff440b819e554ed706359bc (patch)
tree2945a5095973e2ecf05b503d6deb859083045b8e /arch/sparc/lib/atomic32.c
parent53e86b91b7ae66d4c2757195cbd42e00d9199cf2 (diff)
[PATCH] atomic: cmpxchg
Introduce an atomic_cmpxchg operation. Signed-off-by: Nick Piggin <npiggin@suse.de> Cc: "Paul E. McKenney" <paulmck@us.ibm.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'arch/sparc/lib/atomic32.c')
-rw-r--r--arch/sparc/lib/atomic32.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/arch/sparc/lib/atomic32.c b/arch/sparc/lib/atomic32.c
index 2e64e8c3e8e5..be46f6545184 100644
--- a/arch/sparc/lib/atomic32.c
+++ b/arch/sparc/lib/atomic32.c
@@ -37,17 +37,28 @@ int __atomic_add_return(int i, atomic_t *v)
37 spin_unlock_irqrestore(ATOMIC_HASH(v), flags); 37 spin_unlock_irqrestore(ATOMIC_HASH(v), flags);
38 return ret; 38 return ret;
39} 39}
40EXPORT_SYMBOL(__atomic_add_return);
40 41
41void atomic_set(atomic_t *v, int i) 42int atomic_cmpxchg(atomic_t *v, int old, int new)
42{ 43{
44 int ret;
43 unsigned long flags; 45 unsigned long flags;
44 spin_lock_irqsave(ATOMIC_HASH(v), flags);
45 46
46 v->counter = i; 47 spin_lock_irqsave(ATOMIC_HASH(v), flags);
48 ret = v->counter;
49 if (likely(ret == old))
50 v->counter = new;
47 51
48 spin_unlock_irqrestore(ATOMIC_HASH(v), flags); 52 spin_unlock_irqrestore(ATOMIC_HASH(v), flags);
53 return ret;
49} 54}
50 55
51EXPORT_SYMBOL(__atomic_add_return); 56void atomic_set(atomic_t *v, int i)
52EXPORT_SYMBOL(atomic_set); 57{
58 unsigned long flags;
53 59
60 spin_lock_irqsave(ATOMIC_HASH(v), flags);
61 v->counter = i;
62 spin_unlock_irqrestore(ATOMIC_HASH(v), flags);
63}
64EXPORT_SYMBOL(atomic_set);