74 #ifdef G4MULTITHREADED
80 template<
typename _Tp>
85 typedef typename std::atomic<_Tp> base_type;
86 typedef _Tp value_type;
90 using mem_ord = std::memory_order;
96 G4atomic(mem_ord mo = std::memory_order_acq_rel) : fMemOrder(mo)
97 { atomics::set(&fvalue, value_type()); }
101 mem_ord mo = std::memory_order_acq_rel) : fMemOrder(mo)
102 { atomics::set(&fvalue, _init); }
107 mem_ord mo = std::memory_order_acq_rel) : fMemOrder(mo)
108 { atomics::set(&fvalue, rhs); }
113 { atomics::set(&fvalue, rhs.base()); }
119 atomics::set(&fvalue, rhs.fvalue);
123 G4atomic& operator=(
const value_type& rhs)
125 atomics::set(&fvalue, rhs);
129 G4atomic& operator=(
const base_type& rhs)
131 atomics::set(&fvalue, rhs);
136 ~
G4atomic() { fvalue.~base_type(); }
139 base_type&
base() {
return fvalue; }
140 const base_type&
base()
const {
return fvalue; }
141 base_type&
base()
volatile {
return fvalue; }
142 const base_type&
base()
const volatile {
return fvalue; }
145 bool is_lock_free()
const {
return fvalue.is_lock_free(); }
146 bool is_lock_free()
const volatile {
return fvalue.is_lock_free(); }
149 void store(_Tp _desired, mem_ord mo = std::memory_order_seq_cst)
150 { atomics::set(fvalue, _desired, mo); }
151 void store(_Tp _desired, mem_ord mo = std::memory_order_seq_cst)
volatile
152 { atomics::set(fvalue, _desired, mo); }
155 _Tp load(mem_ord mo = std::memory_order_seq_cst)
const
156 {
return atomics::get(fvalue, mo); }
157 _Tp load(mem_ord mo = std::memory_order_seq_cst)
const volatile
158 {
return atomics::get(fvalue, mo); }
161 operator _Tp()
const {
return this->load(); }
162 operator _Tp()
const volatile {
return this->load(); }
164 operator base_type&()
const {
return fvalue; }
167 bool compare_exchange_weak(_Tp& _expected, _Tp _desired,
168 mem_ord _success, mem_ord _failure)
169 {
return fvalue.compare_exchange_weak(_expected, _desired,
170 _success, _failure); }
171 bool compare_exchange_weak(_Tp& _expected, _Tp _desired,
172 mem_ord _success, mem_ord _failure)
volatile
173 {
return fvalue.compare_exchange_weak(_expected, _desired,
174 _success, _failure); }
176 bool compare_exchange_weak(_Tp& _expected, _Tp _desired, mem_ord _order)
177 {
return fvalue.compare_exchange_weak(_expected, _desired, _order); }
178 bool compare_exchange_weak(_Tp& _expected, _Tp _desired,
179 mem_ord _order)
volatile
180 {
return fvalue.compare_exchange_weak(_expected, _desired, _order); }
182 bool compare_exchange_strong(_Tp& _expected, _Tp _desired,
183 mem_ord _success, mem_ord _failure)
184 {
return fvalue.compare_exchange_weak(_expected, _desired,
185 _success, _failure); }
186 bool compare_exchange_strong(_Tp& _expected, _Tp _desired,
187 mem_ord _success, mem_ord _failure)
volatile
188 {
return fvalue.compare_exchange_weak(_expected, _desired,
189 _success, _failure); }
191 bool compare_exchange_strong(_Tp& _expected, _Tp _desired, mem_ord _order)
192 {
return fvalue.compare_exchange_weak(_expected, _desired, _order); }
193 bool compare_exchange_strong(_Tp& _expected, _Tp _desired,
194 mem_ord _order)
volatile
195 {
return fvalue.compare_exchange_weak(_expected, _desired, _order); }
198 G4atomic& operator+=(
const value_type& rhs)
199 { atomics::increment(&fvalue, rhs, fMemOrder);
return *
this; }
200 G4atomic& operator-=(
const value_type& rhs)
201 { atomics::decrement(&fvalue, rhs, fMemOrder);
return *
this; }
202 G4atomic& operator*=(
const value_type& rhs)
203 { atomics::multiply(&fvalue, rhs, fMemOrder);
return *
this; }
204 G4atomic& operator/=(
const value_type& rhs)
205 { atomics::divide(&fvalue, rhs, fMemOrder);
return *
this; }
209 { atomics::increment(&fvalue, rhs.fvalue);
return *
this; }
211 { atomics::decrement(&fvalue, rhs.fvalue);
return *
this; }
213 { atomics::multiply(&fvalue, rhs.fvalue);
return *
this; }
215 { atomics::divide(&fvalue, rhs.fvalue);
return *
this; }
218 { atomics::increment(&fvalue, rhs.fvalue);
return *
this; }
220 { atomics::decrement(&fvalue, rhs.fvalue);
return *
this; }
222 { atomics::multiply(&fvalue, rhs.fvalue);
return *
this; }
224 { atomics::divide(&fvalue, rhs.fvalue);
return *
this; }
227 G4atomic& operator+=(
const std::atomic<_Tp>& rhs)
228 { atomics::increment(&fvalue, rhs, fMemOrder);
return *
this; }
229 G4atomic& operator-=(
const std::atomic<_Tp>& rhs)
230 { atomics::decrement(&fvalue, rhs, fMemOrder);
return *
this; }
231 G4atomic& operator*=(
const std::atomic<_Tp>& rhs)
232 { atomics::multiply(&fvalue, rhs, fMemOrder);
return *
this; }
233 G4atomic& operator/=(
const std::atomic<_Tp>& rhs)
234 { atomics::divide(&fvalue, rhs, fMemOrder);
return *
this; }
236 G4atomic& operator+=(
const std::atomic<_Tp>& rhs)
volatile
237 { atomics::increment(&fvalue, rhs, fMemOrder);
return *
this; }
238 G4atomic& operator-=(
const std::atomic<_Tp>& rhs)
volatile
239 { atomics::decrement(&fvalue, rhs, fMemOrder);
return *
this; }
240 G4atomic& operator*=(
const std::atomic<_Tp>& rhs)
volatile
241 { atomics::multiply(&fvalue, rhs, fMemOrder);
return *
this; }
242 G4atomic& operator/=(
const std::atomic<_Tp>& rhs)
volatile
243 { atomics::divide(&fvalue, rhs, fMemOrder);
return *
this; }
246 value_type operator++() { value_type _tmp = ++fvalue;
return _tmp; }
247 value_type operator++(
int)
248 { value_type _tmp = fvalue++;
return _tmp; }
250 value_type operator--() { value_type _tmp = --fvalue;
return _tmp; }
251 value_type operator--(
int)
252 { value_type _tmp = fvalue--;
return _tmp; }
263 #else // ! G4MULTITHREADED
267 #endif // G4MULTITHREADED
271 #endif // G4atomic_hh_
const XML_Char int const XML_Char int const XML_Char * base
Definition of the G4atomic_defines class.