Changeset View
Changeset View
Standalone View
Standalone View
sys/sparc64/include/atomic.h
Show First 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | |||||
/* Userland needs different ASI's. */ | /* Userland needs different ASI's. */ | ||||
#ifdef _KERNEL | #ifdef _KERNEL | ||||
#define __ASI_ATOMIC ASI_N | #define __ASI_ATOMIC ASI_N | ||||
#else | #else | ||||
#define __ASI_ATOMIC ASI_P | #define __ASI_ATOMIC ASI_P | ||||
#endif | #endif | ||||
static __inline int atomic_cmpset_8(__volatile uint8_t *, uint8_t, uint8_t); | |||||
static __inline int atomic_fcmpset_8(__volatile uint8_t *, uint8_t *, uint8_t); | |||||
static __inline int atomic_cmpset_16(__volatile uint16_t *, uint16_t, uint16_t); | |||||
static __inline int atomic_fcmpset_16(__volatile uint16_t *, uint16_t *, uint16_t); | |||||
/* | /* | ||||
* Various simple arithmetic on memory which is atomic in the presence | * Various simple arithmetic on memory which is atomic in the presence | ||||
* of interrupts and multiple processors. See atomic(9) for details. | * of interrupts and multiple processors. See atomic(9) for details. | ||||
* Note that efficient hardware support exists only for the 32 and 64 | * Note that efficient hardware support exists only for the 32 and 64 | ||||
* bit variants; the 8 and 16 bit versions are not provided and should | * bit variants; the 8 and 16 bit versions are not provided and should | ||||
* not be used in MI code. | * not be used in MI code. | ||||
* | * | ||||
* This implementation takes advantage of the fact that the sparc64 | * This implementation takes advantage of the fact that the sparc64 | ||||
▲ Show 20 Lines • Show All 292 Lines • ▼ Show 20 Lines | |||||
ATOMIC_GEN(int, u_int *, u_int, u_int, 32); | ATOMIC_GEN(int, u_int *, u_int, u_int, 32); | ||||
ATOMIC_GEN(32, uint32_t *, uint32_t, uint32_t, 32); | ATOMIC_GEN(32, uint32_t *, uint32_t, uint32_t, 32); | ||||
ATOMIC_GEN(long, u_long *, u_long, u_long, 64); | ATOMIC_GEN(long, u_long *, u_long, u_long, 64); | ||||
ATOMIC_GEN(64, uint64_t *, uint64_t, uint64_t, 64); | ATOMIC_GEN(64, uint64_t *, uint64_t, uint64_t, 64); | ||||
ATOMIC_GEN(ptr, uintptr_t *, uintptr_t, uintptr_t, 64); | ATOMIC_GEN(ptr, uintptr_t *, uintptr_t, uintptr_t, 64); | ||||
#define ATOMIC_CMPSET_ACQ_REL(WIDTH) \ | |||||
static __inline int \ | |||||
atomic_cmpset_acq_##WIDTH(__volatile uint##WIDTH##_t *p, \ | |||||
uint##WIDTH##_t cmpval, uint##WIDTH##_t newval) \ | |||||
{ \ | |||||
int retval; \ | |||||
\ | |||||
retval = atomic_cmpset_##WIDTH(p, cmpval, newval); \ | |||||
mb(); \ | |||||
return (retval); \ | |||||
} \ | |||||
\ | |||||
static __inline int \ | |||||
atomic_cmpset_rel_##WIDTH(__volatile uint##WIDTH##_t *p, \ | |||||
uint##WIDTH##_t cmpval, uint##WIDTH##_t newval) \ | |||||
{ \ | |||||
mb(); \ | |||||
return (atomic_cmpset_##WIDTH(p, cmpval, newval)); \ | |||||
} | |||||
#define ATOMIC_FCMPSET_ACQ_REL(WIDTH) \ | |||||
static __inline int \ | |||||
atomic_fcmpset_acq_##WIDTH(__volatile uint##WIDTH##_t *p, \ | |||||
uint##WIDTH##_t *cmpval, uint##WIDTH##_t newval) \ | |||||
{ \ | |||||
int retval; \ | |||||
\ | |||||
retval = atomic_fcmpset_##WIDTH(p, cmpval, newval); \ | |||||
mb(); \ | |||||
return (retval); \ | |||||
} \ | |||||
\ | |||||
static __inline int \ | |||||
atomic_fcmpset_rel_##WIDTH(__volatile uint##WIDTH##_t *p, \ | |||||
uint##WIDTH##_t *cmpval, uint##WIDTH##_t newval) \ | |||||
{ \ | |||||
mb(); \ | |||||
return (atomic_fcmpset_##WIDTH(p, cmpval, newval)); \ | |||||
} | |||||
/* | |||||
* Atomically compare the value stored at *p with cmpval and if the | |||||
* two values are equal, update the value of *p with newval. Returns | |||||
* zero if the compare failed, nonzero otherwise. | |||||
*/ | |||||
ATOMIC_CMPSET_ACQ_REL(8); | |||||
ATOMIC_CMPSET_ACQ_REL(16); | |||||
ATOMIC_FCMPSET_ACQ_REL(8); | |||||
ATOMIC_FCMPSET_ACQ_REL(16); | |||||
#define atomic_cmpset_char atomic_cmpset_8 | |||||
#define atomic_cmpset_acq_char atomic_cmpset_acq_8 | |||||
#define atomic_cmpset_rel_char atomic_cmpset_rel_8 | |||||
#define atomic_fcmpset_acq_char atomic_fcmpset_acq_8 | |||||
#define atomic_fcmpset_rel_char atomic_fcmpset_rel_8 | |||||
#define atomic_cmpset_short atomic_cmpset_16 | |||||
#define atomic_cmpset_acq_short atomic_cmpset_acq_16 | |||||
#define atomic_cmpset_rel_short atomic_cmpset_rel_16 | |||||
#define atomic_fcmpset_acq_short atomic_fcmpset_acq_16 | |||||
#define atomic_fcmpset_rel_short atomic_fcmpset_rel_16 | |||||
#define atomic_fetchadd_int atomic_add_int | #define atomic_fetchadd_int atomic_add_int | ||||
#define atomic_fetchadd_32 atomic_add_32 | #define atomic_fetchadd_32 atomic_add_32 | ||||
#define atomic_fetchadd_long atomic_add_long | #define atomic_fetchadd_long atomic_add_long | ||||
#define atomic_fetchadd_64 atomic_add_64 | #define atomic_fetchadd_64 atomic_add_64 | ||||
#undef ATOMIC_GEN | #undef ATOMIC_GEN | ||||
#undef atomic_cas | #undef atomic_cas | ||||
#undef atomic_cas_acq | #undef atomic_cas_acq | ||||
#undef atomic_cas_rel | #undef atomic_cas_rel | ||||
#undef atomic_op | #undef atomic_op | ||||
#undef atomic_op_acq | #undef atomic_op_acq | ||||
#undef atomic_op_rel | #undef atomic_op_rel | ||||
#undef atomic_ld_acq | #undef atomic_ld_acq | ||||
#undef atomic_ld_clear | #undef atomic_ld_clear | ||||
#undef atomic_st | #undef atomic_st | ||||
#undef atomic_st_acq | #undef atomic_st_acq | ||||
#undef atomic_st_rel | #undef atomic_st_rel | ||||
#include <sys/_atomic_subword.h> | |||||
#endif /* !_MACHINE_ATOMIC_H_ */ | #endif /* !_MACHINE_ATOMIC_H_ */ |