diff options
Diffstat (limited to 'arch/x86/include/asm/atomic.h')
| -rw-r--r-- | arch/x86/include/asm/atomic.h | 23 | 
1 files changed, 23 insertions, 0 deletions
diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h index 8f8217b9bdac..706c69492c14 100644 --- a/arch/x86/include/asm/atomic.h +++ b/arch/x86/include/asm/atomic.h  | |||
| @@ -246,6 +246,29 @@ static inline int atomic_add_unless(atomic_t *v, int a, int u) | |||
| 246 | 246 | ||
| 247 | #define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0) | 247 | #define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0) | 
| 248 | 248 | ||
| 249 | /* | ||
| 250 | * atomic_dec_if_positive - decrement by 1 if old value positive | ||
| 251 | * @v: pointer of type atomic_t | ||
| 252 | * | ||
| 253 | * The function returns the old value of *v minus 1, even if | ||
| 254 | * the atomic variable, v, was not decremented. | ||
| 255 | */ | ||
| 256 | static inline int atomic_dec_if_positive(atomic_t *v) | ||
| 257 | { | ||
| 258 | int c, old, dec; | ||
| 259 | c = atomic_read(v); | ||
| 260 | for (;;) { | ||
| 261 | dec = c - 1; | ||
| 262 | if (unlikely(dec < 0)) | ||
| 263 | break; | ||
| 264 | old = atomic_cmpxchg((v), c, dec); | ||
| 265 | if (likely(old == c)) | ||
| 266 | break; | ||
| 267 | c = old; | ||
| 268 | } | ||
| 269 | return dec; | ||
| 270 | } | ||
| 271 | |||
| 249 | /** | 272 | /** | 
| 250 | * atomic_inc_short - increment of a short integer | 273 | * atomic_inc_short - increment of a short integer | 
| 251 | * @v: pointer to type int | 274 | * @v: pointer to type int | 
