LinuxKPI: Change flags parameter type of atomic_dec_and_lock_irqsave

On Linux atomic_dec_and_lock_irqsave is a wrapper macro which provides
a reference to third parameter rather than parameter value itself to
implementation routine called _atomic_dec_and_lock_irqsave [1].

While here, implement a fast path.

[1] https://github.com/torvalds/linux/blob/master/include/linux/spinlock.h#L476

Reviewed by:	hselasky
Differential revision:	https://reviews.freebsd.org/D30781
This commit is contained in:
Vladimir Kondratyev 2021-07-05 03:19:01 +03:00
parent 78a02d8b33
commit c77ec79b57

View File

@ -163,15 +163,20 @@ spin_lock_destroy(spinlock_t *lock)
mtx_assert(&(_l)->m, MA_OWNED); \
} while (0)
#define atomic_dec_and_lock_irqsave(cnt, lock, flags) \
_atomic_dec_and_lock_irqsave(cnt, lock, &(flags))
static inline int
atomic_dec_and_lock_irqsave(atomic_t *cnt, spinlock_t *lock,
unsigned long flags)
_atomic_dec_and_lock_irqsave(atomic_t *cnt, spinlock_t *lock,
unsigned long *flags)
{
spin_lock_irqsave(lock, flags);
if (atomic_add_unless(cnt, -1, 1))
return (0);
spin_lock_irqsave(lock, *flags);
if (atomic_dec_and_test(cnt))
return 1;
spin_unlock_irqrestore(lock, flags);
return 0;
return (1);
spin_unlock_irqrestore(lock, *flags);
return (0);
}
#endif /* _LINUX_SPINLOCK_H_ */