root / tmp / org.txm.statsengine.r.core.win32 / res / win32 / library / BH / include / boost / atomic / detail / cas32strong.hpp @ 2486
History  View  Annotate  Download (25.9 kB)
1 
#ifndef BOOST_ATOMIC_DETAIL_CAS32STRONG_HPP


2 
#define BOOST_ATOMIC_DETAIL_CAS32STRONG_HPP

3  
4 
// Distributed under the Boost Software License, Version 1.0.

5 
// See accompanying file LICENSE_1_0.txt or copy at

6 
// http://www.boost.org/LICENSE_1_0.txt)

7 
//

8 
// Copyright (c) 2011 Helge Bahmann

9 
// Copyright (c) 2013 Tim Blechmann

10  
11  
12 
// Build 8, 16 and 32bit atomic operations from

13 
// a platform_cmpxchg32_strong primitive.

14  
15 
#include <string.h> 
16 
#include <cstddef> 
17 
#include <boost/cstdint.hpp> 
18 
#include <boost/memory_order.hpp> 
19 
#include <boost/atomic/detail/config.hpp> 
20 
#include <boost/atomic/detail/base.hpp> 
21  
22 
#ifdef BOOST_HAS_PRAGMA_ONCE

23 
#pragma once

24 
#endif

25  
26 
namespace boost {

27 
namespace atomics {

28 
namespace detail {

29  
30 
/* integral types */

31  
32 
template<typename T, bool Sign> 
33 
class base_atomic<T, int, 1, Sign> 
34 
{ 
35 
private:

36 
typedef base_atomic this_type;

37 
typedef T value_type;

38 
typedef T difference_type;

39 
typedef uint32_t storage_type;

40  
41 
protected:

42 
typedef value_type value_arg_type;

43  
44 
public:

45 
BOOST_DEFAULTED_FUNCTION(base_atomic(void), {})

46 
BOOST_CONSTEXPR explicit base_atomic(value_type v) BOOST_NOEXCEPT : v_(v) {}

47  
48 
void

49 
store(value_type v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT

50 
{ 
51 
platform_fence_before_store(order); 
52 
const_cast<volatile storage_type &>(v_) = v; 
53 
platform_fence_after_store(order); 
54 
} 
55  
56 
value_type 
57 
load(memory_order order = memory_order_seq_cst) const volatile 
58 
{ 
59 
value_type v = const_cast<const volatile storage_type &>(v_); 
60 
platform_fence_after_load(order); 
61 
return v;

62 
} 
63  
64 
value_type 
65 
exchange(value_type v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT

66 
{ 
67 
value_type original = load(memory_order_relaxed); 
68 
do {

69 
} while (!compare_exchange_weak(original, v, order, memory_order_relaxed));

70 
return original;

71 
} 
72  
73 
bool

74 
compare_exchange_weak( 
75 
value_type & expected, 
76 
value_type desired, 
77 
memory_order success_order, 
78 
memory_order failure_order) volatile BOOST_NOEXCEPT

79 
{ 
80 
return compare_exchange_strong(expected, desired, success_order, failure_order);

81 
} 
82  
83 
bool

84 
compare_exchange_strong( 
85 
value_type & expected, 
86 
value_type desired, 
87 
memory_order success_order, 
88 
memory_order failure_order) volatile BOOST_NOEXCEPT

89 
{ 
90 
platform_fence_before(success_order); 
91  
92 
storage_type expected_s = (storage_type) expected; 
93 
storage_type desired_s = (storage_type) desired; 
94  
95 
bool success = platform_cmpxchg32_strong(expected_s, desired_s, &v_);

96  
97 
if (success) {

98 
platform_fence_after(success_order); 
99 
} else {

100 
platform_fence_after(failure_order); 
101 
expected = (value_type) expected_s; 
102 
} 
103  
104 
return success;

105 
} 
106  
107 
value_type 
108 
fetch_add(value_type v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT

109 
{ 
110 
value_type original = load(memory_order_relaxed); 
111 
do {

112 
} while (!compare_exchange_weak(original, original + v, order, memory_order_relaxed));

113 
return original;

114 
} 
115  
116 
value_type 
117 
fetch_sub(value_type v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT

118 
{ 
119 
value_type original = load(memory_order_relaxed); 
120 
do {

121 
} while (!compare_exchange_weak(original, original  v, order, memory_order_relaxed));

122 
return original;

123 
} 
124  
125 
value_type 
126 
fetch_and(value_type v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT

127 
{ 
128 
value_type original = load(memory_order_relaxed); 
129 
do {

130 
} while (!compare_exchange_weak(original, original & v, order, memory_order_relaxed));

131 
return original;

132 
} 
133  
134 
value_type 
135 
fetch_or(value_type v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT

136 
{ 
137 
value_type original = load(memory_order_relaxed); 
138 
do {

139 
} while (!compare_exchange_weak(original, original  v, order, memory_order_relaxed));

140 
return original;

141 
} 
142  
143 
value_type 
144 
fetch_xor(value_type v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT

145 
{ 
146 
value_type original = load(memory_order_relaxed); 
147 
do {

148 
} while (!compare_exchange_weak(original, original ^ v, order, memory_order_relaxed));

149 
return original;

150 
} 
151  
152 
bool

153 
is_lock_free(void) const volatile 
154 
{ 
155 
return true; 
156 
} 
157  
158 
BOOST_ATOMIC_DECLARE_INTEGRAL_OPERATORS 
159  
160 
BOOST_DELETED_FUNCTION(base_atomic(base_atomic const&))

161 
BOOST_DELETED_FUNCTION(base_atomic& operator=(base_atomic const&)) 
162  
163 
private:

164 
storage_type v_; 
165 
}; 
166  
167 
template<typename T, bool Sign> 
168 
class base_atomic<T, int, 2, Sign> 
169 
{ 
170 
private:

171 
typedef base_atomic this_type;

172 
typedef T value_type;

173 
typedef T difference_type;

174 
typedef uint32_t storage_type;

175  
176 
protected:

177 
typedef value_type value_arg_type;

178  
179 
public:

180 
BOOST_DEFAULTED_FUNCTION(base_atomic(void), {})

181 
BOOST_CONSTEXPR explicit base_atomic(value_type v) BOOST_NOEXCEPT : v_(v) {}

182  
183 
void

184 
store(value_type v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT

185 
{ 
186 
platform_fence_before_store(order); 
187 
const_cast<volatile storage_type &>(v_) = v; 
188 
platform_fence_after_store(order); 
189 
} 
190  
191 
value_type 
192 
load(memory_order order = memory_order_seq_cst) const volatile 
193 
{ 
194 
value_type v = const_cast<const volatile storage_type &>(v_); 
195 
platform_fence_after_load(order); 
196 
return v;

197 
} 
198  
199 
value_type 
200 
exchange(value_type v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT

201 
{ 
202 
value_type original = load(memory_order_relaxed); 
203 
do {

204 
} while (!compare_exchange_weak(original, v, order, memory_order_relaxed));

205 
return original;

206 
} 
207  
208 
bool

209 
compare_exchange_weak( 
210 
value_type & expected, 
211 
value_type desired, 
212 
memory_order success_order, 
213 
memory_order failure_order) volatile BOOST_NOEXCEPT

214 
{ 
215 
return compare_exchange_strong(expected, desired, success_order, failure_order);

216 
} 
217  
218 
bool

219 
compare_exchange_strong( 
220 
value_type & expected, 
221 
value_type desired, 
222 
memory_order success_order, 
223 
memory_order failure_order) volatile BOOST_NOEXCEPT

224 
{ 
225 
platform_fence_before(success_order); 
226  
227 
storage_type expected_s = (storage_type) expected; 
228 
storage_type desired_s = (storage_type) desired; 
229  
230 
bool success = platform_cmpxchg32_strong(expected_s, desired_s, &v_);

231  
232 
if (success) {

233 
platform_fence_after(success_order); 
234 
} else {

235 
platform_fence_after(failure_order); 
236 
expected = (value_type) expected_s; 
237 
} 
238  
239 
return success;

240 
} 
241  
242 
value_type 
243 
fetch_add(value_type v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT

244 
{ 
245 
value_type original = load(memory_order_relaxed); 
246 
do {

247 
} while (!compare_exchange_weak(original, original + v, order, memory_order_relaxed));

248 
return original;

249 
} 
250  
251 
value_type 
252 
fetch_sub(value_type v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT

253 
{ 
254 
value_type original = load(memory_order_relaxed); 
255 
do {

256 
} while (!compare_exchange_weak(original, original  v, order, memory_order_relaxed));

257 
return original;

258 
} 
259  
260 
value_type 
261 
fetch_and(value_type v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT

262 
{ 
263 
value_type original = load(memory_order_relaxed); 
264 
do {

265 
} while (!compare_exchange_weak(original, original & v, order, memory_order_relaxed));

266 
return original;

267 
} 
268  
269 
value_type 
270 
fetch_or(value_type v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT

271 
{ 
272 
value_type original = load(memory_order_relaxed); 
273 
do {

274 
} while (!compare_exchange_weak(original, original  v, order, memory_order_relaxed));

275 
return original;

276 
} 
277  
278 
value_type 
279 
fetch_xor(value_type v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT

280 
{ 
281 
value_type original = load(memory_order_relaxed); 
282 
do {

283 
} while (!compare_exchange_weak(original, original ^ v, order, memory_order_relaxed));

284 
return original;

285 
} 
286  
287 
bool

288 
is_lock_free(void) const volatile 
289 
{ 
290 
return true; 
291 
} 
292  
293 
BOOST_ATOMIC_DECLARE_INTEGRAL_OPERATORS 
294  
295 
BOOST_DELETED_FUNCTION(base_atomic(base_atomic const&))

296 
BOOST_DELETED_FUNCTION(base_atomic& operator=(base_atomic const&)) 
297  
298 
private:

299 
storage_type v_; 
300 
}; 
301  
302 
template<typename T, bool Sign> 
303 
class base_atomic<T, int, 4, Sign> 
304 
{ 
305 
private:

306 
typedef base_atomic this_type;

307 
typedef T value_type;

308 
typedef T difference_type;

309  
310 
protected:

311 
typedef value_type value_arg_type;

312  
313 
public:

314 
BOOST_DEFAULTED_FUNCTION(base_atomic(void), {})

315 
BOOST_CONSTEXPR explicit base_atomic(value_type v) BOOST_NOEXCEPT : v_(v) {}

316  
317 
void

318 
store(value_type v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT

319 
{ 
320 
platform_fence_before_store(order); 
321 
const_cast<volatile value_type &>(v_) = v; 
322 
platform_fence_after_store(order); 
323 
} 
324  
325 
value_type 
326 
load(memory_order order = memory_order_seq_cst) const volatile 
327 
{ 
328 
value_type v = const_cast<const volatile value_type &>(v_); 
329 
platform_fence_after_load(order); 
330 
return v;

331 
} 
332  
333 
value_type 
334 
exchange(value_type v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT

335 
{ 
336 
value_type original = load(memory_order_relaxed); 
337 
do {

338 
} while (!compare_exchange_weak(original, v, order, memory_order_relaxed));

339 
return original;

340 
} 
341  
342 
bool

343 
compare_exchange_weak( 
344 
value_type & expected, 
345 
value_type desired, 
346 
memory_order success_order, 
347 
memory_order failure_order) volatile BOOST_NOEXCEPT

348 
{ 
349 
return compare_exchange_strong(expected, desired, success_order, failure_order);

350 
} 
351  
352 
bool

353 
compare_exchange_strong( 
354 
value_type & expected, 
355 
value_type desired, 
356 
memory_order success_order, 
357 
memory_order failure_order) volatile BOOST_NOEXCEPT

358 
{ 
359 
platform_fence_before(success_order); 
360  
361 
bool success = platform_cmpxchg32_strong(expected, desired, &v_);

362  
363 
if (success) {

364 
platform_fence_after(success_order); 
365 
} else {

366 
platform_fence_after(failure_order); 
367 
} 
368  
369 
return success;

370 
} 
371  
372 
value_type 
373 
fetch_add(value_type v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT

374 
{ 
375 
value_type original = load(memory_order_relaxed); 
376 
do {

377 
} while (!compare_exchange_weak(original, original + v, order, memory_order_relaxed));

378 
return original;

379 
} 
380  
381 
value_type 
382 
fetch_sub(value_type v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT

383 
{ 
384 
value_type original = load(memory_order_relaxed); 
385 
do {

386 
} while (!compare_exchange_weak(original, original  v, order, memory_order_relaxed));

387 
return original;

388 
} 
389  
390 
value_type 
391 
fetch_and(value_type v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT

392 
{ 
393 
value_type original = load(memory_order_relaxed); 
394 
do {

395 
} while (!compare_exchange_weak(original, original & v, order, memory_order_relaxed));

396 
return original;

397 
} 
398  
399 
value_type 
400 
fetch_or(value_type v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT

401 
{ 
402 
value_type original = load(memory_order_relaxed); 
403 
do {

404 
} while (!compare_exchange_weak(original, original  v, order, memory_order_relaxed));

405 
return original;

406 
} 
407  
408 
value_type 
409 
fetch_xor(value_type v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT

410 
{ 
411 
value_type original = load(memory_order_relaxed); 
412 
do {

413 
} while (!compare_exchange_weak(original, original ^ v, order, memory_order_relaxed));

414 
return original;

415 
} 
416  
417 
bool

418 
is_lock_free(void) const volatile 
419 
{ 
420 
return true; 
421 
} 
422  
423 
BOOST_ATOMIC_DECLARE_INTEGRAL_OPERATORS 
424  
425 
BOOST_DELETED_FUNCTION(base_atomic(base_atomic const&))

426 
BOOST_DELETED_FUNCTION(base_atomic& operator=(base_atomic const&)) 
427  
428 
private:

429 
value_type v_; 
430 
}; 
431  
432 
/* pointer types */

433  
434 
template<bool Sign> 
435 
class base_atomic<void *, void *, 4, Sign> 
436 
{ 
437 
private:

438 
typedef base_atomic this_type;

439 
typedef void * value_type; 
440 
typedef std::ptrdiff_t difference_type;

441  
442 
protected:

443 
typedef value_type value_arg_type;

444  
445 
public:

446 
BOOST_DEFAULTED_FUNCTION(base_atomic(void), {})

447 
BOOST_CONSTEXPR explicit base_atomic(value_type v) BOOST_NOEXCEPT : v_(v) {}

448  
449 
void

450 
store(value_type v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT

451 
{ 
452 
platform_fence_before_store(order); 
453 
const_cast<volatile value_type &>(v_) = v; 
454 
platform_fence_after_store(order); 
455 
} 
456  
457 
value_type 
458 
load(memory_order order = memory_order_seq_cst) const volatile 
459 
{ 
460 
value_type v = const_cast<const volatile value_type &>(v_); 
461 
platform_fence_after_load(order); 
462 
return v;

463 
} 
464  
465 
value_type 
466 
exchange(value_type v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT

467 
{ 
468 
value_type original = load(memory_order_relaxed); 
469 
do {

470 
} while (!compare_exchange_weak(original, v, order, memory_order_relaxed));

471 
return original;

472 
} 
473  
474 
bool

475 
compare_exchange_weak( 
476 
value_type & expected, 
477 
value_type desired, 
478 
memory_order success_order, 
479 
memory_order failure_order) volatile BOOST_NOEXCEPT

480 
{ 
481 
return compare_exchange_strong(expected, desired, success_order, failure_order);

482 
} 
483  
484 
bool

485 
compare_exchange_strong( 
486 
value_type & expected, 
487 
value_type desired, 
488 
memory_order success_order, 
489 
memory_order failure_order) volatile BOOST_NOEXCEPT

490 
{ 
491 
platform_fence_before(success_order); 
492  
493 
bool success = platform_cmpxchg32_strong(expected, desired, &v_);

494  
495 
if (success) {

496 
platform_fence_after(success_order); 
497 
} else {

498 
platform_fence_after(failure_order); 
499 
} 
500  
501 
return success;

502 
} 
503  
504 
value_type 
505 
fetch_add(difference_type v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT

506 
{ 
507 
value_type original = load(memory_order_relaxed); 
508 
do {

509 
} while (!compare_exchange_weak(original, (char*)original + v, order, memory_order_relaxed)); 
510 
return original;

511 
} 
512  
513 
value_type 
514 
fetch_sub(difference_type v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT

515 
{ 
516 
value_type original = load(memory_order_relaxed); 
517 
do {

518 
} while (!compare_exchange_weak(original, (char*)original  v, order, memory_order_relaxed)); 
519 
return original;

520 
} 
521  
522 
bool

523 
is_lock_free(void) const volatile 
524 
{ 
525 
return true; 
526 
} 
527  
528 
BOOST_ATOMIC_DECLARE_VOID_POINTER_OPERATORS 
529  
530 
BOOST_DELETED_FUNCTION(base_atomic(base_atomic const&))

531 
BOOST_DELETED_FUNCTION(base_atomic& operator=(base_atomic const&)) 
532  
533 
private:

534 
value_type v_; 
535 
}; 
536  
537 
template<typename T, bool Sign> 
538 
class base_atomic<T *, void *, 4, Sign> 
539 
{ 
540 
private:

541 
typedef base_atomic this_type;

542 
typedef T * value_type;

543 
typedef std::ptrdiff_t difference_type;

544  
545 
protected:

546 
typedef value_type value_arg_type;

547  
548 
public:

549 
BOOST_DEFAULTED_FUNCTION(base_atomic(void), {})

550 
BOOST_CONSTEXPR explicit base_atomic(value_type v) BOOST_NOEXCEPT : v_(v) {}

551  
552 
void

553 
store(value_type v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT

554 
{ 
555 
platform_fence_before_store(order); 
556 
const_cast<volatile value_type &>(v_) = v; 
557 
platform_fence_after_store(order); 
558 
} 
559  
560 
value_type 
561 
load(memory_order order = memory_order_seq_cst) const volatile 
562 
{ 
563 
value_type v = const_cast<const volatile value_type &>(v_); 
564 
platform_fence_after_load(order); 
565 
return v;

566 
} 
567  
568 
value_type 
569 
exchange(value_type v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT

570 
{ 
571 
value_type original = load(memory_order_relaxed); 
572 
do {

573 
} while (!compare_exchange_weak(original, v, order, memory_order_relaxed));

574 
return original;

575 
} 
576  
577 
bool

578 
compare_exchange_weak( 
579 
value_type & expected, 
580 
value_type desired, 
581 
memory_order success_order, 
582 
memory_order failure_order) volatile BOOST_NOEXCEPT

583 
{ 
584 
return compare_exchange_strong(expected, desired, success_order, failure_order);

585 
} 
586  
587 
bool

588 
compare_exchange_strong( 
589 
value_type & expected, 
590 
value_type desired, 
591 
memory_order success_order, 
592 
memory_order failure_order) volatile BOOST_NOEXCEPT

593 
{ 
594 
platform_fence_before(success_order); 
595  
596 
bool success = platform_cmpxchg32_strong(expected, desired, &v_);

597  
598 
if (success) {

599 
platform_fence_after(success_order); 
600 
} else {

601 
platform_fence_after(failure_order); 
602 
} 
603  
604 
return success;

605 
} 
606  
607 
value_type 
608 
fetch_add(difference_type v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT

609 
{ 
610 
value_type original = load(memory_order_relaxed); 
611 
do {

612 
} while (!compare_exchange_weak(original, original + v, order, memory_order_relaxed));

613 
return original;

614 
} 
615  
616 
value_type 
617 
fetch_sub(difference_type v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT

618 
{ 
619 
value_type original = load(memory_order_relaxed); 
620 
do {

621 
} while (!compare_exchange_weak(original, original  v, order, memory_order_relaxed));

622 
return original;

623 
} 
624  
625 
bool

626 
is_lock_free(void) const volatile 
627 
{ 
628 
return true; 
629 
} 
630  
631 
BOOST_ATOMIC_DECLARE_POINTER_OPERATORS 
632  
633 
BOOST_DELETED_FUNCTION(base_atomic(base_atomic const&))

634 
BOOST_DELETED_FUNCTION(base_atomic& operator=(base_atomic const&)) 
635  
636 
private:

637 
value_type v_; 
638 
}; 
639  
640 
/* generic types */

641  
642 
template<typename T, bool Sign> 
643 
class base_atomic<T, void, 1, Sign> 
644 
{ 
645 
private:

646 
typedef base_atomic this_type;

647 
typedef T value_type;

648 
typedef uint32_t storage_type;

649  
650 
protected:

651 
typedef value_type const& value_arg_type; 
652  
653 
public:

654 
BOOST_DEFAULTED_FUNCTION(base_atomic(void), {})

655 
explicit base_atomic(value_type const& v) BOOST_NOEXCEPT : v_(0) 
656 
{ 
657 
memcpy(&v_, &v, sizeof(value_type));

658 
} 
659  
660 
void

661 
store(value_type const& v, memory_order order = memory_order_seq_cst) ) volatile BOOST_NOEXCEPT 
662 
{ 
663 
storage_type tmp = 0;

664 
memcpy(&tmp, &v, sizeof(value_type));

665 
platform_fence_before_store(order); 
666 
const_cast<volatile storage_type &>(v_) = tmp; 
667 
platform_fence_after_store(order); 
668 
} 
669  
670 
value_type 
671 
load(memory_order order = memory_order_seq_cst) const volatile 
672 
{ 
673 
storage_type tmp = const_cast<const volatile storage_type &>(v_); 
674 
platform_fence_after_load(order); 
675  
676 
value_type v; 
677 
memcpy(&v, &tmp, sizeof(value_type));

678 
return v;

679 
} 
680  
681 
value_type 
682 
exchange(value_type const& v, memory_order order = memory_order_seq_cst) ) volatile BOOST_NOEXCEPT 
683 
{ 
684 
value_type original = load(memory_order_relaxed); 
685 
do {

686 
} while (!compare_exchange_weak(original, v, order, memory_order_relaxed));

687 
return original;

688 
} 
689  
690 
bool

691 
compare_exchange_weak( 
692 
value_type & expected, 
693 
value_type const& desired,

694 
memory_order success_order, 
695 
memory_order failure_order) ) volatile BOOST_NOEXCEPT

696 
{ 
697 
return compare_exchange_strong(expected, desired, success_order, failure_order);

698 
} 
699  
700 
bool

701 
compare_exchange_strong( 
702 
value_type & expected, 
703 
value_type const& desired,

704 
memory_order success_order, 
705 
memory_order failure_order) ) volatile BOOST_NOEXCEPT

706 
{ 
707 
storage_type expected_s = 0, desired_s = 0; 
708 
memcpy(&expected_s, &expected, sizeof(value_type));

709 
memcpy(&desired_s, &desired, sizeof(value_type));

710  
711 
platform_fence_before(success_order); 
712 
bool success = platform_cmpxchg32_strong(expected_s, desired_s, &v_);

713  
714 
if (success) {

715 
platform_fence_after(success_order); 
716 
} else {

717 
platform_fence_after(failure_order); 
718 
memcpy(&expected, &expected_s, sizeof(value_type));

719 
} 
720  
721 
return success;

722 
} 
723  
724 
bool

725 
is_lock_free(void) const volatile 
726 
{ 
727 
return true; 
728 
} 
729  
730 
BOOST_ATOMIC_DECLARE_BASE_OPERATORS 
731  
732 
BOOST_DELETED_FUNCTION(base_atomic(base_atomic const&))

733 
BOOST_DELETED_FUNCTION(base_atomic& operator=(base_atomic const&)) 
734  
735 
private:

736 
storage_type v_; 
737 
}; 
738  
739 
template<typename T, bool Sign> 
740 
class base_atomic<T, void, 2, Sign> 
741 
{ 
742 
private:

743 
typedef base_atomic this_type;

744 
typedef T value_type;

745 
typedef uint32_t storage_type;

746  
747 
protected:

748 
typedef value_type const& value_arg_type; 
749  
750 
public:

751 
BOOST_DEFAULTED_FUNCTION(base_atomic(void), {})

752 
explicit base_atomic(value_type const& v) BOOST_NOEXCEPT : v_(0) 
753 
{ 
754 
memcpy(&v_, &v, sizeof(value_type));

755 
} 
756  
757 
void

758 
store(value_type const& v, memory_order order = memory_order_seq_cst) ) volatile BOOST_NOEXCEPT 
759 
{ 
760 
storage_type tmp = 0;

761 
memcpy(&tmp, &v, sizeof(value_type));

762 
platform_fence_before_store(order); 
763 
const_cast<volatile storage_type &>(v_) = tmp; 
764 
platform_fence_after_store(order); 
765 
} 
766  
767 
value_type 
768 
load(memory_order order = memory_order_seq_cst) const volatile 
769 
{ 
770 
storage_type tmp = const_cast<const volatile storage_type &>(v_); 
771 
platform_fence_after_load(order); 
772  
773 
value_type v; 
774 
memcpy(&v, &tmp, sizeof(value_type));

775 
return v;

776 
} 
777  
778 
value_type 
779 
exchange(value_type const& v, memory_order order = memory_order_seq_cst) ) volatile BOOST_NOEXCEPT 
780 
{ 
781 
value_type original = load(memory_order_relaxed); 
782 
do {

783 
} while (!compare_exchange_weak(original, v, order, memory_order_relaxed));

784 
return original;

785 
} 
786  
787 
bool

788 
compare_exchange_weak( 
789 
value_type & expected, 
790 
value_type const& desired,

791 
memory_order success_order, 
792 
memory_order failure_order) volatile BOOST_NOEXCEPT

793 
{ 
794 
return compare_exchange_strong(expected, desired, success_order, failure_order);

795 
} 
796  
797 
bool

798 
compare_exchange_strong( 
799 
value_type & expected, 
800 
value_type const& desired,

801 
memory_order success_order, 
802 
memory_order failure_order) volatile BOOST_NOEXCEPT

803 
{ 
804  
805 
storage_type expected_s = 0, desired_s = 0; 
806 
memcpy(&expected_s, &expected, sizeof(value_type));

807 
memcpy(&desired_s, &desired, sizeof(value_type));

808  
809 
platform_fence_before(success_order); 
810 
bool success = platform_cmpxchg32_strong(expected_s, desired_s, &v_);

811  
812 
if (success) {

813 
platform_fence_after(success_order); 
814 
} else {

815 
platform_fence_after(failure_order); 
816 
memcpy(&expected, &expected_s, sizeof(value_type));

817 
} 
818  
819 
return success;

820 
} 
821  
822 
bool

823 
is_lock_free(void) const volatile 
824 
{ 
825 
return true; 
826 
} 
827  
828 
BOOST_ATOMIC_DECLARE_BASE_OPERATORS 
829  
830 
BOOST_DELETED_FUNCTION(base_atomic(base_atomic const&))

831 
BOOST_DELETED_FUNCTION(base_atomic& operator=(base_atomic const&)) 
832  
833 
private:

834 
storage_type v_; 
835 
}; 
836  
837 
template<typename T, bool Sign> 
838 
class base_atomic<T, void, 4, Sign> 
839 
{ 
840 
private:

841 
typedef base_atomic this_type;

842 
typedef T value_type;

843 
typedef uint32_t storage_type;

844  
845 
protected:

846 
typedef value_type const& value_arg_type; 
847  
848 
public:

849 
BOOST_DEFAULTED_FUNCTION(base_atomic(void), {})

850 
explicit base_atomic(value_type const& v) BOOST_NOEXCEPT : v_(0) 
851 
{ 
852 
memcpy(&v_, &v, sizeof(value_type));

853 
} 
854  
855 
void

856 
store(value_type const& v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT 
857 
{ 
858 
storage_type tmp = 0;

859 
memcpy(&tmp, &v, sizeof(value_type));

860 
platform_fence_before_store(order); 
861 
const_cast<volatile storage_type &>(v_) = tmp; 
862 
platform_fence_after_store(order); 
863 
} 
864  
865 
value_type 
866 
load(memory_order order = memory_order_seq_cst) const volatile 
867 
{ 
868 
storage_type tmp = const_cast<const volatile storage_type &>(v_); 
869 
platform_fence_after_load(order); 
870  
871 
value_type v; 
872 
memcpy(&v, &tmp, sizeof(value_type));

873 
return v;

874 
} 
875  
876 
value_type 
877 
exchange(value_type const& v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT 
878 
{ 
879 
value_type original = load(memory_order_relaxed); 
880 
do {

881 
} while (!compare_exchange_weak(original, v, order, memory_order_relaxed));

882 
return original;

883 
} 
884  
885 
bool

886 
compare_exchange_weak( 
887 
value_type & expected, 
888 
value_type const& desired,

889 
memory_order success_order, 
890 
memory_order failure_order) volatile BOOST_NOEXCEPT

891 
{ 
892 
return compare_exchange_strong(expected, desired, success_order, failure_order);

893 
} 
894  
895 
bool

896 
compare_exchange_strong( 
897 
value_type & expected, 
898 
value_type const& desired,

899 
memory_order success_order, 
900 
memory_order failure_order) volatile BOOST_NOEXCEPT

901 
{ 
902  
903 
storage_type expected_s = 0, desired_s = 0; 
904 
memcpy(&expected_s, &expected, sizeof(value_type));

905 
memcpy(&desired_s, &desired, sizeof(value_type));

906  
907 
platform_fence_before(success_order); 
908 
bool success = platform_cmpxchg32_strong(expected_s, desired_s, &v_);

909  
910 
if (success) {

911 
platform_fence_after(success_order); 
912 
} else {

913 
platform_fence_after(failure_order); 
914 
memcpy(&expected, &expected_s, sizeof(value_type));

915 
} 
916  
917 
return success;

918 
} 
919  
920 
bool

921 
is_lock_free(void) const volatile 
922 
{ 
923 
return true; 
924 
} 
925  
926 
BOOST_ATOMIC_DECLARE_BASE_OPERATORS 
927  
928 
BOOST_DELETED_FUNCTION(base_atomic(base_atomic const&))

929 
BOOST_DELETED_FUNCTION(base_atomic& operator=(base_atomic const&)) 
930  
931 
private:

932 
storage_type v_; 
933 
}; 
934  
935 
} 
936 
} 
937 
} 
938  
939 
#endif
