--- zzzz-none-000/linux-2.6.39.4/arch/x86/include/asm/atomic.h 2011-08-03 19:43:28.000000000 +0000 +++ puma6-atom-6490-729/linux-2.6.39.4/arch/x86/include/asm/atomic.h 2021-11-10 13:38:14.000000000 +0000 @@ -269,6 +269,48 @@ return dec; } +/* + * return the incremented value if value < max_value + * if incremented value == max_value so do not write and return -1 + */ +static inline int atomic_inc_with_max_return(atomic_t * v, unsigned int max_value) { + int c, old, add; + c = atomic_read(v); + for (;;) { + add = c + 1; + if (unlikely(add >= max_value)) { + add = -1; + break; + } + old = atomic_cmpxchg((v), c, add); + if (likely(old == c)) { + break; + } + c = old; + } + return add; +} + +/* + * return the incremented value if value < max_value + * if incremented value == max_value so write and return zero + */ +static inline int atomic_inc_with_wrap_return(atomic_t * v, unsigned int max_value) { + int c, old, add; + c = atomic_read(v); + for (;;) { + add = c + 1; + if (unlikely(add >= max_value)) { + add = 0; + } + old = atomic_cmpxchg((v), c, add); + if (likely(old == c)) { + break; + } + c = old; + } + return add; +} /** * atomic_inc_short - increment of a short integer * @v: pointer to type int