diff options
Diffstat (limited to 'lib/libspl/asm-generic/atomic.c')
-rw-r--r-- | lib/libspl/asm-generic/atomic.c | 135 |
1 files changed, 77 insertions, 58 deletions
diff --git a/lib/libspl/asm-generic/atomic.c b/lib/libspl/asm-generic/atomic.c index a3223eadc..f5eb4f34b 100644 --- a/lib/libspl/asm-generic/atomic.c +++ b/lib/libspl/asm-generic/atomic.c @@ -40,7 +40,7 @@ pthread_mutex_t atomic_lock = PTHREAD_MUTEX_INITIALIZER; * Theses are the void returning variants */ -#define ATOMIC_INC(name, type) \ +#define ATOMIC_INC(name, type) \ void atomic_inc_##name(volatile type *target) \ { \ VERIFY3S(pthread_mutex_lock(&atomic_lock), ==, 0); \ @@ -59,7 +59,7 @@ ATOMIC_INC(ulong, ulong_t) ATOMIC_INC(64, uint64_t) -#define ATOMIC_DEC(name, type) \ +#define ATOMIC_DEC(name, type) \ void atomic_dec_##name(volatile type *target) \ { \ VERIFY3S(pthread_mutex_lock(&atomic_lock), ==, 0); \ @@ -78,7 +78,7 @@ ATOMIC_DEC(ulong, ulong_t) ATOMIC_DEC(64, uint64_t) -#define ATOMIC_ADD(name, type1, type2) \ +#define ATOMIC_ADD(name, type1, type2) \ void atomic_add_##name(volatile type1 *target, type2 bits) \ { \ VERIFY3S(pthread_mutex_lock(&atomic_lock), ==, 0); \ @@ -95,7 +95,8 @@ ATOMIC_ADD(int, uint_t, int) ATOMIC_ADD(long, ulong_t, long) ATOMIC_ADD(64, uint64_t, int64_t) -void atomic_add_ptr(volatile void *target, ssize_t bits) +void +atomic_add_ptr(volatile void *target, ssize_t bits) { VERIFY3S(pthread_mutex_lock(&atomic_lock), ==, 0); *(caddr_t *)target += bits; @@ -103,7 +104,7 @@ void atomic_add_ptr(volatile void *target, ssize_t bits) } -#define ATOMIC_SUB(name, type1, type2) \ +#define ATOMIC_SUB(name, type1, type2) \ void atomic_sub_##name(volatile type1 *target, type2 bits) \ { \ VERIFY3S(pthread_mutex_lock(&atomic_lock), ==, 0); \ @@ -120,7 +121,8 @@ ATOMIC_SUB(int, uint_t, int) ATOMIC_SUB(long, ulong_t, long) ATOMIC_SUB(64, uint64_t, int64_t) -void atomic_sub_ptr(volatile void *target, ssize_t bits) +void +atomic_sub_ptr(volatile void *target, ssize_t bits) { VERIFY3S(pthread_mutex_lock(&atomic_lock), ==, 0); *(caddr_t *)target -= bits; @@ -128,7 +130,7 @@ void atomic_sub_ptr(volatile void *target, ssize_t bits) } -#define ATOMIC_OR(name, type) \ +#define ATOMIC_OR(name, type) \ void atomic_or_##name(volatile type *target, type bits) \ { \ VERIFY3S(pthread_mutex_lock(&atomic_lock), ==, 0); \ @@ -146,7 +148,7 @@ ATOMIC_OR(ulong, ulong_t) ATOMIC_OR(64, uint64_t) -#define ATOMIC_AND(name, type) \ +#define ATOMIC_AND(name, type) \ void atomic_and_##name(volatile type *target, type bits) \ { \ VERIFY3S(pthread_mutex_lock(&atomic_lock), ==, 0); \ @@ -168,14 +170,14 @@ ATOMIC_AND(64, uint64_t) * New value returning variants */ -#define ATOMIC_INC_NV(name, type) \ +#define ATOMIC_INC_NV(name, type) \ type atomic_inc_##name##_nv(volatile type *target) \ { \ type rc; \ VERIFY3S(pthread_mutex_lock(&atomic_lock), ==, 0); \ rc = (++(*target)); \ VERIFY3S(pthread_mutex_unlock(&atomic_lock), ==, 0); \ - return rc; \ + return (rc); \ } ATOMIC_INC_NV(long, unsigned long) @@ -189,14 +191,14 @@ ATOMIC_INC_NV(ulong, ulong_t) ATOMIC_INC_NV(64, uint64_t) -#define ATOMIC_DEC_NV(name, type) \ +#define ATOMIC_DEC_NV(name, type) \ type atomic_dec_##name##_nv(volatile type *target) \ { \ type rc; \ VERIFY3S(pthread_mutex_lock(&atomic_lock), ==, 0); \ rc = (--(*target)); \ VERIFY3S(pthread_mutex_unlock(&atomic_lock), ==, 0); \ - return rc; \ + return (rc); \ } ATOMIC_DEC_NV(long, unsigned long) @@ -210,14 +212,14 @@ ATOMIC_DEC_NV(ulong, ulong_t) ATOMIC_DEC_NV(64, uint64_t) -#define ATOMIC_ADD_NV(name, type1, type2) \ +#define ATOMIC_ADD_NV(name, type1, type2) \ type1 atomic_add_##name##_nv(volatile type1 *target, type2 bits)\ { \ type1 rc; \ VERIFY3S(pthread_mutex_lock(&atomic_lock), ==, 0); \ rc = (*target += bits); \ VERIFY3S(pthread_mutex_unlock(&atomic_lock), ==, 0); \ - return rc; \ + return (rc); \ } ATOMIC_ADD_NV(8, uint8_t, int8_t) @@ -229,7 +231,8 @@ ATOMIC_ADD_NV(int, uint_t, int) ATOMIC_ADD_NV(long, ulong_t, long) ATOMIC_ADD_NV(64, uint64_t, int64_t) -void *atomic_add_ptr_nv(volatile void *target, ssize_t bits) +void * +atomic_add_ptr_nv(volatile void *target, ssize_t bits) { void *ptr; @@ -237,18 +240,18 @@ void *atomic_add_ptr_nv(volatile void *target, ssize_t bits) ptr = (*(caddr_t *)target += bits); VERIFY3S(pthread_mutex_unlock(&atomic_lock), ==, 0); - return ptr; + return (ptr); } -#define ATOMIC_SUB_NV(name, type1, type2) \ +#define ATOMIC_SUB_NV(name, type1, type2) \ type1 atomic_sub_##name##_nv(volatile type1 *target, type2 bits)\ { \ type1 rc; \ VERIFY3S(pthread_mutex_lock(&atomic_lock), ==, 0); \ rc = (*target -= bits); \ VERIFY3S(pthread_mutex_unlock(&atomic_lock), ==, 0); \ - return rc; \ + return (rc); \ } ATOMIC_SUB_NV(8, uint8_t, int8_t) @@ -260,7 +263,8 @@ ATOMIC_SUB_NV(int, uint_t, int) ATOMIC_SUB_NV(long, ulong_t, long) ATOMIC_SUB_NV(64, uint64_t, int64_t) -void *atomic_sub_ptr_nv(volatile void *target, ssize_t bits) +void * +atomic_sub_ptr_nv(volatile void *target, ssize_t bits) { void *ptr; @@ -268,18 +272,18 @@ void *atomic_sub_ptr_nv(volatile void *target, ssize_t bits) ptr = (*(caddr_t *)target -= bits); VERIFY3S(pthread_mutex_unlock(&atomic_lock), ==, 0); - return ptr; + return (ptr); } -#define ATOMIC_OR_NV(name, type) \ +#define ATOMIC_OR_NV(name, type) \ type atomic_or_##name##_nv(volatile type *target, type bits) \ { \ type rc; \ VERIFY3S(pthread_mutex_lock(&atomic_lock), ==, 0); \ rc = (*target |= bits); \ VERIFY3S(pthread_mutex_unlock(&atomic_lock), ==, 0); \ - return rc; \ + return (rc); \ } ATOMIC_OR_NV(long, unsigned long) @@ -293,14 +297,14 @@ ATOMIC_OR_NV(ulong, ulong_t) ATOMIC_OR_NV(64, uint64_t) -#define ATOMIC_AND_NV(name, type) \ +#define ATOMIC_AND_NV(name, type) \ type atomic_and_##name##_nv(volatile type *target, type bits) \ { \ type rc; \ VERIFY3S(pthread_mutex_lock(&atomic_lock), ==, 0); \ rc = (*target &= bits); \ VERIFY3S(pthread_mutex_unlock(&atomic_lock), ==, 0); \ - return rc; \ + return (rc); \ } ATOMIC_AND_NV(long, unsigned long) @@ -318,7 +322,7 @@ ATOMIC_AND_NV(64, uint64_t) * If *arg1 == arg2, set *arg1 = arg3; return old value */ -#define ATOMIC_CAS(name, type) \ +#define ATOMIC_CAS(name, type) \ type atomic_cas_##name(volatile type *target, type arg1, type arg2) \ { \ type old; \ @@ -327,7 +331,7 @@ ATOMIC_AND_NV(64, uint64_t) if (old == arg1) \ *target = arg2; \ VERIFY3S(pthread_mutex_unlock(&atomic_lock), ==, 0); \ - return old; \ + return (old); \ } ATOMIC_CAS(8, uint8_t) @@ -339,17 +343,18 @@ ATOMIC_CAS(uint, uint_t) ATOMIC_CAS(ulong, ulong_t) ATOMIC_CAS(64, uint64_t) -void *atomic_cas_ptr(volatile void *target, void *arg1, void *arg2) +void * +atomic_cas_ptr(volatile void *target, void *arg1, void *arg2) { void *old; VERIFY3S(pthread_mutex_lock(&atomic_lock), ==, 0); old = *(void **)target; - if (old == arg1) - *(void **)target = arg2; + if (old == arg1) + *(void **)target = arg2; VERIFY3S(pthread_mutex_unlock(&atomic_lock), ==, 0); - return old; + return (old); } @@ -357,7 +362,7 @@ void *atomic_cas_ptr(volatile void *target, void *arg1, void *arg2) * Swap target and return old value */ -#define ATOMIC_SWAP(name, type) \ +#define ATOMIC_SWAP(name, type) \ type atomic_swap_##name(volatile type *target, type bits) \ { \ type old; \ @@ -365,7 +370,7 @@ void *atomic_cas_ptr(volatile void *target, void *arg1, void *arg2) old = *target; \ *target = bits; \ VERIFY3S(pthread_mutex_unlock(&atomic_lock), ==, 0); \ - return old; \ + return (old); \ } ATOMIC_SWAP(8, uint8_t) @@ -377,7 +382,8 @@ ATOMIC_SWAP(uint, uint_t) ATOMIC_SWAP(ulong, ulong_t) ATOMIC_SWAP(64, uint64_t) -void *atomic_swap_ptr(volatile void *target, void *bits) +void * +atomic_swap_ptr(volatile void *target, void *bits) { void *old; @@ -386,11 +392,12 @@ void *atomic_swap_ptr(volatile void *target, void *bits) *(void **)target = bits; VERIFY3S(pthread_mutex_unlock(&atomic_lock), ==, 0); - return old; + return (old); } -int atomic_set_long_excl(volatile ulong_t *target, uint_t value) +int +atomic_set_long_excl(volatile ulong_t *target, uint_t value) { ulong_t bit; @@ -398,15 +405,16 @@ int atomic_set_long_excl(volatile ulong_t *target, uint_t value) bit = (1UL << value); if ((*target & bit) != 0) { VERIFY3S(pthread_mutex_unlock(&atomic_lock), ==, 0); - return -1; + return (-1); } *target |= bit; VERIFY3S(pthread_mutex_unlock(&atomic_lock), ==, 0); - return 0; + return (0); } -int atomic_clear_long_excl(volatile ulong_t *target, uint_t value) +int +atomic_clear_long_excl(volatile ulong_t *target, uint_t value) { ulong_t bit; @@ -414,67 +422,78 @@ int atomic_clear_long_excl(volatile ulong_t *target, uint_t value) bit = (1UL << value); if ((*target & bit) != 0) { VERIFY3S(pthread_mutex_unlock(&atomic_lock), ==, 0); - return -1; + return (-1); } *target &= ~bit; VERIFY3S(pthread_mutex_unlock(&atomic_lock), ==, 0); - return 0; + return (0); } -void membar_enter(void) +void +membar_enter(void) { /* XXX - Implement me */ } -void membar_exit(void) +void +membar_exit(void) { /* XXX - Implement me */ } -void membar_producer(void) +void +membar_producer(void) { /* XXX - Implement me */ } -void membar_consumer(void) +void +membar_consumer(void) { /* XXX - Implement me */ } /* Legacy kernel interfaces; they will go away (eventually). */ -uint8_t cas8(uint8_t *target, uint8_t arg1, uint8_t arg2) +uint8_t +cas8(uint8_t *target, uint8_t arg1, uint8_t arg2) { - return atomic_cas_8(target, arg1, arg2); + return (atomic_cas_8(target, arg1, arg2)); } -uint32_t cas32(uint32_t *target, uint32_t arg1, uint32_t arg2) +uint32_t +cas32(uint32_t *target, uint32_t arg1, uint32_t arg2) { - return atomic_cas_32(target, arg1, arg2); + return (atomic_cas_32(target, arg1, arg2)); } -uint64_t cas64(uint64_t *target, uint64_t arg1, uint64_t arg2) +uint64_t +cas64(uint64_t *target, uint64_t arg1, uint64_t arg2) { - return atomic_cas_64(target, arg1, arg2); + return (atomic_cas_64(target, arg1, arg2)); } -ulong_t caslong(ulong_t *target, ulong_t arg1, ulong_t arg2) +ulong_t +caslong(ulong_t *target, ulong_t arg1, ulong_t arg2) { - return atomic_cas_ulong(target, arg1, arg2); + return (atomic_cas_ulong(target, arg1, arg2)); } -void *casptr(void *target, void *arg1, void *arg2) +void * +casptr(void *target, void *arg1, void *arg2) { - return atomic_cas_ptr(target, arg1, arg2); + return (atomic_cas_ptr(target, arg1, arg2)); } -void atomic_and_long(ulong_t *target, ulong_t bits) +void +atomic_and_long(ulong_t *target, ulong_t bits) { - return atomic_and_ulong(target, bits); + return (atomic_and_ulong(target, bits)); } -void atomic_or_long(ulong_t *target, ulong_t bits) +void +atomic_or_long(ulong_t *target, ulong_t bits) { - return atomic_or_ulong(target, bits); + return (atomic_or_ulong(target, bits)); } |