diff options
author | David S. Miller <davem@davemloft.net> | 2005-09-15 00:47:01 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2005-09-15 00:47:01 -0400 |
commit | 4db2ce0199f04b6e99999f22e28ef9a0ae5f0d2f (patch) | |
tree | 87a00c97e02a77cdfec517398caa3f1d8f6a2f0d /arch/ia64/lib | |
parent | 4a805e863d6b9466baf7084e1d6fdbe6e0628d8e (diff) |
[LIB]: Consolidate _atomic_dec_and_lock()
Several implementations were essentialy a common piece of C code using
the cmpxchg() macro. Put the implementation in one spot that everyone
can share, and convert sparc64 over to using this.
Alpha is the lone arch-specific implementation, which codes up a
special fast path for the common case in order to avoid GP reloading
which a pure C version would require.
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'arch/ia64/lib')
-rw-r--r-- | arch/ia64/lib/Makefile | 1 | ||||
-rw-r--r-- | arch/ia64/lib/dec_and_lock.c | 42 |
2 files changed, 0 insertions, 43 deletions
diff --git a/arch/ia64/lib/Makefile b/arch/ia64/lib/Makefile index 799407e7726f..cb1af597370b 100644 --- a/arch/ia64/lib/Makefile +++ b/arch/ia64/lib/Makefile | |||
@@ -15,7 +15,6 @@ lib-$(CONFIG_ITANIUM) += copy_page.o copy_user.o memcpy.o | |||
15 | lib-$(CONFIG_MCKINLEY) += copy_page_mck.o memcpy_mck.o | 15 | lib-$(CONFIG_MCKINLEY) += copy_page_mck.o memcpy_mck.o |
16 | lib-$(CONFIG_PERFMON) += carta_random.o | 16 | lib-$(CONFIG_PERFMON) += carta_random.o |
17 | lib-$(CONFIG_MD_RAID5) += xor.o | 17 | lib-$(CONFIG_MD_RAID5) += xor.o |
18 | lib-$(CONFIG_HAVE_DEC_LOCK) += dec_and_lock.o | ||
19 | 18 | ||
20 | AFLAGS___divdi3.o = | 19 | AFLAGS___divdi3.o = |
21 | AFLAGS___udivdi3.o = -DUNSIGNED | 20 | AFLAGS___udivdi3.o = -DUNSIGNED |
diff --git a/arch/ia64/lib/dec_and_lock.c b/arch/ia64/lib/dec_and_lock.c deleted file mode 100644 index c7ce92f968f1..000000000000 --- a/arch/ia64/lib/dec_and_lock.c +++ /dev/null | |||
@@ -1,42 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2003 Jerome Marchand, Bull S.A. | ||
3 | * Cleaned up by David Mosberger-Tang <davidm@hpl.hp.com> | ||
4 | * | ||
5 | * This file is released under the GPLv2, or at your option any later version. | ||
6 | * | ||
7 | * ia64 version of "atomic_dec_and_lock()" using the atomic "cmpxchg" instruction. This | ||
8 | * code is an adaptation of the x86 version of "atomic_dec_and_lock()". | ||
9 | */ | ||
10 | |||
11 | #include <linux/compiler.h> | ||
12 | #include <linux/module.h> | ||
13 | #include <linux/spinlock.h> | ||
14 | #include <asm/atomic.h> | ||
15 | |||
16 | /* | ||
17 | * Decrement REFCOUNT and if the count reaches zero, acquire the spinlock. Both of these | ||
18 | * operations have to be done atomically, so that the count doesn't drop to zero without | ||
19 | * acquiring the spinlock first. | ||
20 | */ | ||
21 | int | ||
22 | _atomic_dec_and_lock (atomic_t *refcount, spinlock_t *lock) | ||
23 | { | ||
24 | int old, new; | ||
25 | |||
26 | do { | ||
27 | old = atomic_read(refcount); | ||
28 | new = old - 1; | ||
29 | |||
30 | if (unlikely (old == 1)) { | ||
31 | /* oops, we may be decrementing to zero, do it the slow way... */ | ||
32 | spin_lock(lock); | ||
33 | if (atomic_dec_and_test(refcount)) | ||
34 | return 1; | ||
35 | spin_unlock(lock); | ||
36 | return 0; | ||
37 | } | ||
38 | } while (cmpxchg(&refcount->counter, old, new) != old); | ||
39 | return 0; | ||
40 | } | ||
41 | |||
42 | EXPORT_SYMBOL(_atomic_dec_and_lock); | ||