diff options
author | Takashi Iwai <tiwai@suse.de> | 2015-04-16 15:09:09 +0200 |
---|---|---|
committer | Takashi Iwai <tiwai@suse.de> | 2015-04-16 15:09:09 +0200 |
commit | df5e4d7c8a40a5976b0559fc1d4dbd8780460311 (patch) | |
tree | d697c4b334b22c13d48eff4dc373728b7d985ef8 | |
parent | 6e8e199228884852ef307a4e889d205fd702ed47 (diff) | |
download | hda-emu-df5e4d7c8a40a5976b0559fc1d4dbd8780460311.tar.gz |
Add atomic_inc_not_zero() and atomic_dec_if_positive() wrappers
Signed-off-by: Takashi Iwai <tiwai@suse.de>
-rw-r--r-- | include/linux/atomic.h | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/include/linux/atomic.h b/include/linux/atomic.h index cffeb6a..4f84649 100644 --- a/include/linux/atomic.h +++ b/include/linux/atomic.h @@ -13,6 +13,18 @@ typedef struct { #define atomic_inc_return(v) atomic_add_return(1, v) #define atomic_dec_return(v) atomic_sub_return(1, v) #define atomic_set(v, i) (((v)->counter) = (i)) +static inline int atomic_inc_not_zero(atomic_t *v) +{ + if (v->counter) + v->counter++; + return v->counter; +} +static inline int atomic_dec_if_positive(atomic_t *v) +{ + if (!v->counter) + return -1; + return --v->counter; +} #define ATOMIC_INIT(i) { (i) } #endif /* _LINUX_ATOMIC_H */ |