1 /***************************************************************************
2 * Copyright (c) 2010, Ronald Landheer-Cieslak & Vlinder Software *
4 * Ownership of Copyright *
5 * ====================== *
6 * The copyright in this material (including without limitation the text, *
7 * computer code, artwork, photographs, images, music, audio material, *
8 * video material and audio-visual material) is owned by Ronald *
9 * Landheer-Cieslak and/or Vlinder Software. *
13 * This program is free software: you can redistribute it and/or modify *
14 * it under the terms of the GNU General Public License as published by *
15 * the Free Software Foundation, version 3 of the License. *
17 * This program is distributed in the hope that it will be useful, *
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
20 * GNU General Public License for more details. *
22 * You should have received a copy of the GNU General Public License *
23 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
24 ***************************************************************************/
25 #ifndef VLINDER_ATOMICS_RELACYATOMICS_H
26 #define VLINDER_ATOMICS_RELACYATOMICS_H
30 #pragma warning(disable: 4996)
32 #include <relacy/atomic.hpp>
33 #include <relacy/relacy_std.hpp>
34 #include <relacy/atomic_fence.hpp>
46 memory_order_relaxed__
= rl::mo_relaxed
, // no operation orders memory
47 memory_order_consume__
= rl::mo_consume
, // a load operation performs a consume operation on the affected memory location
48 memory_order_acquire__
= rl::mo_acquire
, // a load operation performs an acquire operation on the affected memory location
49 memory_order_release__
= rl::mo_release
, // a store operation performs a release operation on the affected memory location
50 memory_order_acq_rel__
= rl::mo_acq_rel
, // a store operation performs a release operation on the affected memory location;
51 // a load operation performs an acquire operation on the affected memory location
52 memory_order_seq_cst__
= rl::mo_seq_cst
, // a store operation performs a release operation on the affected memory location;
53 // a load operation performs an acquire operation on the affected memory location
56 template < typename T
>
58 : public rl::atomic
< T
>
67 template < typename D
>
68 T
load(const D
& debug_info
, MemoryOrder memory_order
= memory_order_seq_cst__
) const
70 return rl::atomic
< T
>::load((rl::memory_order
)memory_order
, debug_info
);
73 template < typename D
>
74 void store(const D
& debug_info
, T value
, MemoryOrder memory_order
= memory_order_seq_cst__
)
76 return rl::atomic
< T
>::store(value
, (rl::memory_order
)memory_order
, debug_info
);
79 template < typename D
>
80 T
exchange(const D
& debug_info
, T value
, MemoryOrder memory_order
= memory_order_seq_cst__
)
82 return rl::atomic
< T
>::exchange(value
, (rl::memory_order
)memory_order
, debug_info
);
85 template < typename D
>
86 bool cas(const D
& debug_info
, T
* expected
, T desired
, MemoryOrder order
= memory_order_seq_cst__
)
88 return rl::atomic
< T
>::compare_exchange_strong(*expected
, desired
, (rl::memory_order
)order
, debug_info
);
91 template < typename D
>
92 T
fetchAndAdd(const D
& debug_info
, T value
, MemoryOrder order
= memory_order_seq_cst__
)
94 return rl::atomic
< T
>::fetch_add(value
, (rl::memory_order
)order
, debug_info
);
97 template < typename D
>
98 void add(const D
& debug_info
, T value
, MemoryOrder order
= memory_order_seq_cst__
)
100 rl::atomic
< T
>::fetch_add(value
, (rl::memory_order
)order
, debug_info
);
103 template < typename D
>
104 void sub(const D
& debug_info
, T value
, MemoryOrder order
= memory_order_seq_cst__
)
106 rl::atomic
< T
>::fetch_sub(value
, (rl::memory_order
)order
, debug_info
);
110 template < typename D
>
111 static void membarRelease(const D
& debug_info
)
113 rl::atomic_thread_fence(rl::mo_release
, debug_info
);
116 template < typename D
>
117 static void membarAcquire(const D
& debug_info
)
119 rl::atomic_thread_fence(rl::mo_acquire
, debug_info
);
122 template < typename D
>
123 static void assertion(const D
& debug_info
, bool assertion
, const char * assertion_text
)
125 RL_ASSERT_IMPL(assertion
, rl::test_result_user_assert_failed
, assertion_text
, debug_info
);