73 #ifdef G4MULTITHREADED
79 template<
typename _Tp>
84 typedef typename std::atomic<_Tp> base_type;
85 typedef _Tp value_type;
89 using mem_ord = std::memory_order;
95 G4atomic(mem_ord mo = std::memory_order_acq_rel) : fMemOrder(mo)
96 { atomics::set(&fvalue, value_type()); }
100 mem_ord mo = std::memory_order_acq_rel) : fMemOrder(mo)
101 { atomics::set(&fvalue, _init); }
106 mem_ord mo = std::memory_order_acq_rel) : fMemOrder(mo)
107 { atomics::set(&fvalue, rhs); }
112 { atomics::set(&fvalue, rhs.base()); }
118 atomics::set(&fvalue, rhs.fvalue);
122 G4atomic& operator=(
const value_type& rhs)
124 atomics::set(&fvalue, rhs);
128 G4atomic& operator=(
const base_type& rhs)
130 atomics::set(&fvalue, rhs);
135 ~
G4atomic() { fvalue.~base_type(); }
138 base_type&
base() {
return fvalue; }
139 const base_type&
base()
const {
return fvalue; }
140 base_type&
base()
volatile {
return fvalue; }
141 const base_type&
base()
const volatile {
return fvalue; }
144 bool is_lock_free()
const {
return fvalue.is_lock_free(); }
145 bool is_lock_free()
const volatile {
return fvalue.is_lock_free(); }
148 void store(_Tp _desired, mem_ord mo = std::memory_order_seq_cst)
149 { atomics::set(fvalue, _desired, mo); }
150 void store(_Tp _desired, mem_ord mo = std::memory_order_seq_cst)
volatile
151 { atomics::set(fvalue, _desired, mo); }
154 _Tp load(mem_ord mo = std::memory_order_seq_cst)
const
156 _Tp load(mem_ord mo = std::memory_order_seq_cst)
const volatile
160 operator _Tp()
const {
return this->load(); }
161 operator _Tp()
const volatile {
return this->load(); }
163 operator base_type&()
const {
return fvalue; }
166 bool compare_exchange_weak(_Tp& _expected, _Tp _desired,
167 mem_ord _success, mem_ord _failure)
168 {
return fvalue.compare_exchange_weak(_expected, _desired,
169 _success, _failure); }
170 bool compare_exchange_weak(_Tp& _expected, _Tp _desired,
171 mem_ord _success, mem_ord _failure)
volatile
172 {
return fvalue.compare_exchange_weak(_expected, _desired,
173 _success, _failure); }
175 bool compare_exchange_weak(_Tp& _expected, _Tp _desired, mem_ord _order)
176 {
return fvalue.compare_exchange_weak(_expected, _desired, _order); }
177 bool compare_exchange_weak(_Tp& _expected, _Tp _desired,
178 mem_ord _order)
volatile
179 {
return fvalue.compare_exchange_weak(_expected, _desired, _order); }
181 bool compare_exchange_strong(_Tp& _expected, _Tp _desired,
182 mem_ord _success, mem_ord _failure)
183 {
return fvalue.compare_exchange_weak(_expected, _desired,
184 _success, _failure); }
185 bool compare_exchange_strong(_Tp& _expected, _Tp _desired,
186 mem_ord _success, mem_ord _failure)
volatile
187 {
return fvalue.compare_exchange_weak(_expected, _desired,
188 _success, _failure); }
190 bool compare_exchange_strong(_Tp& _expected, _Tp _desired, mem_ord _order)
191 {
return fvalue.compare_exchange_weak(_expected, _desired, _order); }
192 bool compare_exchange_strong(_Tp& _expected, _Tp _desired,
193 mem_ord _order)
volatile
194 {
return fvalue.compare_exchange_weak(_expected, _desired, _order); }
197 G4atomic& operator+=(
const value_type& rhs)
198 { atomics::increment(&fvalue, rhs, fMemOrder);
return *
this; }
199 G4atomic& operator-=(
const value_type& rhs)
200 { atomics::decrement(&fvalue, rhs, fMemOrder);
return *
this; }
201 G4atomic& operator*=(
const value_type& rhs)
202 { atomics::multiply(&fvalue, rhs, fMemOrder);
return *
this; }
203 G4atomic& operator/=(
const value_type& rhs)
204 { atomics::divide(&fvalue, rhs, fMemOrder);
return *
this; }
208 { atomics::increment(&fvalue, rhs.fvalue);
return *
this; }
210 { atomics::decrement(&fvalue, rhs.fvalue);
return *
this; }
212 { atomics::multiply(&fvalue, rhs.fvalue);
return *
this; }
214 { atomics::divide(&fvalue, rhs.fvalue);
return *
this; }
217 { atomics::increment(&fvalue, rhs.fvalue);
return *
this; }
219 { atomics::decrement(&fvalue, rhs.fvalue);
return *
this; }
221 { atomics::multiply(&fvalue, rhs.fvalue);
return *
this; }
223 { atomics::divide(&fvalue, rhs.fvalue);
return *
this; }
226 G4atomic& operator+=(
const std::atomic<_Tp>& rhs)
227 { atomics::increment(&fvalue, rhs, fMemOrder);
return *
this; }
228 G4atomic& operator-=(
const std::atomic<_Tp>& rhs)
229 { atomics::decrement(&fvalue, rhs, fMemOrder);
return *
this; }
230 G4atomic& operator*=(
const std::atomic<_Tp>& rhs)
231 { atomics::multiply(&fvalue, rhs, fMemOrder);
return *
this; }
232 G4atomic& operator/=(
const std::atomic<_Tp>& rhs)
233 { atomics::divide(&fvalue, rhs, fMemOrder);
return *
this; }
235 G4atomic& operator+=(
const std::atomic<_Tp>& rhs)
volatile
236 { atomics::increment(&fvalue, rhs, fMemOrder);
return *
this; }
237 G4atomic& operator-=(
const std::atomic<_Tp>& rhs)
volatile
238 { atomics::decrement(&fvalue, rhs, fMemOrder);
return *
this; }
239 G4atomic& operator*=(
const std::atomic<_Tp>& rhs)
volatile
240 { atomics::multiply(&fvalue, rhs, fMemOrder);
return *
this; }
241 G4atomic& operator/=(
const std::atomic<_Tp>& rhs)
volatile
242 { atomics::divide(&fvalue, rhs, fMemOrder);
return *
this; }
245 value_type operator++() { value_type _tmp = ++fvalue;
return _tmp; }
246 value_type operator++(
int)
247 { value_type _tmp = fvalue++;
return _tmp; }
249 value_type operator--() { value_type _tmp = --fvalue;
return _tmp; }
250 value_type operator--(
int)
251 { value_type _tmp = fvalue--;
return _tmp; }
262 #else // ! G4MULTITHREADED
266 #endif // G4MULTITHREADED
270 #endif // G4atomic_hh_