74 #ifdef G4MULTITHREADED
80 template<
typename _Tp>
84 typedef typename std::atomic<_Tp> base_type;
85 typedef _Tp value_type;
88 using mem_odr = std::memory_order;
93 G4atomic(mem_odr odr = std::memory_order_acq_rel) : fMemOrder(odr)
94 { atomics::set(&fvalue, value_type()); }
98 mem_odr odr = std::memory_order_acq_rel) : fMemOrder(odr)
99 { atomics::set(&fvalue, _init); }
104 mem_odr odr = std::memory_order_acq_rel) : fMemOrder(odr)
105 { atomics::set(&fvalue, rhs); }
110 { atomics::set(&fvalue, rhs.base()); }
116 atomics::set(&fvalue, rhs.fvalue);
120 G4atomic& operator=(
const value_type& rhs)
122 atomics::set(&fvalue, rhs);
126 G4atomic& operator=(
const base_type& rhs)
128 atomics::set(&fvalue, rhs);
133 ~
G4atomic() { fvalue.~base_type(); }
136 base_type&
base() {
return fvalue; }
137 const base_type&
base()
const {
return fvalue; }
138 base_type&
base()
volatile {
return fvalue; }
139 const base_type&
base()
const volatile {
return fvalue; }
142 bool is_lock_free()
const {
return fvalue.is_lock_free(); }
143 bool is_lock_free()
const volatile {
return fvalue.is_lock_free(); }
146 void store(_Tp _desired, std::memory_order mem_odr
147 = std::memory_order_seq_cst)
148 { atomics::set(fvalue, _desired, mem_odr); }
149 void store(_Tp _desired, std::memory_order mem_odr
150 = std::memory_order_seq_cst)
volatile
151 { atomics::set(fvalue, _desired, mem_odr); }
154 _Tp load(std::memory_order mem_odr
155 = std::memory_order_seq_cst)
const
156 {
return atomics::get(fvalue, mem_odr); }
157 _Tp load(std::memory_order mem_odr
158 = std::memory_order_seq_cst)
const volatile
159 {
return atomics::get(fvalue, mem_odr); }
162 operator _Tp()
const {
return this->load(); }
163 operator _Tp()
const volatile {
return this->load(); }
165 operator base_type&()
const {
return fvalue; }
168 bool compare_exchange_weak(_Tp& _expected, _Tp _desired,
169 std::memory_order _success,
170 std::memory_order _failure)
171 {
return fvalue.compare_exchange_weak(_expected, _desired,
172 _success, _failure); }
173 bool compare_exchange_weak(_Tp& _expected, _Tp _desired,
174 std::memory_order _success,
175 std::memory_order _failure)
volatile
176 {
return fvalue.compare_exchange_weak(_expected, _desired,
177 _success, _failure); }
179 bool compare_exchange_weak(_Tp& _expected, _Tp _desired,
180 std::memory_order _order)
181 {
return fvalue.compare_exchange_weak(_expected, _desired, _order); }
182 bool compare_exchange_weak(_Tp& _expected, _Tp _desired,
183 std::memory_order _order)
volatile
184 {
return fvalue.compare_exchange_weak(_expected, _desired, _order); }
186 bool compare_exchange_strong(_Tp& _expected, _Tp _desired,
187 std::memory_order _success,
188 std::memory_order _failure)
189 {
return fvalue.compare_exchange_weak(_expected, _desired,
190 _success, _failure); }
191 bool compare_exchange_strong(_Tp& _expected, _Tp _desired,
192 std::memory_order _success,
193 std::memory_order _failure)
volatile
194 {
return fvalue.compare_exchange_weak(_expected, _desired,
195 _success, _failure); }
197 bool compare_exchange_strong(_Tp& _expected, _Tp _desired,
198 std::memory_order _order)
199 {
return fvalue.compare_exchange_weak(_expected, _desired, _order); }
200 bool compare_exchange_strong(_Tp& _expected, _Tp _desired,
201 std::memory_order _order)
volatile
202 {
return fvalue.compare_exchange_weak(_expected, _desired, _order); }
205 G4atomic& operator+=(
const value_type& rhs)
206 { atomics::increment(&fvalue, rhs, fMemOrder);
return *
this; }
207 G4atomic& operator-=(
const value_type& rhs)
208 { atomics::decrement(&fvalue, rhs, fMemOrder);
return *
this; }
209 G4atomic& operator*=(
const value_type& rhs)
210 { atomics::multiply(&fvalue, rhs, fMemOrder);
return *
this; }
211 G4atomic& operator/=(
const value_type& rhs)
212 { atomics::divide(&fvalue, rhs, fMemOrder);
return *
this; }
216 { atomics::increment(&fvalue, rhs.fvalue);
return *
this; }
218 { atomics::decrement(&fvalue, rhs.fvalue);
return *
this; }
220 { atomics::multiply(&fvalue, rhs.fvalue);
return *
this; }
222 { atomics::divide(&fvalue, rhs.fvalue);
return *
this; }
225 { atomics::increment(&fvalue, rhs.fvalue);
return *
this; }
227 { atomics::decrement(&fvalue, rhs.fvalue);
return *
this; }
229 { atomics::multiply(&fvalue, rhs.fvalue);
return *
this; }
231 { atomics::divide(&fvalue, rhs.fvalue);
return *
this; }
234 G4atomic& operator+=(
const std::atomic<_Tp>& rhs)
235 { atomics::increment(&fvalue, rhs, fMemOrder);
return *
this; }
236 G4atomic& operator-=(
const std::atomic<_Tp>& rhs)
237 { atomics::decrement(&fvalue, rhs, fMemOrder);
return *
this; }
238 G4atomic& operator*=(
const std::atomic<_Tp>& rhs)
239 { atomics::multiply(&fvalue, rhs, fMemOrder);
return *
this; }
240 G4atomic& operator/=(
const std::atomic<_Tp>& rhs)
241 { atomics::divide(&fvalue, rhs, fMemOrder);
return *
this; }
243 G4atomic& operator+=(
const std::atomic<_Tp>& rhs)
volatile
244 { atomics::increment(&fvalue, rhs, fMemOrder);
return *
this; }
245 G4atomic& operator-=(
const std::atomic<_Tp>& rhs)
volatile
246 { atomics::decrement(&fvalue, rhs, fMemOrder);
return *
this; }
247 G4atomic& operator*=(
const std::atomic<_Tp>& rhs)
volatile
248 { atomics::multiply(&fvalue, rhs, fMemOrder);
return *
this; }
249 G4atomic& operator/=(
const std::atomic<_Tp>& rhs)
volatile
250 { atomics::divide(&fvalue, rhs, fMemOrder);
return *
this; }
253 value_type operator++() { value_type _tmp = ++fvalue;
return _tmp; }
254 value_type operator++(
int)
255 { value_type _tmp = fvalue++;
return _tmp; }
257 value_type operator--() { value_type _tmp = --fvalue;
return _tmp; }
258 value_type operator--(
int)
259 { value_type _tmp = fvalue--;
return _tmp; }
269 #else // ! G4MULTITHREADED
273 #endif // G4MULTITHREADED
277 #endif // G4atomic_hh_
const XML_Char int const XML_Char int const XML_Char * base
Definition of the G4atomic_defines class.