diff options
author | Richard Braun <rbraun@sceen.net> | 2017-01-25 00:35:58 +0100 |
---|---|---|
committer | Richard Braun <rbraun@sceen.net> | 2017-01-25 00:35:58 +0100 |
commit | a4746bfe8f174bf90777419a539b49914942b20d (patch) | |
tree | 379c9794cc8c16f1b42db01e6e665c88e0f6967a | |
parent | 9d8e1b745149dd39385cfefbc1f75937885caf69 (diff) |
x86/atomic: add functions for uintptr_t
-rw-r--r-- | arch/x86/machine/atomic.h | 182 |
1 files changed, 153 insertions, 29 deletions
diff --git a/arch/x86/machine/atomic.h b/arch/x86/machine/atomic.h index 1304bb37..c990526c 100644 --- a/arch/x86/machine/atomic.h +++ b/arch/x86/machine/atomic.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012-2014 Richard Braun. + * Copyright (c) 2012-2017 Richard Braun. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -23,6 +23,8 @@ #ifndef _X86_ATOMIC_H #define _X86_ATOMIC_H +#include <kern/stdint.h> + #define ATOMIC_ADD(ptr, delta) \ asm volatile("lock add %1, %0" \ : "+m" (*(ptr)) \ @@ -163,6 +165,67 @@ atomic_cas_uint(volatile unsigned int *ptr, unsigned int predicate, } static inline void +atomic_local_add_uint(volatile unsigned int *ptr, int delta) +{ + ATOMIC_LOCAL_ADD(ptr, delta); +} + +/* + * Implies a compiler barrier. + */ +static inline unsigned int +atomic_local_fetchadd_uint(volatile unsigned int *ptr, int delta) +{ + unsigned int oldval; + + ATOMIC_LOCAL_FETCHADD(ptr, oldval, delta); + return oldval; +} + +static inline void +atomic_local_and_uint(volatile unsigned int *ptr, unsigned int bits) +{ + ATOMIC_LOCAL_AND(ptr, bits); +} + +static inline void +atomic_local_or_uint(volatile unsigned int *ptr, unsigned int bits) +{ + ATOMIC_LOCAL_OR(ptr, bits); +} + +static inline void +atomic_local_xor_uint(volatile unsigned int *ptr, unsigned int bits) +{ + ATOMIC_LOCAL_XOR(ptr, bits); +} + +/* + * Implies a compiler barrier. + */ +static inline unsigned int +atomic_local_swap_uint(volatile unsigned int *ptr, unsigned int newval) +{ + unsigned int oldval; + + ATOMIC_LOCAL_SWAP(ptr, oldval, newval); + return oldval; +} + +/* + * Implies a compiler barrier. + */ +static inline unsigned int +atomic_local_cas_uint(volatile unsigned int *ptr, unsigned int predicate, + unsigned int newval) +{ + unsigned int oldval; + + ATOMIC_LOCAL_CAS(ptr, oldval, predicate, newval); + return oldval; +} + +static inline void atomic_add_ulong(volatile unsigned long *ptr, long delta) { ATOMIC_ADD(ptr, delta); @@ -224,7 +287,7 @@ atomic_cas_ulong(volatile unsigned long *ptr, unsigned long predicate, } static inline void -atomic_local_add_uint(volatile unsigned int *ptr, int delta) +atomic_local_add_ulong(volatile unsigned long *ptr, long delta) { ATOMIC_LOCAL_ADD(ptr, delta); } @@ -232,29 +295,29 @@ atomic_local_add_uint(volatile unsigned int *ptr, int delta) /* * Implies a compiler barrier. */ -static inline unsigned int -atomic_local_fetchadd_uint(volatile unsigned int *ptr, int delta) +static inline unsigned long +atomic_local_fetchadd_ulong(volatile unsigned long *ptr, long delta) { - unsigned int oldval; + unsigned long oldval; ATOMIC_LOCAL_FETCHADD(ptr, oldval, delta); return oldval; } static inline void -atomic_local_and_uint(volatile unsigned int *ptr, unsigned int bits) +atomic_local_and_ulong(volatile unsigned long *ptr, unsigned long bits) { ATOMIC_LOCAL_AND(ptr, bits); } static inline void -atomic_local_or_uint(volatile unsigned int *ptr, unsigned int bits) +atomic_local_or_ulong(volatile unsigned long *ptr, unsigned long bits) { ATOMIC_LOCAL_OR(ptr, bits); } static inline void -atomic_local_xor_uint(volatile unsigned int *ptr, unsigned int bits) +atomic_local_xor_ulong(volatile unsigned long *ptr, unsigned long bits) { ATOMIC_LOCAL_XOR(ptr, bits); } @@ -262,10 +325,10 @@ atomic_local_xor_uint(volatile unsigned int *ptr, unsigned int bits) /* * Implies a compiler barrier. */ -static inline unsigned int -atomic_local_swap_uint(volatile unsigned int *ptr, unsigned int newval) +static inline unsigned long +atomic_local_swap_ulong(volatile unsigned long *ptr, unsigned long newval) { - unsigned int oldval; + unsigned long oldval; ATOMIC_LOCAL_SWAP(ptr, oldval, newval); return oldval; @@ -274,18 +337,79 @@ atomic_local_swap_uint(volatile unsigned int *ptr, unsigned int newval) /* * Implies a compiler barrier. */ -static inline unsigned int -atomic_local_cas_uint(volatile unsigned int *ptr, unsigned int predicate, - unsigned int newval) +static inline unsigned long +atomic_local_cas_ulong(volatile unsigned long *ptr, unsigned long predicate, + unsigned long newval) { - unsigned int oldval; + unsigned long oldval; ATOMIC_LOCAL_CAS(ptr, oldval, predicate, newval); return oldval; } static inline void -atomic_local_add_ulong(volatile unsigned long *ptr, long delta) +atomic_add_uintptr(volatile uintptr_t *ptr, intptr_t delta) +{ + ATOMIC_ADD(ptr, delta); +} + +/* + * Implies a full memory barrier. + */ +static inline uintptr_t +atomic_fetchadd_uintptr(volatile uintptr_t *ptr, intptr_t delta) +{ + uintptr_t oldval; + + ATOMIC_FETCHADD(ptr, oldval, delta); + return oldval; +} + +static inline void +atomic_and_uintptr(volatile uintptr_t *ptr, uintptr_t bits) +{ + ATOMIC_AND(ptr, bits); +} + +static inline void +atomic_or_uintptr(volatile uintptr_t *ptr, uintptr_t bits) +{ + ATOMIC_OR(ptr, bits); +} + +static inline void +atomic_xor_uintptr(volatile uintptr_t *ptr, uintptr_t bits) +{ + ATOMIC_XOR(ptr, bits); +} + +/* + * Implies a full memory barrier. + */ +static inline uintptr_t +atomic_swap_uintptr(volatile uintptr_t *ptr, uintptr_t newval) +{ + uintptr_t oldval; + + ATOMIC_SWAP(ptr, oldval, newval); + return oldval; +} + +/* + * Implies a full memory barrier. + */ +static inline uintptr_t +atomic_cas_uintptr(volatile uintptr_t *ptr, uintptr_t predicate, + uintptr_t newval) +{ + uintptr_t oldval; + + ATOMIC_CAS(ptr, oldval, predicate, newval); + return oldval; +} + +static inline void +atomic_local_add_uintptr(volatile uintptr_t *ptr, intptr_t delta) { ATOMIC_LOCAL_ADD(ptr, delta); } @@ -293,29 +417,29 @@ atomic_local_add_ulong(volatile unsigned long *ptr, long delta) /* * Implies a compiler barrier. */ -static inline unsigned long -atomic_local_fetchadd_ulong(volatile unsigned long *ptr, long delta) +static inline uintptr_t +atomic_local_fetchadd_uintptr(volatile uintptr_t *ptr, intptr_t delta) { - unsigned long oldval; + uintptr_t oldval; ATOMIC_LOCAL_FETCHADD(ptr, oldval, delta); return oldval; } static inline void -atomic_local_and_ulong(volatile unsigned long *ptr, unsigned long bits) +atomic_local_and_uintptr(volatile uintptr_t *ptr, uintptr_t bits) { ATOMIC_LOCAL_AND(ptr, bits); } static inline void -atomic_local_or_ulong(volatile unsigned long *ptr, unsigned long bits) +atomic_local_or_uintptr(volatile uintptr_t *ptr, uintptr_t bits) { ATOMIC_LOCAL_OR(ptr, bits); } static inline void -atomic_local_xor_ulong(volatile unsigned long *ptr, unsigned long bits) +atomic_local_xor_uintptr(volatile uintptr_t *ptr, uintptr_t bits) { ATOMIC_LOCAL_XOR(ptr, bits); } @@ -323,10 +447,10 @@ atomic_local_xor_ulong(volatile unsigned long *ptr, unsigned long bits) /* * Implies a compiler barrier. */ -static inline unsigned long -atomic_local_swap_ulong(volatile unsigned long *ptr, unsigned long newval) +static inline uintptr_t +atomic_local_swap_uintptr(volatile uintptr_t *ptr, uintptr_t newval) { - unsigned long oldval; + uintptr_t oldval; ATOMIC_LOCAL_SWAP(ptr, oldval, newval); return oldval; @@ -335,11 +459,11 @@ atomic_local_swap_ulong(volatile unsigned long *ptr, unsigned long newval) /* * Implies a compiler barrier. */ -static inline unsigned long -atomic_local_cas_ulong(volatile unsigned long *ptr, unsigned long predicate, - unsigned long newval) +static inline uintptr_t +atomic_local_cas_uintptr(volatile uintptr_t *ptr, uintptr_t predicate, + uintptr_t newval) { - unsigned long oldval; + uintptr_t oldval; ATOMIC_LOCAL_CAS(ptr, oldval, predicate, newval); return oldval; |