Statistics
| Revision:

root / tmp / org.txm.statsengine.r.core.win32 / res / win32 / library / BH / include / boost / atomic / detail / gcc-sparcv9.hpp @ 2486

History | View | Annotate | Download (37.2 kB)

1
#ifndef BOOST_ATOMIC_DETAIL_GCC_SPARC_HPP
2
#define BOOST_ATOMIC_DETAIL_GCC_SPARC_HPP
3

    
4
//  Copyright (c) 2010 Helge Bahmann
5
//  Copyright (c) 2013 Tim Blechmann
6
//
7
//  Distributed under the Boost Software License, Version 1.0.
8
//  See accompanying file LICENSE_1_0.txt or copy at
9
//  http://www.boost.org/LICENSE_1_0.txt)
10

    
11
#include <string.h>
12
#include <cstddef>
13
#include <boost/cstdint.hpp>
14
#include <boost/atomic/detail/config.hpp>
15

    
16
#ifdef BOOST_HAS_PRAGMA_ONCE
17
#pragma once
18
#endif
19

    
20
namespace boost {
21
namespace atomics {
22
namespace detail {
23

    
24
inline void
25
platform_fence_before(memory_order order)
26
{
27
    switch(order)
28
    {
29
    case memory_order_relaxed:
30
    case memory_order_acquire:
31
    case memory_order_consume:
32
        break;
33
    case memory_order_release:
34
    case memory_order_acq_rel:
35
        __asm__ __volatile__ ("membar #StoreStore | #LoadStore" ::: "memory");
36
        /* release */
37
        break;
38
    case memory_order_seq_cst:
39
        __asm__ __volatile__ ("membar #Sync" ::: "memory");
40
        /* seq */
41
        break;
42
    }
43
}
44

    
45
inline void
46
platform_fence_after(memory_order order)
47
{
48
    switch(order)
49
    {
50
    case memory_order_relaxed:
51
    case memory_order_release:
52
        break;
53
    case memory_order_acquire:
54
    case memory_order_acq_rel:
55
        __asm__ __volatile__ ("membar #LoadLoad | #LoadStore" ::: "memory");
56
        /* acquire */
57
        break;
58
    case memory_order_consume:
59
        /* consume */
60
        break;
61
    case memory_order_seq_cst:
62
        __asm__ __volatile__ ("membar #Sync" ::: "memory");
63
        /* seq */
64
        break;
65
    default:;
66
    }
67
}
68

    
69
inline void
70
platform_fence_after_store(memory_order order)
71
{
72
    switch(order)
73
    {
74
    case memory_order_seq_cst:
75
        __asm__ __volatile__ ("membar #Sync" ::: "memory");
76
    default:;
77
    }
78
}
79

    
80

    
81
inline void
82
platform_fence_after_load(memory_order order)
83
{
84
    platform_fence_after(order);
85
}
86

    
87
}
88
}
89

    
90
class atomic_flag
91
{
92
private:
93
    atomic_flag(const atomic_flag &) /* = delete */ ;
94
    atomic_flag & operator=(const atomic_flag &) /* = delete */ ;
95
    uint32_t v_;
96
public:
97
    BOOST_CONSTEXPR atomic_flag(void) BOOST_NOEXCEPT : v_(0) {}
98

    
99
    void
100
    clear(memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT
101
    {
102
        atomics::detail::platform_fence_before(order);
103
        const_cast<volatile uint32_t &>(v_) = 0;
104
        atomics::detail::platform_fence_after_store(order);
105
    }
106

    
107
    bool
108
    test_and_set(memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT
109
    {
110
        atomics::detail::platform_fence_before(order);
111
        uint32_t tmp = 1;
112
        __asm__ (
113
            "cas [%1], %2, %0"
114
            : "+r" (tmp)
115
            : "r" (&v_), "r" (0)
116
            : "memory"
117
        );
118
        atomics::detail::platform_fence_after(order);
119
        return tmp;
120
    }
121
};
122

    
123
} /* namespace boost */
124

    
125
#define BOOST_ATOMIC_FLAG_LOCK_FREE 2
126

    
127
#include <boost/atomic/detail/base.hpp>
128

    
129
#if !defined(BOOST_ATOMIC_FORCE_FALLBACK)
130

    
131
#define BOOST_ATOMIC_CHAR_LOCK_FREE 2
132
#define BOOST_ATOMIC_CHAR16_T_LOCK_FREE 2
133
#define BOOST_ATOMIC_CHAR32_T_LOCK_FREE 2
134
#define BOOST_ATOMIC_WCHAR_T_LOCK_FREE 2
135
#define BOOST_ATOMIC_SHORT_LOCK_FREE 2
136
#define BOOST_ATOMIC_INT_LOCK_FREE 2
137
#define BOOST_ATOMIC_LONG_LOCK_FREE 2
138
#define BOOST_ATOMIC_LLONG_LOCK_FREE 0
139
#define BOOST_ATOMIC_POINTER_LOCK_FREE 2
140
#define BOOST_ATOMIC_BOOL_LOCK_FREE 2
141

    
142
namespace boost {
143

    
144
#define BOOST_ATOMIC_THREAD_FENCE 2
145
inline void
146
atomic_thread_fence(memory_order order)
147
{
148
    switch(order)
149
    {
150
    case memory_order_relaxed:
151
        break;
152
    case memory_order_release:
153
        __asm__ __volatile__ ("membar #StoreStore | #LoadStore" ::: "memory");
154
        break;
155
    case memory_order_acquire:
156
        __asm__ __volatile__ ("membar #LoadLoad | #LoadStore" ::: "memory");
157
        break;
158
    case memory_order_acq_rel:
159
        __asm__ __volatile__ ("membar #LoadLoad | #LoadStore | #StoreStore" ::: "memory");
160
        break;
161
    case memory_order_consume:
162
        break;
163
    case memory_order_seq_cst:
164
        __asm__ __volatile__ ("membar #Sync" ::: "memory");
165
        break;
166
    default:;
167
    }
168
}
169

    
170
#define BOOST_ATOMIC_SIGNAL_FENCE 2
171
inline void
172
atomic_signal_fence(memory_order)
173
{
174
    __asm__ __volatile__ ("" ::: "memory");
175
}
176

    
177
namespace atomics {
178
namespace detail {
179

    
180
/* integral types */
181

    
182
template<typename T>
183
class base_atomic<T, int, 1, true>
184
{
185
private:
186
    typedef base_atomic this_type;
187
    typedef T value_type;
188
    typedef T difference_type;
189
    typedef int32_t storage_type;
190

    
191
protected:
192
    typedef value_type value_arg_type;
193

    
194
public:
195
    BOOST_DEFAULTED_FUNCTION(base_atomic(void), {})
196
    BOOST_CONSTEXPR explicit base_atomic(value_type v) BOOST_NOEXCEPT : v_(v) {}
197

    
198
    void
199
    store(value_type v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT
200
    {
201
        platform_fence_before(order);
202
        const_cast<volatile storage_type &>(v_) = v;
203
        platform_fence_after_store(order);
204
    }
205

    
206
    value_type
207
    load(memory_order order = memory_order_seq_cst) const volatile BOOST_NOEXCEPT
208
    {
209
        value_type v = const_cast<const volatile storage_type &>(v_);
210
        platform_fence_after_load(order);
211
        return v;
212
    }
213

    
214
    value_type
215
    fetch_add(value_type v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT
216
    {
217
        value_type tmp = load(memory_order_relaxed);
218
        do {} while(!compare_exchange_weak(tmp, tmp + v, order, memory_order_relaxed));
219
        return tmp;
220
    }
221

    
222
    value_type
223
    fetch_sub(value_type v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT
224
    {
225
        value_type tmp = load(memory_order_relaxed);
226
        do {} while(!compare_exchange_weak(tmp, tmp - v, order, memory_order_relaxed));
227
        return tmp;
228
    }
229

    
230
    value_type
231
    exchange(value_type v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT
232
    {
233
        value_type tmp = load(memory_order_relaxed);
234
        do {} while(!compare_exchange_weak(tmp, v, order, memory_order_relaxed));
235
        return tmp;
236
    }
237

    
238
    bool
239
    compare_exchange_strong(
240
        value_type & expected,
241
        value_type desired,
242
        memory_order success_order,
243
        memory_order failure_order) volatile BOOST_NOEXCEPT
244
    {
245
        platform_fence_before(success_order);
246
        storage_type desired_s = desired;
247
        __asm__ (
248
            "cas [%1], %2, %0"
249
            : "+r" (desired_s)
250
            : "r" (&v_), "r" ((storage_type)expected)
251
            : "memory"
252
        );
253
        desired = desired_s;
254
        bool success = (desired == expected);
255
        if (success)
256
            platform_fence_after(success_order);
257
        else
258
            platform_fence_after(failure_order);
259
        expected = desired;
260
        return success;
261
    }
262

    
263
    bool
264
    compare_exchange_weak(
265
        value_type & expected,
266
        value_type desired,
267
        memory_order success_order,
268
        memory_order failure_order) volatile BOOST_NOEXCEPT
269
    {
270
        return compare_exchange_strong(expected, desired, success_order, failure_order);
271
    }
272

    
273
    value_type
274
    fetch_and(value_type v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT
275
    {
276
        value_type tmp = load(memory_order_relaxed);
277
        do {} while(!compare_exchange_weak(tmp, tmp & v, order, memory_order_relaxed));
278
        return tmp;
279
    }
280

    
281
    value_type
282
    fetch_or(value_type v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT
283
    {
284
        value_type tmp = load(memory_order_relaxed);
285
        do {} while(!compare_exchange_weak(tmp, tmp | v, order, memory_order_relaxed));
286
        return tmp;
287
    }
288

    
289
    value_type
290
    fetch_xor(value_type v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT
291
    {
292
        value_type tmp = load(memory_order_relaxed);
293
        do {} while(!compare_exchange_weak(tmp, tmp ^ v, order, memory_order_relaxed));
294
        return tmp;
295
    }
296

    
297
    bool
298
    is_lock_free(void) const volatile BOOST_NOEXCEPT
299
    {
300
        return true;
301
    }
302

    
303
    BOOST_ATOMIC_DECLARE_INTEGRAL_OPERATORS
304

    
305
    BOOST_DELETED_FUNCTION(base_atomic(base_atomic const&))
306
    BOOST_DELETED_FUNCTION(base_atomic& operator=(base_atomic const&))
307

    
308
private:
309
    storage_type v_;
310
};
311

    
312
template<typename T>
313
class base_atomic<T, int, 1, false>
314
{
315
private:
316
    typedef base_atomic this_type;
317
    typedef T value_type;
318
    typedef T difference_type;
319
    typedef uint32_t storage_type;
320

    
321
protected:
322
    typedef value_type value_arg_type;
323

    
324
public:
325
    BOOST_DEFAULTED_FUNCTION(base_atomic(void), {})
326
    BOOST_CONSTEXPR explicit base_atomic(value_type v) BOOST_NOEXCEPT : v_(v) {}
327

    
328
    void
329
    store(value_type v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT
330
    {
331
        platform_fence_before(order);
332
        const_cast<volatile storage_type &>(v_) = v;
333
        platform_fence_after_store(order);
334
    }
335

    
336
    value_type
337
    load(memory_order order = memory_order_seq_cst) const volatile BOOST_NOEXCEPT
338
    {
339
        value_type v = const_cast<const volatile storage_type &>(v_);
340
        platform_fence_after_load(order);
341
        return v;
342
    }
343

    
344
    value_type
345
    fetch_add(value_type v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT
346
    {
347
        value_type tmp = load(memory_order_relaxed);
348
        do {} while(!compare_exchange_weak(tmp, tmp + v, order, memory_order_relaxed));
349
        return tmp;
350
    }
351

    
352
    value_type
353
    fetch_sub(value_type v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT
354
    {
355
        value_type tmp = load(memory_order_relaxed);
356
        do {} while(!compare_exchange_weak(tmp, tmp - v, order, memory_order_relaxed));
357
        return tmp;
358
    }
359

    
360
    value_type
361
    exchange(value_type v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT
362
    {
363
        value_type tmp = load(memory_order_relaxed);
364
        do {} while(!compare_exchange_weak(tmp, v, order, memory_order_relaxed));
365
        return tmp;
366
    }
367

    
368
    bool
369
    compare_exchange_strong(
370
        value_type & expected,
371
        value_type desired,
372
        memory_order success_order,
373
        memory_order failure_order) volatile BOOST_NOEXCEPT
374
    {
375
        platform_fence_before(success_order);
376
        storage_type desired_s = desired;
377
        __asm__ (
378
            "cas [%1], %2, %0"
379
            : "+r" (desired_s)
380
            : "r" (&v_), "r" ((storage_type)expected)
381
            : "memory"
382
        );
383
        desired = desired_s;
384
        bool success = (desired == expected);
385
        if (success)
386
            platform_fence_after(success_order);
387
        else
388
            platform_fence_after(failure_order);
389
        expected = desired;
390
        return success;
391
    }
392

    
393
    bool
394
    compare_exchange_weak(
395
        value_type & expected,
396
        value_type desired,
397
        memory_order success_order,
398
        memory_order failure_order) volatile BOOST_NOEXCEPT
399
    {
400
        return compare_exchange_strong(expected, desired, success_order, failure_order);
401
    }
402

    
403
    value_type
404
    fetch_and(value_type v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT
405
    {
406
        value_type tmp = load(memory_order_relaxed);
407
        do {} while(!compare_exchange_weak(tmp, tmp & v, order, memory_order_relaxed));
408
        return tmp;
409
    }
410

    
411
    value_type
412
    fetch_or(value_type v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT
413
    {
414
        value_type tmp = load(memory_order_relaxed);
415
        do {} while(!compare_exchange_weak(tmp, tmp | v, order, memory_order_relaxed));
416
        return tmp;
417
    }
418

    
419
    value_type
420
    fetch_xor(value_type v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT
421
    {
422
        value_type tmp = load(memory_order_relaxed);
423
        do {} while(!compare_exchange_weak(tmp, tmp ^ v, order, memory_order_relaxed));
424
        return tmp;
425
    }
426

    
427
    bool
428
    is_lock_free(void) const volatile BOOST_NOEXCEPT
429
    {
430
        return true;
431
    }
432

    
433
    BOOST_ATOMIC_DECLARE_INTEGRAL_OPERATORS
434

    
435
    BOOST_DELETED_FUNCTION(base_atomic(base_atomic const&))
436
    BOOST_DELETED_FUNCTION(base_atomic& operator=(base_atomic const&))
437

    
438
private:
439
    storage_type v_;
440
};
441

    
442
template<typename T>
443
class base_atomic<T, int, 2, true>
444
{
445
private:
446
    typedef base_atomic this_type;
447
    typedef T value_type;
448
    typedef T difference_type;
449
    typedef int32_t storage_type;
450

    
451
protected:
452
    typedef value_type value_arg_type;
453

    
454
public:
455
    BOOST_DEFAULTED_FUNCTION(base_atomic(void), {})
456
    BOOST_CONSTEXPR explicit base_atomic(value_type v) BOOST_NOEXCEPT : v_(v) {}
457

    
458
    void
459
    store(value_type v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT
460
    {
461
        platform_fence_before(order);
462
        const_cast<volatile storage_type &>(v_) = v;
463
        platform_fence_after_store(order);
464
    }
465

    
466
    value_type
467
    load(memory_order order = memory_order_seq_cst) const volatile BOOST_NOEXCEPT
468
    {
469
        value_type v = const_cast<const volatile storage_type &>(v_);
470
        platform_fence_after_load(order);
471
        return v;
472
    }
473

    
474
    value_type
475
    fetch_add(value_type v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT
476
    {
477
        value_type tmp = load(memory_order_relaxed);
478
        do {} while(!compare_exchange_weak(tmp, tmp + v, order, memory_order_relaxed));
479
        return tmp;
480
    }
481

    
482
    value_type
483
    fetch_sub(value_type v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT
484
    {
485
        value_type tmp = load(memory_order_relaxed);
486
        do {} while(!compare_exchange_weak(tmp, tmp - v, order, memory_order_relaxed));
487
        return tmp;
488
    }
489

    
490
    value_type
491
    exchange(value_type v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT
492
    {
493
        value_type tmp = load(memory_order_relaxed);
494
        do {} while(!compare_exchange_weak(tmp, v, order, memory_order_relaxed));
495
        return tmp;
496
    }
497

    
498
    bool
499
    compare_exchange_strong(
500
        value_type & expected,
501
        value_type desired,
502
        memory_order success_order,
503
        memory_order failure_order) volatile BOOST_NOEXCEPT
504
    {
505
        platform_fence_before(success_order);
506
        storage_type desired_s = desired;
507
        __asm__ (
508
            "cas [%1], %2, %0"
509
            : "+r" (desired_s)
510
            : "r" (&v_), "r" ((storage_type)expected)
511
            : "memory"
512
        );
513
        desired = desired_s;
514
        bool success = (desired == expected);
515
        if (success)
516
            platform_fence_after(success_order);
517
        else
518
            platform_fence_after(failure_order);
519
        expected = desired;
520
        return success;
521
    }
522

    
523
    bool
524
    compare_exchange_weak(
525
        value_type & expected,
526
        value_type desired,
527
        memory_order success_order,
528
        memory_order failure_order) volatile BOOST_NOEXCEPT
529
    {
530
        return compare_exchange_strong(expected, desired, success_order, failure_order);
531
    }
532

    
533
    value_type
534
    fetch_and(value_type v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT
535
    {
536
        value_type tmp = load(memory_order_relaxed);
537
        do {} while(!compare_exchange_weak(tmp, tmp & v, order, memory_order_relaxed));
538
        return tmp;
539
    }
540

    
541
    value_type
542
    fetch_or(value_type v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT
543
    {
544
        value_type tmp = load(memory_order_relaxed);
545
        do {} while(!compare_exchange_weak(tmp, tmp | v, order, memory_order_relaxed));
546
        return tmp;
547
    }
548

    
549
    value_type
550
    fetch_xor(value_type v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT
551
    {
552
        value_type tmp = load(memory_order_relaxed);
553
        do {} while(!compare_exchange_weak(tmp, tmp ^ v, order, memory_order_relaxed));
554
        return tmp;
555
    }
556

    
557
    bool
558
    is_lock_free(void) const volatile BOOST_NOEXCEPT
559
    {
560
        return true;
561
    }
562

    
563
    BOOST_ATOMIC_DECLARE_INTEGRAL_OPERATORS
564

    
565
    BOOST_DELETED_FUNCTION(base_atomic(base_atomic const&))
566
    BOOST_DELETED_FUNCTION(base_atomic& operator=(base_atomic const&))
567

    
568
private:
569
    storage_type v_;
570
};
571

    
572
template<typename T>
573
class base_atomic<T, int, 2, false>
574
{
575
private:
576
    typedef base_atomic this_type;
577
    typedef T value_type;
578
    typedef T difference_type;
579
    typedef uint32_t storage_type;
580

    
581
protected:
582
    typedef value_type value_arg_type;
583

    
584
public:
585
    BOOST_DEFAULTED_FUNCTION(base_atomic(void), {})
586
    BOOST_CONSTEXPR explicit base_atomic(value_type v) BOOST_NOEXCEPT : v_(v) {}
587

    
588
    void
589
    store(value_type v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT
590
    {
591
        platform_fence_before(order);
592
        const_cast<volatile storage_type &>(v_) = v;
593
        platform_fence_after_store(order);
594
    }
595

    
596
    value_type
597
    load(memory_order order = memory_order_seq_cst) const volatile BOOST_NOEXCEPT
598
    {
599
        value_type v = const_cast<const volatile storage_type &>(v_);
600
        platform_fence_after_load(order);
601
        return v;
602
    }
603

    
604
    value_type
605
    fetch_add(value_type v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT
606
    {
607
        value_type tmp = load(memory_order_relaxed);
608
        do {} while(!compare_exchange_weak(tmp, tmp + v, order, memory_order_relaxed));
609
        return tmp;
610
    }
611

    
612
    value_type
613
    fetch_sub(value_type v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT
614
    {
615
        value_type tmp = load(memory_order_relaxed);
616
        do {} while(!compare_exchange_weak(tmp, tmp - v, order, memory_order_relaxed));
617
        return tmp;
618
    }
619

    
620
    value_type
621
    exchange(value_type v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT
622
    {
623
        value_type tmp = load(memory_order_relaxed);
624
        do {} while(!compare_exchange_weak(tmp, v, order, memory_order_relaxed));
625
        return tmp;
626
    }
627

    
628
    bool
629
    compare_exchange_strong(
630
        value_type & expected,
631
        value_type desired,
632
        memory_order success_order,
633
        memory_order failure_order) volatile BOOST_NOEXCEPT
634
    {
635
        platform_fence_before(success_order);
636
        storage_type desired_s = desired;
637
        __asm__ (
638
            "cas [%1], %2, %0"
639
            : "+r" (desired_s)
640
            : "r" (&v_), "r" ((storage_type)expected)
641
            : "memory"
642
        );
643
        desired = desired_s;
644
        bool success = (desired == expected);
645
        if (success)
646
            platform_fence_after(success_order);
647
        else
648
            platform_fence_after(failure_order);
649
        expected = desired;
650
        return success;
651
    }
652

    
653
    bool
654
    compare_exchange_weak(
655
        value_type & expected,
656
        value_type desired,
657
        memory_order success_order,
658
        memory_order failure_order) volatile BOOST_NOEXCEPT
659
    {
660
        return compare_exchange_strong(expected, desired, success_order, failure_order);
661
    }
662

    
663
    value_type
664
    fetch_and(value_type v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT
665
    {
666
        value_type tmp = load(memory_order_relaxed);
667
        do {} while(!compare_exchange_weak(tmp, tmp & v, order, memory_order_relaxed));
668
        return tmp;
669
    }
670

    
671
    value_type
672
    fetch_or(value_type v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT
673
    {
674
        value_type tmp = load(memory_order_relaxed);
675
        do {} while(!compare_exchange_weak(tmp, tmp | v, order, memory_order_relaxed));
676
        return tmp;
677
    }
678

    
679
    value_type
680
    fetch_xor(value_type v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT
681
    {
682
        value_type tmp = load(memory_order_relaxed);
683
        do {} while(!compare_exchange_weak(tmp, tmp ^ v, order, memory_order_relaxed));
684
        return tmp;
685
    }
686

    
687
    bool
688
    is_lock_free(void) const volatile BOOST_NOEXCEPT
689
    {
690
        return true;
691
    }
692

    
693
    BOOST_ATOMIC_DECLARE_INTEGRAL_OPERATORS
694

    
695
    BOOST_DELETED_FUNCTION(base_atomic(base_atomic const&))
696
    BOOST_DELETED_FUNCTION(base_atomic& operator=(base_atomic const&))
697

    
698
private:
699
    storage_type v_;
700
};
701

    
702
template<typename T, bool Sign>
703
class base_atomic<T, int, 4, Sign>
704
{
705
private:
706
    typedef base_atomic this_type;
707
    typedef T value_type;
708
    typedef T difference_type;
709

    
710
protected:
711
    typedef value_type value_arg_type;
712

    
713
public:
714
    BOOST_DEFAULTED_FUNCTION(base_atomic(void), {})
715
    BOOST_CONSTEXPR explicit base_atomic(value_type v) BOOST_NOEXCEPT : v_(v) {}
716

    
717
    void
718
    store(value_type v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT
719
    {
720
        platform_fence_before(order);
721
        const_cast<volatile value_type &>(v_) = v;
722
        platform_fence_after_store(order);
723
    }
724

    
725
    value_type
726
    load(memory_order order = memory_order_seq_cst)const volatile BOOST_NOEXCEPT
727
    {
728
        value_type v = const_cast<const volatile value_type &>(v_);
729
        platform_fence_after_load(order);
730
        return v;
731
    }
732

    
733
    value_type
734
    fetch_add(value_type v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT
735
    {
736
        value_type tmp = load(memory_order_relaxed);
737
        do {} while(!compare_exchange_weak(tmp, tmp + v, order, memory_order_relaxed));
738
        return tmp;
739
    }
740

    
741
    value_type
742
    fetch_sub(value_type v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT
743
    {
744
        value_type tmp = load(memory_order_relaxed);
745
        do {} while(!compare_exchange_weak(tmp, tmp - v, order, memory_order_relaxed));
746
        return tmp;
747
    }
748

    
749
    value_type
750
    exchange(value_type v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT
751
    {
752
        value_type tmp = load(memory_order_relaxed);
753
        do {} while(!compare_exchange_weak(tmp, v, order, memory_order_relaxed));
754
        return tmp;
755
    }
756

    
757
    bool
758
    compare_exchange_strong(
759
        value_type & expected,
760
        value_type desired,
761
        memory_order success_order,
762
        memory_order failure_order) volatile BOOST_NOEXCEPT
763
    {
764
        platform_fence_before(success_order);
765
        __asm__ (
766
            "cas [%1], %2, %0"
767
            : "+r" (desired)
768
            : "r" (&v_), "r" (expected)
769
            : "memory"
770
        );
771
        bool success = (desired == expected);
772
        if (success)
773
            platform_fence_after(success_order);
774
        else
775
            platform_fence_after(failure_order);
776
        expected = desired;
777
        return success;
778
    }
779

    
780
    bool
781
    compare_exchange_weak(
782
        value_type & expected,
783
        value_type desired,
784
        memory_order success_order,
785
        memory_order failure_order) volatile BOOST_NOEXCEPT
786
    {
787
        return compare_exchange_strong(expected, desired, success_order, failure_order);
788
    }
789

    
790
    value_type
791
    fetch_and(value_type v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT
792
    {
793
        value_type tmp = load(memory_order_relaxed);
794
        do {} while(!compare_exchange_weak(tmp, tmp & v, order, memory_order_relaxed));
795
        return tmp;
796
    }
797

    
798
    value_type
799
    fetch_or(value_type v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT
800
    {
801
        value_type tmp = load(memory_order_relaxed);
802
        do {} while(!compare_exchange_weak(tmp, tmp | v, order, memory_order_relaxed));
803
        return tmp;
804
    }
805

    
806
    value_type
807
    fetch_xor(value_type v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT
808
    {
809
        value_type tmp = load(memory_order_relaxed);
810
        do {} while(!compare_exchange_weak(tmp, tmp ^ v, order, memory_order_relaxed));
811
        return tmp;
812
    }
813

    
814
    bool
815
    is_lock_free(void) const volatile BOOST_NOEXCEPT
816
    {
817
        return true;
818
    }
819

    
820
    BOOST_ATOMIC_DECLARE_INTEGRAL_OPERATORS
821

    
822
    BOOST_DELETED_FUNCTION(base_atomic(base_atomic const&))
823
    BOOST_DELETED_FUNCTION(base_atomic& operator=(base_atomic const&))
824

    
825
private:
826
    value_type v_;
827
};
828

    
829
/* pointer types */
830

    
831
template<bool Sign>
832
class base_atomic<void *, void *, 4, Sign>
833
{
834
private:
835
    typedef base_atomic this_type;
836
    typedef std::ptrdiff_t difference_type;
837
    typedef void * value_type;
838

    
839
protected:
840
    typedef value_type value_arg_type;
841

    
842
public:
843
    BOOST_DEFAULTED_FUNCTION(base_atomic(void), {})
844
    BOOST_CONSTEXPR explicit base_atomic(value_type v) BOOST_NOEXCEPT : v_(v) {}
845

    
846
    void
847
    store(value_type v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT
848
    {
849
        platform_fence_before(order);
850
        const_cast<volatile value_type &>(v_) = v;
851
        platform_fence_after_store(order);
852
    }
853

    
854
    value_type load(memory_order order = memory_order_seq_cst)const volatile BOOST_NOEXCEPT
855
    {
856
        value_type v = const_cast<const volatile value_type &>(v_);
857
        platform_fence_after_load(order);
858
        return v;
859
    }
860

    
861
    value_type
862
    exchange(value_type v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT
863
    {
864
        value_type tmp = load(memory_order_relaxed);
865
        do {} while(!compare_exchange_weak(tmp, v, order, memory_order_relaxed));
866
        return tmp;
867
    }
868

    
869
    bool
870
    compare_exchange_strong(
871
        value_type & expected,
872
        value_type desired,
873
        memory_order success_order,
874
        memory_order failure_order) volatile BOOST_NOEXCEPT
875
    {
876
        platform_fence_before(success_order);
877
        __asm__ (
878
            "cas [%1], %2, %0"
879
            : "+r" (desired)
880
            : "r" (&v_), "r" (expected)
881
            : "memory"
882
        );
883
        bool success = (desired == expected);
884
        if (success)
885
            platform_fence_after(success_order);
886
        else
887
            platform_fence_after(failure_order);
888
        expected = desired;
889
        return success;
890
    }
891

    
892

    
893
    bool compare_exchange_weak(value_type & expected, value_type desired,
894
        memory_order success_order,
895
        memory_order failure_order) volatile BOOST_NOEXCEPT
896
    {
897
        return compare_exchange_strong(expected, desired, success_order, failure_order);
898
    }
899

    
900
    bool
901
    is_lock_free(void) const volatile BOOST_NOEXCEPT
902
    {
903
        return true;
904
    }
905

    
906
    value_type
907
    fetch_add(difference_type v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT
908
    {
909
        value_type tmp = load(memory_order_relaxed);
910
        do {} while(!compare_exchange_weak(tmp, (char*)tmp + v, order, memory_order_relaxed));
911
        return tmp;
912
    }
913

    
914
    value_type
915
    fetch_sub(difference_type v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT
916
    {
917
        value_type tmp = load(memory_order_relaxed);
918
        do {} while(!compare_exchange_weak(tmp, (char*)tmp - v, order, memory_order_relaxed));
919
        return tmp;
920
    }
921

    
922
    BOOST_ATOMIC_DECLARE_VOID_POINTER_OPERATORS
923

    
924
    BOOST_DELETED_FUNCTION(base_atomic(base_atomic const&))
925
    BOOST_DELETED_FUNCTION(base_atomic& operator=(base_atomic const&))
926

    
927
private:
928
    value_type v_;
929
};
930

    
931
template<typename T, bool Sign>
932
class base_atomic<T *, void *, 4, Sign>
933
{
934
private:
935
    typedef base_atomic this_type;
936
    typedef T * value_type;
937
    typedef std::ptrdiff_t difference_type;
938

    
939
protected:
940
    typedef value_type value_arg_type;
941

    
942
public:
943
    BOOST_DEFAULTED_FUNCTION(base_atomic(void), {})
944
    BOOST_CONSTEXPR explicit base_atomic(value_type v) BOOST_NOEXCEPT : v_(v) {}
945

    
946
    void
947
    store(value_type v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT
948
    {
949
        platform_fence_before(order);
950
        const_cast<volatile value_type &>(v_) = v;
951
        platform_fence_after_store(order);
952
    }
953

    
954
    value_type
955
    load(memory_order order = memory_order_seq_cst)const volatile BOOST_NOEXCEPT
956
    {
957
        value_type v = const_cast<const volatile value_type &>(v_);
958
        platform_fence_after_load(order);
959
        return v;
960
    }
961

    
962
    value_type
963
    exchange(value_type v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT
964
    {
965
        value_type tmp = load(memory_order_relaxed);
966
        do {} while(!compare_exchange_weak(tmp, v, order, memory_order_relaxed));
967
        return tmp;
968
    }
969

    
970
    bool
971
    compare_exchange_strong(
972
        value_type & expected,
973
        value_type desired,
974
        memory_order success_order,
975
        memory_order failure_order) volatile BOOST_NOEXCEPT
976
    {
977
        platform_fence_before(success_order);
978
        __asm__ (
979
            "cas [%1], %2, %0"
980
            : "+r" (desired)
981
            : "r" (&v_), "r" (expected)
982
            : "memory"
983
        );
984
        bool success = (desired == expected);
985
        if (success)
986
            platform_fence_after(success_order);
987
        else
988
            platform_fence_after(failure_order);
989
        expected = desired;
990
        return success;
991
    }
992

    
993
    bool
994
    compare_exchange_weak(
995
        value_type & expected,
996
        value_type desired,
997
        memory_order success_order,
998
        memory_order failure_order) volatile BOOST_NOEXCEPT
999
    {
1000
        return compare_exchange_strong(expected, desired, success_order, failure_order);
1001
    }
1002

    
1003
    value_type
1004
    fetch_add(difference_type v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT
1005
    {
1006
        value_type tmp = load(memory_order_relaxed);
1007
        do {} while(!compare_exchange_weak(tmp, tmp + v, order, memory_order_relaxed));
1008
        return tmp;
1009
    }
1010

    
1011
    value_type
1012
    fetch_sub(difference_type v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT
1013
    {
1014
        value_type tmp = load(memory_order_relaxed);
1015
        do {} while(!compare_exchange_weak(tmp, tmp - v, order, memory_order_relaxed));
1016
        return tmp;
1017
    }
1018

    
1019
    bool
1020
    is_lock_free(void) const volatile BOOST_NOEXCEPT
1021
    {
1022
        return true;
1023
    }
1024

    
1025
    BOOST_ATOMIC_DECLARE_POINTER_OPERATORS
1026

    
1027
    BOOST_DELETED_FUNCTION(base_atomic(base_atomic const&))
1028
    BOOST_DELETED_FUNCTION(base_atomic& operator=(base_atomic const&))
1029

    
1030
private:
1031
    value_type v_;
1032
};
1033

    
1034
/* generic types */
1035

    
1036
template<typename T, bool Sign>
1037
class base_atomic<T, void, 1, Sign>
1038
{
1039
private:
1040
    typedef base_atomic this_type;
1041
    typedef T value_type;
1042
    typedef uint32_t storage_type;
1043

    
1044
protected:
1045
    typedef value_type const& value_arg_type;
1046

    
1047
public:
1048
    BOOST_DEFAULTED_FUNCTION(base_atomic(void), {})
1049
    BOOST_CONSTEXPR explicit base_atomic(value_type const& v) BOOST_NOEXCEPT : v_(0)
1050
    {
1051
        memcpy(&v_, &v, sizeof(value_type));
1052
    }
1053

    
1054
    void
1055
    store(value_type const& v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT
1056
    {
1057
        storage_type tmp = 0;
1058
        memcpy(&tmp, &v, sizeof(value_type));
1059
        platform_fence_before(order);
1060
        const_cast<volatile storage_type &>(v_) = tmp;
1061
        platform_fence_after_store(order);
1062
    }
1063

    
1064
    value_type
1065
    load(memory_order order = memory_order_seq_cst)const volatile BOOST_NOEXCEPT
1066
    {
1067
        storage_type tmp = const_cast<volatile storage_type &>(v_);
1068
        platform_fence_after_load(order);
1069
        value_type v;
1070
        memcpy(&v, &tmp, sizeof(value_type));
1071
        return v;
1072
    }
1073

    
1074
    value_type
1075
    exchange(value_type const& v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT
1076
    {
1077
        value_type tmp = load(memory_order_relaxed);
1078
        do {} while(!compare_exchange_weak(tmp, v, order, memory_order_relaxed));
1079
        return tmp;
1080
    }
1081

    
1082
    bool
1083
    compare_exchange_strong(
1084
        value_type & expected,
1085
        value_type const& desired,
1086
        memory_order success_order,
1087
        memory_order failure_order) volatile BOOST_NOEXCEPT
1088
    {
1089
        storage_type expected_s = 0, desired_s = 0;
1090
        memcpy(&expected_s, &expected, sizeof(value_type));
1091
        memcpy(&desired_s, &desired, sizeof(value_type));
1092
        platform_fence_before(success_order);
1093
        __asm__ (
1094
            "cas [%1], %2, %0"
1095
            : "+r" (desired_s)
1096
            : "r" (&v_), "r" (expected_s)
1097
            : "memory"
1098
        );
1099
        bool success = (desired_s == expected_s);
1100
        if (success)
1101
            platform_fence_after(success_order);
1102
        else
1103
            platform_fence_after(failure_order);
1104
        memcpy(&expected, &desired_s, sizeof(value_type));
1105
        return success;
1106
    }
1107

    
1108
    bool
1109
    compare_exchange_weak(
1110
        value_type & expected,
1111
        value_type const& desired,
1112
        memory_order success_order,
1113
        memory_order failure_order) volatile BOOST_NOEXCEPT
1114
    {
1115
        return compare_exchange_strong(expected, desired, success_order, failure_order);
1116
    }
1117

    
1118
    bool
1119
    is_lock_free(void) const volatile BOOST_NOEXCEPT
1120
    {
1121
        return true;
1122
    }
1123

    
1124
    BOOST_ATOMIC_DECLARE_BASE_OPERATORS
1125

    
1126
    BOOST_DELETED_FUNCTION(base_atomic(base_atomic const&))
1127
    BOOST_DELETED_FUNCTION(base_atomic& operator=(base_atomic const&))
1128

    
1129
private:
1130
    storage_type v_;
1131
};
1132

    
1133
template<typename T, bool Sign>
1134
class base_atomic<T, void, 2, Sign>
1135
{
1136
private:
1137
    typedef base_atomic this_type;
1138
    typedef T value_type;
1139
    typedef uint32_t storage_type;
1140

    
1141
protected:
1142
    typedef value_type const& value_arg_type;
1143

    
1144
public:
1145
    BOOST_DEFAULTED_FUNCTION(base_atomic(void), {})
1146
    BOOST_CONSTEXPR explicit base_atomic(value_type const& v) BOOST_NOEXCEPT : v_(0)
1147
    {
1148
        memcpy(&v_, &v, sizeof(value_type));
1149
    }
1150

    
1151
    void
1152
    store(value_type const& v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT
1153
    {
1154
        storage_type tmp = 0;
1155
        memcpy(&tmp, &v, sizeof(value_type));
1156
        platform_fence_before(order);
1157
        const_cast<volatile storage_type &>(v_) = tmp;
1158
        platform_fence_after_store(order);
1159
    }
1160

    
1161
    value_type
1162
    load(memory_order order = memory_order_seq_cst)const volatile BOOST_NOEXCEPT
1163
    {
1164
        storage_type tmp = const_cast<volatile storage_type &>(v_);
1165
        platform_fence_after_load(order);
1166
        value_type v;
1167
        memcpy(&v, &tmp, sizeof(value_type));
1168
        return v;
1169
    }
1170

    
1171
    value_type
1172
    exchange(value_type const& v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT
1173
    {
1174
        value_type tmp = load(memory_order_relaxed);
1175
        do {} while(!compare_exchange_weak(tmp, v, order, memory_order_relaxed));
1176
        return tmp;
1177
    }
1178

    
1179
    bool
1180
    compare_exchange_strong(
1181
        value_type & expected,
1182
        value_type const& desired,
1183
        memory_order success_order,
1184
        memory_order failure_order) volatile BOOST_NOEXCEPT
1185
    {
1186
        storage_type expected_s = 0, desired_s = 0;
1187
        memcpy(&expected_s, &expected, sizeof(value_type));
1188
        memcpy(&desired_s, &desired, sizeof(value_type));
1189
        platform_fence_before(success_order);
1190
        __asm__ (
1191
            "cas [%1], %2, %0"
1192
            : "+r" (desired_s)
1193
            : "r" (&v_), "r" (expected_s)
1194
            : "memory"
1195
        );
1196
        bool success = (desired_s == expected_s);
1197
        if (success)
1198
            platform_fence_after(success_order);
1199
        else
1200
            platform_fence_after(failure_order);
1201
        memcpy(&expected, &desired_s, sizeof(value_type));
1202
        return success;
1203
    }
1204

    
1205
    bool
1206
    compare_exchange_weak(
1207
        value_type & expected,
1208
        value_type const& desired,
1209
        memory_order success_order,
1210
        memory_order failure_order) volatile BOOST_NOEXCEPT
1211
    {
1212
        return compare_exchange_strong(expected, desired, success_order, failure_order);
1213
    }
1214

    
1215
    bool
1216
    is_lock_free(void) const volatile BOOST_NOEXCEPT
1217
    {
1218
        return true;
1219
    }
1220

    
1221
    BOOST_ATOMIC_DECLARE_BASE_OPERATORS
1222

    
1223
    BOOST_DELETED_FUNCTION(base_atomic(base_atomic const&))
1224
    BOOST_DELETED_FUNCTION(base_atomic& operator=(base_atomic const&))
1225

    
1226
private:
1227
    storage_type v_;
1228
};
1229

    
1230
template<typename T, bool Sign>
1231
class base_atomic<T, void, 4, Sign>
1232
{
1233
private:
1234
    typedef base_atomic this_type;
1235
    typedef T value_type;
1236
    typedef uint32_t storage_type;
1237

    
1238
protected:
1239
    typedef value_type const& value_arg_type;
1240

    
1241
public:
1242
    BOOST_DEFAULTED_FUNCTION(base_atomic(void), {})
1243
    BOOST_CONSTEXPR explicit base_atomic(value_type const& v) BOOST_NOEXCEPT : v_(0)
1244
    {
1245
        memcpy(&v_, &v, sizeof(value_type));
1246
    }
1247

    
1248
    void
1249
    store(value_type const& v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT
1250
    {
1251
        storage_type tmp = 0;
1252
        memcpy(&tmp, &v, sizeof(value_type));
1253
        platform_fence_before(order);
1254
        const_cast<volatile storage_type &>(v_) = tmp;
1255
        platform_fence_after_store(order);
1256
    }
1257

    
1258
    value_type
1259
    load(memory_order order = memory_order_seq_cst)const volatile BOOST_NOEXCEPT
1260
    {
1261
        storage_type tmp = const_cast<volatile storage_type &>(v_);
1262
        platform_fence_after_load(order);
1263
        value_type v;
1264
        memcpy(&v, &tmp, sizeof(value_type));
1265
        return v;
1266
    }
1267

    
1268
    value_type
1269
    exchange(value_type const& v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT
1270
    {
1271
        value_type tmp = load(memory_order_relaxed);
1272
        do {} while(!compare_exchange_weak(tmp, v, order, memory_order_relaxed));
1273
        return tmp;
1274
    }
1275

    
1276
    bool
1277
    compare_exchange_strong(
1278
        value_type & expected,
1279
        value_type const& desired,
1280
        memory_order success_order,
1281
        memory_order failure_order) volatile BOOST_NOEXCEPT
1282
    {
1283
        storage_type expected_s = 0, desired_s = 0;
1284
        memcpy(&expected_s, &expected, sizeof(value_type));
1285
        memcpy(&desired_s, &desired, sizeof(value_type));
1286
        platform_fence_before(success_order);
1287
        __asm__ (
1288
            "cas [%1], %2, %0"
1289
            : "+r" (desired_s)
1290
            : "r" (&v_), "r" (expected_s)
1291
            : "memory"
1292
        );
1293
        bool success = (desired_s == expected_s);
1294
        if (success)
1295
            platform_fence_after(success_order);
1296
        else
1297
            platform_fence_after(failure_order);
1298
        memcpy(&expected, &desired_s, sizeof(value_type));
1299
        return success;
1300
    }
1301

    
1302
    bool
1303
    compare_exchange_weak(
1304
        value_type & expected,
1305
        value_type const& desired,
1306
        memory_order success_order,
1307
        memory_order failure_order) volatile BOOST_NOEXCEPT
1308
    {
1309
        return compare_exchange_strong(expected, desired, success_order, failure_order);
1310
    }
1311

    
1312
    bool
1313
    is_lock_free(void) const volatile BOOST_NOEXCEPT
1314
    {
1315
        return true;
1316
    }
1317

    
1318
    BOOST_ATOMIC_DECLARE_BASE_OPERATORS
1319

    
1320
    BOOST_DELETED_FUNCTION(base_atomic(base_atomic const&))
1321
    BOOST_DELETED_FUNCTION(base_atomic& operator=(base_atomic const&))
1322

    
1323
private:
1324
    storage_type v_;
1325
};
1326

    
1327
#endif /* !defined(BOOST_ATOMIC_FORCE_FALLBACK) */
1328

    
1329
}
1330
}
1331
}
1332

    
1333
#endif