Optimize andes_clear_page() and andes_copy_page() with prefetch
[linux-2.6/linux-mips.git] / lib / dec_and_lock.c
blob281bb359cae40d7d4d9b8c25c08693609b71cf6b
1 #include <linux/spinlock.h>
2 #include <asm/atomic.h>
4 /*
5 * This is an architecture-neutral, but slow,
6 * implementation of the notion of "decrement
7 * a reference count, and return locked if it
8 * decremented to zero".
10 * NOTE NOTE NOTE! This is _not_ equivalent to
12 * if (atomic_dec_and_test(&atomic)) {
13 * spin_lock(&lock);
14 * return 1;
15 * }
16 * return 0;
18 * because the spin-lock and the decrement must be
19 * "atomic".
21 * This slow version gets the spinlock unconditionally,
22 * and releases it if it isn't needed. Architectures
23 * are encouraged to come up with better approaches,
24 * this is trivially done efficiently using a load-locked
25 * store-conditional approach, for example.
28 #ifndef atomic_dec_and_lock
29 int atomic_dec_and_lock(atomic_t *atomic, spinlock_t *lock)
31 spin_lock(lock);
32 if (atomic_dec_and_test(atomic))
33 return 1;
34 spin_unlock(lock);
35 return 0;
37 #endif