1 #include "../../rtt-config.h" 2 #ifndef __ARCH_MSVC_ORO_ATOMIC__ 3 #define __ARCH_MSVC_ORO_ATOMIC__ 11 #define ORO_ATOMIC_SETUP oro_atomic_set 12 #define ORO_ATOMIC_CLEANUP(a_int) 14 #define oro_atomic_read(a_int) (*(a_int)) 16 #define oro_atomic_set(a_int,n) (*(a_int) = (n)) 20 _InterlockedExchangeAdd((
long *)a_int, n);
30 return ((_InterlockedExchangeAdd((
long *)a_int, -n) - n) == 0);
35 _InterlockedIncrement((
long *)a_int);
40 _InterlockedDecrement((
long *)a_int);
45 return (_InterlockedDecrement((
long *)a_int) == 0);
50 return (_InterlockedIncrement((
long *)a_int) == 0);
55 return ((_InterlockedExchangeAdd((
long *)a_int, n) + n) < 0);
58 static __forceinline
int oro_atomic_add_return(
oro_atomic_t *a_int,
int n)
60 return _InterlockedExchangeAdd((
long *)a_int, n) + n;
63 static __forceinline
int oro_atomic_sub_return(
oro_atomic_t *a_int,
int n)
65 return oro_atomic_add_return(a_int, -n);
68 static __forceinline
int oro_atomic_inc_return(
oro_atomic_t *a_int)
70 return _InterlockedIncrement((
long *)a_int);
73 static __forceinline
int oro_atomic_dec_return(
oro_atomic_t *a_int)
75 return _InterlockedDecrement((
long *)a_int);
78 static __forceinline
int oro_atomic_clear_mask(
oro_atomic_t *a_int,
int mask)
80 return _InterlockedAnd((
long *)a_int, ~mask);
83 static __forceinline
int oro_atomic_set_mask(
oro_atomic_t *a_int,
int mask)
85 return _InterlockedOr((
long *)a_int, mask);
89 #pragma warning(disable : 4715) // Disable warning on "specified function can potentially not return a value" 91 template<
typename T>
inline T
oro_cmpxchg(
volatile void * ptr, T old, T _new)
96 return (T)(_InterlockedCompareExchange16((
short *)ptr, (
short)_new, (
short)old));
98 return (T)(_InterlockedCompareExchange((
long *)ptr, (
long)_new, (
long)old));
100 return (T)(_InterlockedCompareExchange64((__int64 *)ptr, (__int64)_new, (__int64)old));
int oro_atomic_inc_and_test(oro_atomic_t *a)
Increment a atomically and test for zero.
void oro_atomic_inc(oro_atomic_t *a)
Increment a atomically.
volatile long oro_atomic_t
void oro_atomic_sub(int n, oro_atomic_t *a, int n)
Substract n from a.
int oro_atomic_dec_and_test(oro_atomic_t *a)
Decrement a atomically and test for zero.
int oro_atomic_sub_and_test(oro_atomic_t *a, int n)
Substract n from a and test for zero.
#define oro_atomic_add_negative(a, v)
T oro_cmpxchg(volatile void *ptr, T old, T _new)
void oro_atomic_dec(oro_atomic_t *a)
Decrement a atomically.
Structure that contains an int for atomic operations.
void oro_atomic_add(oro_atomic_t *a, int n)
Add n to a.