33 #ifndef MADNESS_WORLD_ATOMICINT_H__INCLUDED
34 #define MADNESS_WORLD_ATOMICINT_H__INCLUDED
42 #if defined(HAVE_IBMBGP) && !defined(MADATOMIC_USE_GCC)
43 # define MADATOMIC_USE_BGP
44 #elif defined(HAVE_IBMBGQ)
45 # define MADATOMIC_USE_BGQ
46 #elif defined(USE_X86_32_ASM) || defined(USE_X86_64_ASM) || defined(X86_64) || defined(X86_32)
47 # define MADATOMIC_USE_X86_ASM
49 # define MADATOMIC_USE_GCC
52 #if defined(MADATOMIC_USE_BGP)
53 # include <bpcore/bgp_atomic_ops.h>
54 #elif defined (MADATOMIC_USE_BGQ)
56 #elif defined(MADATOMIC_USE_AIX)
57 # include <sys/atomic_op.h>
58 #elif defined(MADATOMIC_USE_GCC)
59 # ifdef GCC_ATOMICS_IN_BITS
60 # include <bits/atomicity.h>
62 # include <ext/atomicity.h>
76 #if defined(MADATOMIC_USE_BGP)
77 typedef _BGP_Atomic atomic_int;
78 #elif defined(MADATOMIC_USE_BGQ)
79 typedef volatile int atomic_int;
81 typedef volatile int atomic_int;
85 inline int exchange_and_add(
int i) {
86 #if defined(MADATOMIC_USE_GCC)
87 return __gnu_cxx::__exchange_and_add(&value,i);
88 #elif defined(MADATOMIC_USE_X86_ASM)
89 __asm__ __volatile__(
"lock; xaddl %0,%1" :
"=r"(i) :
"m"(value),
"0"(i));
91 #elif defined(MADATOMIC_USE_AIX)
92 return fetch_and_add(&value,i);
93 #elif defined(MADATOMIC_USE_BGP)
94 return _bgp_fetch_and_add(&value,i);
95 #elif defined(MADATOMIC_USE_BGQ)
96 return FetchAndAddSigned32(&value,i);
98 # error ... atomic exchange_and_add operator must be implemented for this platform;
104 operator int()
const volatile {
107 #if defined(MADATOMIC_USE_BGP)
108 int result = value.atom;
109 __asm__ __volatile__ (
"" : : :
"memory");
111 #elif defined (MADATOMIC_USE_BGQ)
113 __asm__ __volatile__ (
"" : : :
"memory");
118 __asm__ __volatile__ (
"" : : :
"memory");
127 #if defined(MADATOMIC_USE_BGP)
129 __asm__ __volatile__ (
"" : : :
"memory");
131 #elif defined (MADATOMIC_USE_BGQ)
132 __asm__ __volatile__ (
"" : : :
"memory");
135 __asm__ __volatile__ (
"" : : :
"memory");
149 return exchange_and_add(-1);
154 return exchange_and_add(-1) - 1;
159 return exchange_and_add(1);
164 return exchange_and_add(1) + 1;
169 return exchange_and_add(value) + value;
174 return exchange_and_add(-value) - value;
179 return ((*
this)-- == 1);
186 inline int compare_and_swap(
int compare,
int newval) {
187 #if defined(MADATOMIC_USE_GCC)
188 return __sync_val_compare_and_swap(&value, compare, newval);
189 #elif defined(MADATOMIC_USE_BGP)
190 return _bgp_compare_and_swap(&value, compare, newval);
191 #elif defined(MADATOMIC_USE_BGQ)
192 return CompareAndSwapSigned32(&value, compare, newval);
194 #error ... atomic exchange_and_add operator must be implemented for this platform;
202 #endif // MADNESS_WORLD_ATOMICINT_H__INCLUDED
int operator--(int)
Decrements the counter and returns the original value.
Definition: atomicint.h:148
int operator--()
Decrements the counter and returns the incremented value.
Definition: atomicint.h:153
int operator=(int other)
Sets the value of the counter with fence ensuring preceding operations are not moved after the store...
Definition: atomicint.h:124
bool dec_and_test()
Decrements the counter and returns true if the new value is zero.
Definition: atomicint.h:178
int operator++()
Increments the counter and returns the incremented value.
Definition: atomicint.h:163
AtomicInt & operator=(const AtomicInt &other)
Sets the value of the counter with fences ensuring operations are not moved either side of the load+s...
Definition: atomicint.h:142
int operator++(int)
Increments the counter and returns the original value.
Definition: atomicint.h:158
An integer with atomic set, get, read+inc, read+dec, dec+test operations.
Definition: atomicint.h:73
int operator-=(const int value)
Subtract value and returns the new value.
Definition: atomicint.h:173
int operator+=(const int value)
Add value and returns the new value.
Definition: atomicint.h:168
Holds machinery to set up Functions/FuncImpls using various Factories and Interfaces.
Definition: chem/atomutil.cc:45