ZFS: add emulation of atomic_swap_64 and atomic_load_64
Some 32-bit platforms do not provide 64-bit atomic operations that ZFS requires, either in userland or at all. We emulate those operations for those platforms using a mutex. That is not entirely correct and it's very efficient. Besides, the loads are plain loads, so torn values are possible. Nevertheless, the emulation seems to work for some definition of work. This change adds atomic_swap_64, which is already used in ZFS code, and atomic_load_64 that can be used to prevent torn reads. MFC after: 1 week
This commit is contained in:
parent
87b704d0e3
commit
3458e5d1e6
@ -71,6 +71,29 @@ atomic_dec_64(volatile uint64_t *target)
|
||||
*target -= 1;
|
||||
mtx_unlock(&atomic_mtx);
|
||||
}
|
||||
|
||||
uint64_t
|
||||
atomic_swap_64(volatile uint64_t *a, uint64_t value)
|
||||
{
|
||||
uint64_t ret;
|
||||
|
||||
mtx_lock(&atomic_mtx);
|
||||
ret = *a;
|
||||
*a = value;
|
||||
mtx_unlock(&atomic_mtx);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
uint64_t
|
||||
atomic_load_64(volatile uint64_t *a)
|
||||
{
|
||||
uint64_t ret;
|
||||
|
||||
mtx_lock(&atomic_mtx);
|
||||
ret = *a;
|
||||
mtx_unlock(&atomic_mtx);
|
||||
return (ret);
|
||||
}
|
||||
#endif
|
||||
|
||||
uint64_t
|
||||
|
@ -44,6 +44,8 @@
|
||||
!defined(ARM_HAVE_ATOMIC64) && !defined(I386_HAVE_ATOMIC64)
|
||||
extern void atomic_add_64(volatile uint64_t *target, int64_t delta);
|
||||
extern void atomic_dec_64(volatile uint64_t *target);
|
||||
extern uint64_t atomic_swap_64(volatile uint64_t *a, uint64_t value);
|
||||
extern uint64_t atomic_load_64(volatile uint64_t *a);
|
||||
#endif
|
||||
#ifndef __sparc64__
|
||||
extern uint32_t atomic_cas_32(volatile uint32_t *target, uint32_t cmp,
|
||||
|
Loading…
x
Reference in New Issue
Block a user