Add atomic_dec_not_last_64
Signed-off-by: Mateusz Guzik <mjguzik@gmail.com>
This commit is contained in:
parent
043c6ee3b6
commit
84d0c4d7ec
|
@ -149,6 +149,23 @@ atomic_cas_64(volatile uint64_t *target, uint64_t cmp, uint64_t newval)
|
|||
#endif
|
||||
#endif
|
||||
|
||||
static inline int
|
||||
atomic_dec_not_last_64(volatile uint64_t *target)
|
||||
{
|
||||
uint64_t val, oldval;
|
||||
|
||||
val = *target;
|
||||
for (;;) {
|
||||
if (val <= 1) {
|
||||
return (0);
|
||||
}
|
||||
oldval = atomic_cas_64(target, val, val - 1);
|
||||
if (oldval == val)
|
||||
return (1);
|
||||
val = oldval;
|
||||
}
|
||||
}
|
||||
|
||||
static __inline void
|
||||
atomic_inc_64(volatile uint64_t *target)
|
||||
{
|
||||
|
|
|
@ -62,6 +62,7 @@
|
|||
#define atomic_swap_64(v, x) atomic64_xchg((atomic64_t *)(v), x)
|
||||
#define atomic_load_64(v) atomic64_read((atomic64_t *)(v))
|
||||
#define atomic_store_64(v, x) atomic64_set((atomic64_t *)(v), x)
|
||||
#define atomic_dec_not_last_64(v) atomic64_dec_if_positive((atomic64_t *)(v))
|
||||
|
||||
#ifdef _LP64
|
||||
static __inline__ void *
|
||||
|
|
|
@ -62,6 +62,24 @@ ATOMIC_DEC(uchar, uchar_t)
|
|||
ATOMIC_DEC(ushort, ushort_t)
|
||||
ATOMIC_DEC(uint, uint_t)
|
||||
ATOMIC_DEC(ulong, ulong_t)
|
||||
|
||||
int
|
||||
atomic_dec_not_last_64(volatile uint64_t *target)
|
||||
{
|
||||
uint64_t val, oldval;
|
||||
|
||||
val = *target;
|
||||
for (;;) {
|
||||
if (val <= 1) {
|
||||
return (0);
|
||||
}
|
||||
oldval = atomic_cas_64(target, val, val - 1);
|
||||
if (oldval == val)
|
||||
return (1);
|
||||
val = oldval;
|
||||
}
|
||||
}
|
||||
|
||||
/* END CSTYLED */
|
||||
|
||||
|
||||
|
|
|
@ -155,6 +155,7 @@ extern uint_t atomic_dec_uint_nv(volatile uint_t *);
|
|||
extern ulong_t atomic_dec_ulong_nv(volatile ulong_t *);
|
||||
#if defined(_INT64_TYPE)
|
||||
extern uint64_t atomic_dec_64_nv(volatile uint64_t *);
|
||||
extern int atomic_dec_not_last_64(volatile uint64_t *);
|
||||
#endif
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in New Issue