 e79bee24fd
			
		
	
	
	e79bee24fd
	
	
	
		
			
			The x86 implementation of atomic_dec_if_positive is quite generic, so make it available to all architectures. This is needed for "swap: add a simple detector for inappropriate swapin readahead". [akpm@linux-foundation.org: do the "#define foo foo" trick in the conventional manner] Signed-off-by: Shaohua Li <shli@fusionio.com> Cc: Stephen Rothwell <sfr@canb.auug.org.au> Cc: "David S. Miller" <davem@davemloft.net> Cc: Rik van Riel <riel@redhat.com> Cc: Ingo Molnar <mingo@elte.hu> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: "H. Peter Anvin" <hpa@zytor.com> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org> Cc: Michal Simek <monstr@monstr.eu> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
		
			
				
	
	
		
			27 lines
		
	
	
	
		
			587 B
			
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			27 lines
		
	
	
	
		
			587 B
			
		
	
	
	
		
			C
		
	
	
	
	
	
| #ifndef _ASM_MICROBLAZE_ATOMIC_H
 | |
| #define _ASM_MICROBLAZE_ATOMIC_H
 | |
| 
 | |
| #include <asm/cmpxchg.h>
 | |
| #include <asm-generic/atomic.h>
 | |
| #include <asm-generic/atomic64.h>
 | |
| 
 | |
| /*
 | |
|  * Atomically test *v and decrement if it is greater than 0.
 | |
|  * The function returns the old value of *v minus 1.
 | |
|  */
 | |
| static inline int atomic_dec_if_positive(atomic_t *v)
 | |
| {
 | |
| 	unsigned long flags;
 | |
| 	int res;
 | |
| 
 | |
| 	local_irq_save(flags);
 | |
| 	res = v->counter - 1;
 | |
| 	if (res >= 0)
 | |
| 		v->counter = res;
 | |
| 	local_irq_restore(flags);
 | |
| 
 | |
| 	return res;
 | |
| }
 | |
| #define atomic_dec_if_positive atomic_dec_if_positive
 | |
| 
 | |
| #endif /* _ASM_MICROBLAZE_ATOMIC_H */
 |