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/ppc64/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/ppc64/lib')
-rw-r--r-- | arch/ppc64/lib/Makefile | 2 | ||||
-rw-r--r-- | arch/ppc64/lib/dec_and_lock.c | 47 |
2 files changed, 1 insertions, 48 deletions
diff --git a/arch/ppc64/lib/Makefile b/arch/ppc64/lib/Makefile index 76fbfa9f706f..0b6e967de948 100644 --- a/arch/ppc64/lib/Makefile +++ b/arch/ppc64/lib/Makefile | |||
@@ -2,7 +2,7 @@ | |||
2 | # Makefile for ppc64-specific library files.. | 2 | # Makefile for ppc64-specific library files.. |
3 | # | 3 | # |
4 | 4 | ||
5 | lib-y := checksum.o dec_and_lock.o string.o strcase.o | 5 | lib-y := checksum.o string.o strcase.o |
6 | lib-y += copypage.o memcpy.o copyuser.o usercopy.o | 6 | lib-y += copypage.o memcpy.o copyuser.o usercopy.o |
7 | 7 | ||
8 | # Lock primitives are defined as no-ops in include/linux/spinlock.h | 8 | # Lock primitives are defined as no-ops in include/linux/spinlock.h |
diff --git a/arch/ppc64/lib/dec_and_lock.c b/arch/ppc64/lib/dec_and_lock.c deleted file mode 100644 index 7b9d4da5cf92..000000000000 --- a/arch/ppc64/lib/dec_and_lock.c +++ /dev/null | |||
@@ -1,47 +0,0 @@ | |||
1 | /* | ||
2 | * ppc64 version of atomic_dec_and_lock() using cmpxchg | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or | ||
5 | * modify it under the terms of the GNU General Public License | ||
6 | * as published by the Free Software Foundation; either version | ||
7 | * 2 of the License, or (at your option) any later version. | ||
8 | */ | ||
9 | |||
10 | #include <linux/module.h> | ||
11 | #include <linux/spinlock.h> | ||
12 | #include <asm/atomic.h> | ||
13 | #include <asm/system.h> | ||
14 | |||
15 | /* | ||
16 | * This is an implementation of the notion of "decrement a | ||
17 | * reference count, and return locked if it decremented to zero". | ||
18 | * | ||
19 | * This implementation can be used on any architecture that | ||
20 | * has a cmpxchg, and where atomic->value is an int holding | ||
21 | * the value of the atomic (i.e. the high bits aren't used | ||
22 | * for a lock or anything like that). | ||
23 | */ | ||
24 | int _atomic_dec_and_lock(atomic_t *atomic, spinlock_t *lock) | ||
25 | { | ||
26 | int counter; | ||
27 | int newcount; | ||
28 | |||
29 | for (;;) { | ||
30 | counter = atomic_read(atomic); | ||
31 | newcount = counter - 1; | ||
32 | if (!newcount) | ||
33 | break; /* do it the slow way */ | ||
34 | |||
35 | newcount = cmpxchg(&atomic->counter, counter, newcount); | ||
36 | if (newcount == counter) | ||
37 | return 0; | ||
38 | } | ||
39 | |||
40 | spin_lock(lock); | ||
41 | if (atomic_dec_and_test(atomic)) | ||
42 | return 1; | ||
43 | spin_unlock(lock); | ||
44 | return 0; | ||
45 | } | ||
46 | |||
47 | EXPORT_SYMBOL(_atomic_dec_and_lock); | ||