provide atomic64_try_cmpxchg() for 32bit

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
Kent Overstreet 2024-07-12 14:24:38 -04:00
parent 0f9b409aee
commit 4be409afea
2 changed files with 16 additions and 0 deletions

View File

@ -344,6 +344,7 @@ void atomic64_sub(s64, atomic64_t *);
s64 atomic64_xchg(atomic64_t *, s64);
s64 atomic64_cmpxchg(atomic64_t *, s64, s64);
bool atomic64_try_cmpxchg(atomic64_t *, s64 *, s64);
#define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
#define atomic64_inc(v) atomic64_add(1LL, (v))

View File

@ -157,6 +157,21 @@ long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n)
return val;
}
bool atomic64_try_cmpxchg(atomic64_t *v, s64 *o, s64 n)
{
unsigned long flags;
raw_spinlock_t *lock = lock_addr(v);
raw_spin_lock_irqsave(lock, flags);
bool ret = v->counter == *o;
if (ret)
v->counter = n;
else
*o = v->counter;
raw_spin_unlock_irqrestore(lock, flags);
return ret;
}
long long atomic64_xchg(atomic64_t *v, long long new)
{
unsigned long flags;