Changeset View
Changeset View
Standalone View
Standalone View
sys/compat/linuxkpi/common/include/asm/atomic.h
Show First 20 Lines • Show All 153 Lines • ▼ Show 20 Lines | if (atomic_cmpset_int(&v->counter, old, new)) | ||||
break; | break; | ||||
ret = READ_ONCE(v->counter); | ret = READ_ONCE(v->counter); | ||||
if (ret != old) | if (ret != old) | ||||
break; | break; | ||||
} | } | ||||
return (ret); | return (ret); | ||||
} | } | ||||
static inline int | |||||
atomic_dec_if_positive(atomic_t *v) { | |||||
int c, old, dec; | |||||
c = atomic_read(v); | |||||
for (;;) { | |||||
dec = c - 1; | |||||
if (unlikely(dec < 0)) | |||||
break; | |||||
old = atomic_cmpxchg((v), c, dec); | |||||
if (likely(old == c)) | |||||
break; | |||||
c = old; | |||||
} | |||||
return dec; | |||||
} | |||||
#define cmpxchg(ptr, old, new) ({ \ | #define cmpxchg(ptr, old, new) ({ \ | ||||
union { \ | union { \ | ||||
__typeof(*(ptr)) val; \ | __typeof(*(ptr)) val; \ | ||||
u8 u8[0]; \ | u8 u8[0]; \ | ||||
u16 u16[0]; \ | u16 u16[0]; \ | ||||
u32 u32[0]; \ | u32 u32[0]; \ | ||||
u64 u64[0]; \ | u64 u64[0]; \ | ||||
} __ret = { .val = (old) }, __new = { .val = (new) }; \ | } __ret = { .val = (old) }, __new = { .val = (new) }; \ | ||||
▲ Show 20 Lines • Show All 101 Lines • Show Last 20 Lines |