author | coleenp |
Thu, 10 Jan 2019 15:13:51 -0500 | |
changeset 53244 | 9807daeb47c4 |
parent 51330 | edd33b9946ca |
child 59247 | 56bf71d64d51 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
51330
diff
changeset
|
2 |
* Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved. |
1 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
3795
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
3795
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
3795
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
51330
diff
changeset
|
25 |
#ifndef SHARE_RUNTIME_ATOMIC_HPP |
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
51330
diff
changeset
|
26 |
#define SHARE_RUNTIME_ATOMIC_HPP |
7397 | 27 |
|
28 |
#include "memory/allocation.hpp" |
|
46993
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
29 |
#include "metaprogramming/conditional.hpp" |
46958
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
30 |
#include "metaprogramming/enableIf.hpp" |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
31 |
#include "metaprogramming/isIntegral.hpp" |
46993
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
32 |
#include "metaprogramming/isPointer.hpp" |
46958
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
33 |
#include "metaprogramming/isSame.hpp" |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
34 |
#include "metaprogramming/primitiveConversions.hpp" |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
35 |
#include "metaprogramming/removeCV.hpp" |
46993
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
36 |
#include "metaprogramming/removePointer.hpp" |
46625 | 37 |
#include "utilities/align.hpp" |
40655
9f644073d3a0
8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents:
39404
diff
changeset
|
38 |
#include "utilities/macros.hpp" |
7397 | 39 |
|
50029
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
49364
diff
changeset
|
40 |
enum atomic_memory_order { |
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
49364
diff
changeset
|
41 |
// The modes that align with C++11 are intended to |
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
49364
diff
changeset
|
42 |
// follow the same semantics. |
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
49364
diff
changeset
|
43 |
memory_order_relaxed = 0, |
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
49364
diff
changeset
|
44 |
memory_order_acquire = 2, |
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
49364
diff
changeset
|
45 |
memory_order_release = 3, |
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
49364
diff
changeset
|
46 |
memory_order_acq_rel = 4, |
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
49364
diff
changeset
|
47 |
// Strong two-way memory barrier. |
39404 | 48 |
memory_order_conservative = 8 |
49 |
}; |
|
50 |
||
1 | 51 |
class Atomic : AllStatic { |
47609
a1f68e415b48
8188813: Generalize OrderAccess to use templates
eosterlund
parents:
47593
diff
changeset
|
52 |
public: |
48468 | 53 |
// Atomic operations on int64 types are not available on all 32-bit |
54 |
// platforms. If atomic ops on int64 are defined here they must only |
|
15803
9328492899cc
8008314: Unimplemented() Atomic::load breaks the applications
jwilhelm
parents:
14626
diff
changeset
|
55 |
// be used from code that verifies they are available at runtime and |
9328492899cc
8008314: Unimplemented() Atomic::load breaks the applications
jwilhelm
parents:
14626
diff
changeset
|
56 |
// can provide an alternative action if not - see supports_cx8() for |
9328492899cc
8008314: Unimplemented() Atomic::load breaks the applications
jwilhelm
parents:
14626
diff
changeset
|
57 |
// a means to test availability. |
9328492899cc
8008314: Unimplemented() Atomic::load breaks the applications
jwilhelm
parents:
14626
diff
changeset
|
58 |
|
25625
00dca966711e
8049104: resolve atomic.hpp wording issues from JDK-8047104 code review
dcubed
parents:
25069
diff
changeset
|
59 |
// The memory operations that are mentioned with each of the atomic |
00dca966711e
8049104: resolve atomic.hpp wording issues from JDK-8047104 code review
dcubed
parents:
25069
diff
changeset
|
60 |
// function families come from src/share/vm/runtime/orderAccess.hpp, |
00dca966711e
8049104: resolve atomic.hpp wording issues from JDK-8047104 code review
dcubed
parents:
25069
diff
changeset
|
61 |
// e.g., <fence> is described in that file and is implemented by the |
00dca966711e
8049104: resolve atomic.hpp wording issues from JDK-8047104 code review
dcubed
parents:
25069
diff
changeset
|
62 |
// OrderAccess::fence() function. See that file for the gory details |
00dca966711e
8049104: resolve atomic.hpp wording issues from JDK-8047104 code review
dcubed
parents:
25069
diff
changeset
|
63 |
// on the Memory Access Ordering Model. |
00dca966711e
8049104: resolve atomic.hpp wording issues from JDK-8047104 code review
dcubed
parents:
25069
diff
changeset
|
64 |
|
00dca966711e
8049104: resolve atomic.hpp wording issues from JDK-8047104 code review
dcubed
parents:
25069
diff
changeset
|
65 |
// All of the atomic operations that imply a read-modify-write action |
00dca966711e
8049104: resolve atomic.hpp wording issues from JDK-8047104 code review
dcubed
parents:
25069
diff
changeset
|
66 |
// guarantee a two-way memory barrier across that operation. Historically |
00dca966711e
8049104: resolve atomic.hpp wording issues from JDK-8047104 code review
dcubed
parents:
25069
diff
changeset
|
67 |
// these semantics reflect the strength of atomic operations that are |
00dca966711e
8049104: resolve atomic.hpp wording issues from JDK-8047104 code review
dcubed
parents:
25069
diff
changeset
|
68 |
// provided on SPARC/X86. We assume that strength is necessary unless |
00dca966711e
8049104: resolve atomic.hpp wording issues from JDK-8047104 code review
dcubed
parents:
25069
diff
changeset
|
69 |
// we can prove that a weaker form is sufficiently safe. |
00dca966711e
8049104: resolve atomic.hpp wording issues from JDK-8047104 code review
dcubed
parents:
25069
diff
changeset
|
70 |
|
1 | 71 |
// Atomically store to a location |
47593
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
72 |
// The type T must be either a pointer type convertible to or equal |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
73 |
// to D, an integral/enum type equal to D, or a type equal to D that |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
74 |
// is primitive convertible using PrimitiveConversions. |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
75 |
template<typename T, typename D> |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
76 |
inline static void store(T store_value, volatile D* dest); |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
77 |
|
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
78 |
// Atomically load from a location |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
79 |
// The type T must be either a pointer type, an integral/enum type, |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
80 |
// or a type that is primitive convertible using PrimitiveConversions. |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
81 |
template<typename T> |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
82 |
inline static T load(const volatile T* dest); |
3594
0ce9158bc84c
6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
670
diff
changeset
|
83 |
|
25625
00dca966711e
8049104: resolve atomic.hpp wording issues from JDK-8047104 code review
dcubed
parents:
25069
diff
changeset
|
84 |
// Atomically add to a location. Returns updated value. add*() provide: |
00dca966711e
8049104: resolve atomic.hpp wording issues from JDK-8047104 code review
dcubed
parents:
25069
diff
changeset
|
85 |
// <fence> add-value-to-dest <membar StoreLoad|StoreStore> |
46993
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
86 |
|
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
87 |
template<typename I, typename D> |
50029
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
49364
diff
changeset
|
88 |
inline static D add(I add_value, D volatile* dest, |
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
49364
diff
changeset
|
89 |
atomic_memory_order order = memory_order_conservative); |
46993
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
90 |
|
47634
6a0c42c40cd1
8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents:
47609
diff
changeset
|
91 |
template<typename I, typename D> |
50029
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
49364
diff
changeset
|
92 |
inline static D sub(I sub_value, D volatile* dest, |
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
49364
diff
changeset
|
93 |
atomic_memory_order order = memory_order_conservative); |
9990
c8683968c01b
6941923: RFE: Handling large log files produced by long running Java Applications
minqi
parents:
7397
diff
changeset
|
94 |
|
47552
8a3599d60996
8186838: Generalize Atomic::inc/dec with templates
eosterlund
parents:
47216
diff
changeset
|
95 |
// Atomically increment location. inc() provide: |
25625
00dca966711e
8049104: resolve atomic.hpp wording issues from JDK-8047104 code review
dcubed
parents:
25069
diff
changeset
|
96 |
// <fence> increment-dest <membar StoreLoad|StoreStore> |
47552
8a3599d60996
8186838: Generalize Atomic::inc/dec with templates
eosterlund
parents:
47216
diff
changeset
|
97 |
// The type D may be either a pointer type, or an integral |
8a3599d60996
8186838: Generalize Atomic::inc/dec with templates
eosterlund
parents:
47216
diff
changeset
|
98 |
// type. If it is a pointer type, then the increment is |
8a3599d60996
8186838: Generalize Atomic::inc/dec with templates
eosterlund
parents:
47216
diff
changeset
|
99 |
// scaled to the size of the type pointed to by the pointer. |
8a3599d60996
8186838: Generalize Atomic::inc/dec with templates
eosterlund
parents:
47216
diff
changeset
|
100 |
template<typename D> |
50029
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
49364
diff
changeset
|
101 |
inline static void inc(D volatile* dest, |
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
49364
diff
changeset
|
102 |
atomic_memory_order order = memory_order_conservative); |
1 | 103 |
|
47552
8a3599d60996
8186838: Generalize Atomic::inc/dec with templates
eosterlund
parents:
47216
diff
changeset
|
104 |
// Atomically decrement a location. dec() provide: |
25625
00dca966711e
8049104: resolve atomic.hpp wording issues from JDK-8047104 code review
dcubed
parents:
25069
diff
changeset
|
105 |
// <fence> decrement-dest <membar StoreLoad|StoreStore> |
47552
8a3599d60996
8186838: Generalize Atomic::inc/dec with templates
eosterlund
parents:
47216
diff
changeset
|
106 |
// The type D may be either a pointer type, or an integral |
8a3599d60996
8186838: Generalize Atomic::inc/dec with templates
eosterlund
parents:
47216
diff
changeset
|
107 |
// type. If it is a pointer type, then the decrement is |
8a3599d60996
8186838: Generalize Atomic::inc/dec with templates
eosterlund
parents:
47216
diff
changeset
|
108 |
// scaled to the size of the type pointed to by the pointer. |
8a3599d60996
8186838: Generalize Atomic::inc/dec with templates
eosterlund
parents:
47216
diff
changeset
|
109 |
template<typename D> |
50029
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
49364
diff
changeset
|
110 |
inline static void dec(D volatile* dest, |
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
49364
diff
changeset
|
111 |
atomic_memory_order order = memory_order_conservative); |
1 | 112 |
|
25625
00dca966711e
8049104: resolve atomic.hpp wording issues from JDK-8047104 code review
dcubed
parents:
25069
diff
changeset
|
113 |
// Performs atomic exchange of *dest with exchange_value. Returns old |
00dca966711e
8049104: resolve atomic.hpp wording issues from JDK-8047104 code review
dcubed
parents:
25069
diff
changeset
|
114 |
// prior value of *dest. xchg*() provide: |
00dca966711e
8049104: resolve atomic.hpp wording issues from JDK-8047104 code review
dcubed
parents:
25069
diff
changeset
|
115 |
// <fence> exchange-value-with-dest <membar StoreLoad|StoreStore> |
47578
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
116 |
// The type T must be either a pointer type convertible to or equal |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
117 |
// to D, an integral/enum type equal to D, or a type equal to D that |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
118 |
// is primitive convertible using PrimitiveConversions. |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
119 |
template<typename T, typename D> |
50029
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
49364
diff
changeset
|
120 |
inline static D xchg(T exchange_value, volatile D* dest, |
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
49364
diff
changeset
|
121 |
atomic_memory_order order = memory_order_conservative); |
47578
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
122 |
|
25625
00dca966711e
8049104: resolve atomic.hpp wording issues from JDK-8047104 code review
dcubed
parents:
25069
diff
changeset
|
123 |
// Performs atomic compare of *dest and compare_value, and exchanges |
00dca966711e
8049104: resolve atomic.hpp wording issues from JDK-8047104 code review
dcubed
parents:
25069
diff
changeset
|
124 |
// *dest with exchange_value if the comparison succeeded. Returns prior |
00dca966711e
8049104: resolve atomic.hpp wording issues from JDK-8047104 code review
dcubed
parents:
25069
diff
changeset
|
125 |
// value of *dest. cmpxchg*() provide: |
00dca966711e
8049104: resolve atomic.hpp wording issues from JDK-8047104 code review
dcubed
parents:
25069
diff
changeset
|
126 |
// <fence> compare-and-exchange <membar StoreLoad|StoreStore> |
46958
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
127 |
|
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
128 |
template<typename T, typename D, typename U> |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
129 |
inline static D cmpxchg(T exchange_value, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
130 |
D volatile* dest, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
131 |
U compare_value, |
50029
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
49364
diff
changeset
|
132 |
atomic_memory_order order = memory_order_conservative); |
46958
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
133 |
|
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
134 |
// Performs atomic compare of *dest and NULL, and replaces *dest |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
135 |
// with exchange_value if the comparison succeeded. Returns true if |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
136 |
// the comparison succeeded and the exchange occurred. This is |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
137 |
// often used as part of lazy initialization, as a lock-free |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
138 |
// alternative to the Double-Checked Locking Pattern. |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
139 |
template<typename T, typename D> |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
140 |
inline static bool replace_if_null(T* value, D* volatile* dest, |
50029
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
49364
diff
changeset
|
141 |
atomic_memory_order order = memory_order_conservative); |
46958
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
142 |
|
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
143 |
private: |
49022
83fd70753121
8196889: VS2017 Unable to Instantiate OrderAccess::release_store with an Incomplete Class Within an Inlined Method
lfoltan
parents:
48468
diff
changeset
|
144 |
WINDOWS_ONLY(public:) // VS2017 warns (C2027) use of undefined type if IsPointerConvertible is declared private |
46958
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
145 |
// Test whether From is implicitly convertible to To. |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
146 |
// From and To must be pointer types. |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
147 |
// Note: Provides the limited subset of C++11 std::is_convertible |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
148 |
// that is needed here. |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
149 |
template<typename From, typename To> struct IsPointerConvertible; |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
150 |
|
47609
a1f68e415b48
8188813: Generalize OrderAccess to use templates
eosterlund
parents:
47593
diff
changeset
|
151 |
protected: |
47593
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
152 |
// Dispatch handler for store. Provides type-based validity |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
153 |
// checking and limited conversions around calls to the platform- |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
154 |
// specific implementation layer provided by PlatformOp. |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
155 |
template<typename T, typename D, typename PlatformOp, typename Enable = void> |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
156 |
struct StoreImpl; |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
157 |
|
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
158 |
// Platform-specific implementation of store. Support for sizes |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
159 |
// of 1, 2, 4, and (if different) pointer size bytes are required. |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
160 |
// The class is a function object that must be default constructable, |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
161 |
// with these requirements: |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
162 |
// |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
163 |
// either: |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
164 |
// - dest is of type D*, an integral, enum or pointer type. |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
165 |
// - new_value are of type T, an integral, enum or pointer type D or |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
166 |
// pointer type convertible to D. |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
167 |
// or: |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
168 |
// - T and D are the same and are primitive convertible using PrimitiveConversions |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
169 |
// and either way: |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
170 |
// - platform_store is an object of type PlatformStore<sizeof(T)>. |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
171 |
// |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
172 |
// Then |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
173 |
// platform_store(new_value, dest) |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
174 |
// must be a valid expression. |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
175 |
// |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
176 |
// The default implementation is a volatile store. If a platform |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
177 |
// requires more for e.g. 64 bit stores, a specialization is required |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
178 |
template<size_t byte_size> struct PlatformStore; |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
179 |
|
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
180 |
// Dispatch handler for load. Provides type-based validity |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
181 |
// checking and limited conversions around calls to the platform- |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
182 |
// specific implementation layer provided by PlatformOp. |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
183 |
template<typename T, typename PlatformOp, typename Enable = void> |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
184 |
struct LoadImpl; |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
185 |
|
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
186 |
// Platform-specific implementation of load. Support for sizes of |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
187 |
// 1, 2, 4 bytes and (if different) pointer size bytes are required. |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
188 |
// The class is a function object that must be default |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
189 |
// constructable, with these requirements: |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
190 |
// |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
191 |
// - dest is of type T*, an integral, enum or pointer type, or |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
192 |
// T is convertible to a primitive type using PrimitiveConversions |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
193 |
// - platform_load is an object of type PlatformLoad<sizeof(T)>. |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
194 |
// |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
195 |
// Then |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
196 |
// platform_load(src) |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
197 |
// must be a valid expression, returning a result convertible to T. |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
198 |
// |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
199 |
// The default implementation is a volatile load. If a platform |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
200 |
// requires more for e.g. 64 bit loads, a specialization is required |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
201 |
template<size_t byte_size> struct PlatformLoad; |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
202 |
|
47609
a1f68e415b48
8188813: Generalize OrderAccess to use templates
eosterlund
parents:
47593
diff
changeset
|
203 |
private: |
46993
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
204 |
// Dispatch handler for add. Provides type-based validity checking |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
205 |
// and limited conversions around calls to the platform-specific |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
206 |
// implementation layer provided by PlatformAdd. |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
207 |
template<typename I, typename D, typename Enable = void> |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
208 |
struct AddImpl; |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
209 |
|
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
210 |
// Platform-specific implementation of add. Support for sizes of 4 |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
211 |
// bytes and (if different) pointer size bytes are required. The |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
212 |
// class is a function object that must be default constructable, |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
213 |
// with these requirements: |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
214 |
// |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
215 |
// - dest is of type D*, an integral or pointer type. |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
216 |
// - add_value is of type I, an integral type. |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
217 |
// - sizeof(I) == sizeof(D). |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
218 |
// - if D is an integral type, I == D. |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
219 |
// - platform_add is an object of type PlatformAdd<sizeof(D)>. |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
220 |
// |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
221 |
// Then |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
222 |
// platform_add(add_value, dest) |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
223 |
// must be a valid expression, returning a result convertible to D. |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
224 |
// |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
225 |
// No definition is provided; all platforms must explicitly define |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
226 |
// this class and any needed specializations. |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
227 |
template<size_t byte_size> struct PlatformAdd; |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
228 |
|
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
229 |
// Helper base classes for defining PlatformAdd. To use, define |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
230 |
// PlatformAdd or a specialization that derives from one of these, |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
231 |
// and include in the PlatformAdd definition the support function |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
232 |
// (described below) required by the base class. |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
233 |
// |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
234 |
// These classes implement the required function object protocol for |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
235 |
// PlatformAdd, using a support function template provided by the |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
236 |
// derived class. Let add_value (of type I) and dest (of type D) be |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
237 |
// the arguments the object is called with. If D is a pointer type |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
238 |
// P*, then let addend (of type I) be add_value * sizeof(P); |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
239 |
// otherwise, addend is add_value. |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
240 |
// |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
241 |
// FetchAndAdd requires the derived class to provide |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
242 |
// fetch_and_add(addend, dest) |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
243 |
// atomically adding addend to the value of dest, and returning the |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
244 |
// old value. |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
245 |
// |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
246 |
// AddAndFetch requires the derived class to provide |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
247 |
// add_and_fetch(addend, dest) |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
248 |
// atomically adding addend to the value of dest, and returning the |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
249 |
// new value. |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
250 |
// |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
251 |
// When D is a pointer type P*, both fetch_and_add and add_and_fetch |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
252 |
// treat it as if it were a uintptr_t; they do not perform any |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
253 |
// scaling of the addend, as that has already been done by the |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
254 |
// caller. |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
255 |
public: // Temporary, can't be private: C++03 11.4/2. Fixed by C++11. |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
256 |
template<typename Derived> struct FetchAndAdd; |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
257 |
template<typename Derived> struct AddAndFetch; |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
258 |
private: |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
259 |
|
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
260 |
// Support for platforms that implement some variants of add using a |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
261 |
// (typically out of line) non-template helper function. The |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
262 |
// generic arguments passed to PlatformAdd need to be translated to |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
263 |
// the appropriate type for the helper function, the helper function |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
264 |
// invoked on the translated arguments, and the result translated |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
265 |
// back. Type is the parameter / return type of the helper |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
266 |
// function. No scaling of add_value is performed when D is a pointer |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
267 |
// type, so this function can be used to implement the support function |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
268 |
// required by AddAndFetch. |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
269 |
template<typename Type, typename Fn, typename I, typename D> |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
270 |
static D add_using_helper(Fn fn, I add_value, D volatile* dest); |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
271 |
|
46958
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
272 |
// Dispatch handler for cmpxchg. Provides type-based validity |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
273 |
// checking and limited conversions around calls to the |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
274 |
// platform-specific implementation layer provided by |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
275 |
// PlatformCmpxchg. |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
276 |
template<typename T, typename D, typename U, typename Enable = void> |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
277 |
struct CmpxchgImpl; |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
278 |
|
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
279 |
// Platform-specific implementation of cmpxchg. Support for sizes |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
280 |
// of 1, 4, and 8 are required. The class is a function object that |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
281 |
// must be default constructable, with these requirements: |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
282 |
// |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
283 |
// - dest is of type T*. |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
284 |
// - exchange_value and compare_value are of type T. |
50029
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
49364
diff
changeset
|
285 |
// - order is of type atomic_memory_order. |
46958
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
286 |
// - platform_cmpxchg is an object of type PlatformCmpxchg<sizeof(T)>. |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
287 |
// |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
288 |
// Then |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
289 |
// platform_cmpxchg(exchange_value, dest, compare_value, order) |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
290 |
// must be a valid expression, returning a result convertible to T. |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
291 |
// |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
292 |
// A default definition is provided, which declares a function template |
50029
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
49364
diff
changeset
|
293 |
// T operator()(T, T volatile*, T, atomic_memory_order) const |
46958
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
294 |
// |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
295 |
// For each required size, a platform must either provide an |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
296 |
// appropriate definition of that function, or must entirely |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
297 |
// specialize the class template for that size. |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
298 |
template<size_t byte_size> struct PlatformCmpxchg; |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
299 |
|
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
300 |
// Support for platforms that implement some variants of cmpxchg |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
301 |
// using a (typically out of line) non-template helper function. |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
302 |
// The generic arguments passed to PlatformCmpxchg need to be |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
303 |
// translated to the appropriate type for the helper function, the |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
304 |
// helper invoked on the translated arguments, and the result |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
305 |
// translated back. Type is the parameter / return type of the |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
306 |
// helper function. |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
307 |
template<typename Type, typename Fn, typename T> |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
308 |
static T cmpxchg_using_helper(Fn fn, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
309 |
T exchange_value, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
310 |
T volatile* dest, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
311 |
T compare_value); |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
312 |
|
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
313 |
// Support platforms that do not provide Read-Modify-Write |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
314 |
// byte-level atomic access. To use, derive PlatformCmpxchg<1> from |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
315 |
// this class. |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
316 |
public: // Temporary, can't be private: C++03 11.4/2. Fixed by C++11. |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
317 |
struct CmpxchgByteUsingInt; |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
318 |
private: |
47578
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
319 |
|
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
320 |
// Dispatch handler for xchg. Provides type-based validity |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
321 |
// checking and limited conversions around calls to the |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
322 |
// platform-specific implementation layer provided by |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
323 |
// PlatformXchg. |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
324 |
template<typename T, typename D, typename Enable = void> |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
325 |
struct XchgImpl; |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
326 |
|
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
327 |
// Platform-specific implementation of xchg. Support for sizes |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
328 |
// of 4, and sizeof(intptr_t) are required. The class is a function |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
329 |
// object that must be default constructable, with these requirements: |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
330 |
// |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
331 |
// - dest is of type T*. |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
332 |
// - exchange_value is of type T. |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
333 |
// - platform_xchg is an object of type PlatformXchg<sizeof(T)>. |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
334 |
// |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
335 |
// Then |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
336 |
// platform_xchg(exchange_value, dest) |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
337 |
// must be a valid expression, returning a result convertible to T. |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
338 |
// |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
339 |
// A default definition is provided, which declares a function template |
50029
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
49364
diff
changeset
|
340 |
// T operator()(T, T volatile*, T, atomic_memory_order) const |
47578
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
341 |
// |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
342 |
// For each required size, a platform must either provide an |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
343 |
// appropriate definition of that function, or must entirely |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
344 |
// specialize the class template for that size. |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
345 |
template<size_t byte_size> struct PlatformXchg; |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
346 |
|
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
347 |
// Support for platforms that implement some variants of xchg |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
348 |
// using a (typically out of line) non-template helper function. |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
349 |
// The generic arguments passed to PlatformXchg need to be |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
350 |
// translated to the appropriate type for the helper function, the |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
351 |
// helper invoked on the translated arguments, and the result |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
352 |
// translated back. Type is the parameter / return type of the |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
353 |
// helper function. |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
354 |
template<typename Type, typename Fn, typename T> |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
355 |
static T xchg_using_helper(Fn fn, |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
356 |
T exchange_value, |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
357 |
T volatile* dest); |
46958
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
358 |
}; |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
359 |
|
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
360 |
template<typename From, typename To> |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
361 |
struct Atomic::IsPointerConvertible<From*, To*> : AllStatic { |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
362 |
// Determine whether From* is implicitly convertible to To*, using |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
363 |
// the "sizeof trick". |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
364 |
typedef char yes; |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
365 |
typedef char (&no)[2]; |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
366 |
|
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
367 |
static yes test(To*); |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
368 |
static no test(...); |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
369 |
static From* test_value; |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
370 |
|
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
371 |
static const bool value = (sizeof(yes) == sizeof(test(test_value))); |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
372 |
}; |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
373 |
|
47593
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
374 |
// Handle load for pointer, integral and enum types. |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
375 |
template<typename T, typename PlatformOp> |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
376 |
struct Atomic::LoadImpl< |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
377 |
T, |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
378 |
PlatformOp, |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
379 |
typename EnableIf<IsIntegral<T>::value || IsRegisteredEnum<T>::value || IsPointer<T>::value>::type> |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
380 |
{ |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
381 |
T operator()(T const volatile* dest) const { |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
382 |
// Forward to the platform handler for the size of T. |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
383 |
return PlatformOp()(dest); |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
384 |
} |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
385 |
}; |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
386 |
|
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
387 |
// Handle load for types that have a translator. |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
388 |
// |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
389 |
// All the involved types must be identical. |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
390 |
// |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
391 |
// This translates the original call into a call on the decayed |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
392 |
// arguments, and returns the recovered result of that translated |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
393 |
// call. |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
394 |
template<typename T, typename PlatformOp> |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
395 |
struct Atomic::LoadImpl< |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
396 |
T, |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
397 |
PlatformOp, |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
398 |
typename EnableIf<PrimitiveConversions::Translate<T>::value>::type> |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
399 |
{ |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
400 |
T operator()(T const volatile* dest) const { |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
401 |
typedef PrimitiveConversions::Translate<T> Translator; |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
402 |
typedef typename Translator::Decayed Decayed; |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
403 |
STATIC_ASSERT(sizeof(T) == sizeof(Decayed)); |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
404 |
Decayed result = PlatformOp()(reinterpret_cast<Decayed const volatile*>(dest)); |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
405 |
return Translator::recover(result); |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
406 |
} |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
407 |
}; |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
408 |
|
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
409 |
// Default implementation of atomic load if a specific platform |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
410 |
// does not provide a specialization for a certain size class. |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
411 |
// For increased safety, the default implementation only allows |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
412 |
// load types that are pointer sized or smaller. If a platform still |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
413 |
// supports wide atomics, then it has to use specialization |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
414 |
// of Atomic::PlatformLoad for that wider size class. |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
415 |
template<size_t byte_size> |
49364
601146c66cad
8173070: Remove ValueObj class for allocation subclassing for runtime code
coleenp
parents:
49022
diff
changeset
|
416 |
struct Atomic::PlatformLoad { |
47593
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
417 |
template<typename T> |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
418 |
T operator()(T const volatile* dest) const { |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
419 |
STATIC_ASSERT(sizeof(T) <= sizeof(void*)); // wide atomics need specialization |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
420 |
return *dest; |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
421 |
} |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
422 |
}; |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
423 |
|
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
424 |
// Handle store for integral and enum types. |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
425 |
// |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
426 |
// All the involved types must be identical. |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
427 |
template<typename T, typename PlatformOp> |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
428 |
struct Atomic::StoreImpl< |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
429 |
T, T, |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
430 |
PlatformOp, |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
431 |
typename EnableIf<IsIntegral<T>::value || IsRegisteredEnum<T>::value>::type> |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
432 |
{ |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
433 |
void operator()(T new_value, T volatile* dest) const { |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
434 |
// Forward to the platform handler for the size of T. |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
435 |
PlatformOp()(new_value, dest); |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
436 |
} |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
437 |
}; |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
438 |
|
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
439 |
// Handle store for pointer types. |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
440 |
// |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
441 |
// The new_value must be implicitly convertible to the |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
442 |
// destination's type; it must be type-correct to store the |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
443 |
// new_value in the destination. |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
444 |
template<typename T, typename D, typename PlatformOp> |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
445 |
struct Atomic::StoreImpl< |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
446 |
T*, D*, |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
447 |
PlatformOp, |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
448 |
typename EnableIf<Atomic::IsPointerConvertible<T*, D*>::value>::type> |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
449 |
{ |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
450 |
void operator()(T* new_value, D* volatile* dest) const { |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
451 |
// Allow derived to base conversion, and adding cv-qualifiers. |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
452 |
D* value = new_value; |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
453 |
PlatformOp()(value, dest); |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
454 |
} |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
455 |
}; |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
456 |
|
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
457 |
// Handle store for types that have a translator. |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
458 |
// |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
459 |
// All the involved types must be identical. |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
460 |
// |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
461 |
// This translates the original call into a call on the decayed |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
462 |
// arguments. |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
463 |
template<typename T, typename PlatformOp> |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
464 |
struct Atomic::StoreImpl< |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
465 |
T, T, |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
466 |
PlatformOp, |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
467 |
typename EnableIf<PrimitiveConversions::Translate<T>::value>::type> |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
468 |
{ |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
469 |
void operator()(T new_value, T volatile* dest) const { |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
470 |
typedef PrimitiveConversions::Translate<T> Translator; |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
471 |
typedef typename Translator::Decayed Decayed; |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
472 |
STATIC_ASSERT(sizeof(T) == sizeof(Decayed)); |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
473 |
PlatformOp()(Translator::decay(new_value), |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
474 |
reinterpret_cast<Decayed volatile*>(dest)); |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
475 |
} |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
476 |
}; |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
477 |
|
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
478 |
// Default implementation of atomic store if a specific platform |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
479 |
// does not provide a specialization for a certain size class. |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
480 |
// For increased safety, the default implementation only allows |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
481 |
// storing types that are pointer sized or smaller. If a platform still |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
482 |
// supports wide atomics, then it has to use specialization |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
483 |
// of Atomic::PlatformStore for that wider size class. |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
484 |
template<size_t byte_size> |
49364
601146c66cad
8173070: Remove ValueObj class for allocation subclassing for runtime code
coleenp
parents:
49022
diff
changeset
|
485 |
struct Atomic::PlatformStore { |
47593
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
486 |
template<typename T> |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
487 |
void operator()(T new_value, |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
488 |
T volatile* dest) const { |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
489 |
STATIC_ASSERT(sizeof(T) <= sizeof(void*)); // wide atomics need specialization |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
490 |
(void)const_cast<T&>(*dest = new_value); |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
491 |
} |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
492 |
}; |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
493 |
|
46993
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
494 |
// Define FetchAndAdd and AddAndFetch helper classes before including |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
495 |
// platform file, which may use these as base classes, requiring they |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
496 |
// be complete. |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
497 |
|
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
498 |
template<typename Derived> |
49364
601146c66cad
8173070: Remove ValueObj class for allocation subclassing for runtime code
coleenp
parents:
49022
diff
changeset
|
499 |
struct Atomic::FetchAndAdd { |
46993
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
500 |
template<typename I, typename D> |
50029
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
49364
diff
changeset
|
501 |
D operator()(I add_value, D volatile* dest, atomic_memory_order order) const; |
46993
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
502 |
}; |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
503 |
|
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
504 |
template<typename Derived> |
49364
601146c66cad
8173070: Remove ValueObj class for allocation subclassing for runtime code
coleenp
parents:
49022
diff
changeset
|
505 |
struct Atomic::AddAndFetch { |
46993
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
506 |
template<typename I, typename D> |
50029
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
49364
diff
changeset
|
507 |
D operator()(I add_value, D volatile* dest, atomic_memory_order order) const; |
46993
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
508 |
}; |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
509 |
|
47552
8a3599d60996
8186838: Generalize Atomic::inc/dec with templates
eosterlund
parents:
47216
diff
changeset
|
510 |
template<typename D> |
50029
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
49364
diff
changeset
|
511 |
inline void Atomic::inc(D volatile* dest, atomic_memory_order order) { |
47552
8a3599d60996
8186838: Generalize Atomic::inc/dec with templates
eosterlund
parents:
47216
diff
changeset
|
512 |
STATIC_ASSERT(IsPointer<D>::value || IsIntegral<D>::value); |
8a3599d60996
8186838: Generalize Atomic::inc/dec with templates
eosterlund
parents:
47216
diff
changeset
|
513 |
typedef typename Conditional<IsPointer<D>::value, ptrdiff_t, D>::type I; |
50029
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
49364
diff
changeset
|
514 |
Atomic::add(I(1), dest, order); |
47552
8a3599d60996
8186838: Generalize Atomic::inc/dec with templates
eosterlund
parents:
47216
diff
changeset
|
515 |
} |
8a3599d60996
8186838: Generalize Atomic::inc/dec with templates
eosterlund
parents:
47216
diff
changeset
|
516 |
|
8a3599d60996
8186838: Generalize Atomic::inc/dec with templates
eosterlund
parents:
47216
diff
changeset
|
517 |
template<typename D> |
50029
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
49364
diff
changeset
|
518 |
inline void Atomic::dec(D volatile* dest, atomic_memory_order order) { |
47552
8a3599d60996
8186838: Generalize Atomic::inc/dec with templates
eosterlund
parents:
47216
diff
changeset
|
519 |
STATIC_ASSERT(IsPointer<D>::value || IsIntegral<D>::value); |
8a3599d60996
8186838: Generalize Atomic::inc/dec with templates
eosterlund
parents:
47216
diff
changeset
|
520 |
typedef typename Conditional<IsPointer<D>::value, ptrdiff_t, D>::type I; |
8a3599d60996
8186838: Generalize Atomic::inc/dec with templates
eosterlund
parents:
47216
diff
changeset
|
521 |
// Assumes two's complement integer representation. |
8a3599d60996
8186838: Generalize Atomic::inc/dec with templates
eosterlund
parents:
47216
diff
changeset
|
522 |
#pragma warning(suppress: 4146) |
50029
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
49364
diff
changeset
|
523 |
Atomic::add(I(-1), dest, order); |
47552
8a3599d60996
8186838: Generalize Atomic::inc/dec with templates
eosterlund
parents:
47216
diff
changeset
|
524 |
} |
8a3599d60996
8186838: Generalize Atomic::inc/dec with templates
eosterlund
parents:
47216
diff
changeset
|
525 |
|
47634
6a0c42c40cd1
8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents:
47609
diff
changeset
|
526 |
template<typename I, typename D> |
50029
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
49364
diff
changeset
|
527 |
inline D Atomic::sub(I sub_value, D volatile* dest, atomic_memory_order order) { |
47634
6a0c42c40cd1
8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents:
47609
diff
changeset
|
528 |
STATIC_ASSERT(IsPointer<D>::value || IsIntegral<D>::value); |
6a0c42c40cd1
8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents:
47609
diff
changeset
|
529 |
STATIC_ASSERT(IsIntegral<I>::value); |
6a0c42c40cd1
8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents:
47609
diff
changeset
|
530 |
// If D is a pointer type, use [u]intptr_t as the addend type, |
6a0c42c40cd1
8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents:
47609
diff
changeset
|
531 |
// matching signedness of I. Otherwise, use D as the addend type. |
6a0c42c40cd1
8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents:
47609
diff
changeset
|
532 |
typedef typename Conditional<IsSigned<I>::value, intptr_t, uintptr_t>::type PI; |
6a0c42c40cd1
8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents:
47609
diff
changeset
|
533 |
typedef typename Conditional<IsPointer<D>::value, PI, D>::type AddendType; |
6a0c42c40cd1
8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents:
47609
diff
changeset
|
534 |
// Only allow conversions that can't change the value. |
6a0c42c40cd1
8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents:
47609
diff
changeset
|
535 |
STATIC_ASSERT(IsSigned<I>::value == IsSigned<AddendType>::value); |
6a0c42c40cd1
8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents:
47609
diff
changeset
|
536 |
STATIC_ASSERT(sizeof(I) <= sizeof(AddendType)); |
6a0c42c40cd1
8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents:
47609
diff
changeset
|
537 |
AddendType addend = sub_value; |
6a0c42c40cd1
8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents:
47609
diff
changeset
|
538 |
// Assumes two's complement integer representation. |
6a0c42c40cd1
8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents:
47609
diff
changeset
|
539 |
#pragma warning(suppress: 4146) // In case AddendType is not signed. |
50029
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
49364
diff
changeset
|
540 |
return Atomic::add(-addend, dest, order); |
47634
6a0c42c40cd1
8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents:
47609
diff
changeset
|
541 |
} |
6a0c42c40cd1
8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents:
47609
diff
changeset
|
542 |
|
46958
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
543 |
// Define the class before including platform file, which may specialize |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
544 |
// the operator definition. No generic definition of specializations |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
545 |
// of the operator template are provided, nor are there any generic |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
546 |
// specializations of the class. The platform file is responsible for |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
547 |
// providing those. |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
548 |
template<size_t byte_size> |
49364
601146c66cad
8173070: Remove ValueObj class for allocation subclassing for runtime code
coleenp
parents:
49022
diff
changeset
|
549 |
struct Atomic::PlatformCmpxchg { |
46958
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
550 |
template<typename T> |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
551 |
T operator()(T exchange_value, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
552 |
T volatile* dest, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
553 |
T compare_value, |
50029
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
49364
diff
changeset
|
554 |
atomic_memory_order order) const; |
46958
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
555 |
}; |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
556 |
|
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
557 |
// Define the class before including platform file, which may use this |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
558 |
// as a base class, requiring it be complete. The definition is later |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
559 |
// in this file, near the other definitions related to cmpxchg. |
49364
601146c66cad
8173070: Remove ValueObj class for allocation subclassing for runtime code
coleenp
parents:
49022
diff
changeset
|
560 |
struct Atomic::CmpxchgByteUsingInt { |
46958
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
561 |
template<typename T> |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
562 |
T operator()(T exchange_value, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
563 |
T volatile* dest, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
564 |
T compare_value, |
50029
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
49364
diff
changeset
|
565 |
atomic_memory_order order) const; |
1 | 566 |
}; |
7397 | 567 |
|
47578
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
568 |
// Define the class before including platform file, which may specialize |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
569 |
// the operator definition. No generic definition of specializations |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
570 |
// of the operator template are provided, nor are there any generic |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
571 |
// specializations of the class. The platform file is responsible for |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
572 |
// providing those. |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
573 |
template<size_t byte_size> |
49364
601146c66cad
8173070: Remove ValueObj class for allocation subclassing for runtime code
coleenp
parents:
49022
diff
changeset
|
574 |
struct Atomic::PlatformXchg { |
47578
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
575 |
template<typename T> |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
576 |
T operator()(T exchange_value, |
50029
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
49364
diff
changeset
|
577 |
T volatile* dest, |
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
49364
diff
changeset
|
578 |
atomic_memory_order order) const; |
47578
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
579 |
}; |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
580 |
|
40655
9f644073d3a0
8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents:
39404
diff
changeset
|
581 |
// platform specific in-line definitions - must come before shared definitions |
9f644073d3a0
8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents:
39404
diff
changeset
|
582 |
|
9f644073d3a0
8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents:
39404
diff
changeset
|
583 |
#include OS_CPU_HEADER(atomic) |
18438
9ea6bbfe0b83
8009575: Reduce Symbol::_refcount from 4 bytes to 2 bytes
iklam
parents:
15803
diff
changeset
|
584 |
|
40655
9f644073d3a0
8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents:
39404
diff
changeset
|
585 |
// shared in-line definitions |
9f644073d3a0
8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents:
39404
diff
changeset
|
586 |
|
9f644073d3a0
8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents:
39404
diff
changeset
|
587 |
// size_t casts... |
9f644073d3a0
8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents:
39404
diff
changeset
|
588 |
#if (SIZE_MAX != UINTPTR_MAX) |
9f644073d3a0
8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents:
39404
diff
changeset
|
589 |
#error size_t is not WORD_SIZE, interesting platform, but missing implementation here |
18438
9ea6bbfe0b83
8009575: Reduce Symbol::_refcount from 4 bytes to 2 bytes
iklam
parents:
15803
diff
changeset
|
590 |
#endif |
9ea6bbfe0b83
8009575: Reduce Symbol::_refcount from 4 bytes to 2 bytes
iklam
parents:
15803
diff
changeset
|
591 |
|
47593
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
592 |
template<typename T> |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
593 |
inline T Atomic::load(const volatile T* dest) { |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
594 |
return LoadImpl<T, PlatformLoad<sizeof(T)> >()(dest); |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
595 |
} |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
596 |
|
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
597 |
template<typename T, typename D> |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
598 |
inline void Atomic::store(T store_value, volatile D* dest) { |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
599 |
StoreImpl<T, D, PlatformStore<sizeof(D)> >()(store_value, dest); |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
600 |
} |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
601 |
|
46993
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
602 |
template<typename I, typename D> |
50029
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
49364
diff
changeset
|
603 |
inline D Atomic::add(I add_value, D volatile* dest, |
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
49364
diff
changeset
|
604 |
atomic_memory_order order) { |
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
49364
diff
changeset
|
605 |
return AddImpl<I, D>()(add_value, dest, order); |
46993
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
606 |
} |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
607 |
|
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
608 |
template<typename I, typename D> |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
609 |
struct Atomic::AddImpl< |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
610 |
I, D, |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
611 |
typename EnableIf<IsIntegral<I>::value && |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
612 |
IsIntegral<D>::value && |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
613 |
(sizeof(I) <= sizeof(D)) && |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
614 |
(IsSigned<I>::value == IsSigned<D>::value)>::type> |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
615 |
{ |
50029
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
49364
diff
changeset
|
616 |
D operator()(I add_value, D volatile* dest, atomic_memory_order order) const { |
46993
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
617 |
D addend = add_value; |
50029
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
49364
diff
changeset
|
618 |
return PlatformAdd<sizeof(D)>()(addend, dest, order); |
46993
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
619 |
} |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
620 |
}; |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
621 |
|
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
622 |
template<typename I, typename P> |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
623 |
struct Atomic::AddImpl< |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
624 |
I, P*, |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
625 |
typename EnableIf<IsIntegral<I>::value && (sizeof(I) <= sizeof(P*))>::type> |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
626 |
{ |
50029
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
49364
diff
changeset
|
627 |
P* operator()(I add_value, P* volatile* dest, atomic_memory_order order) const { |
46993
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
628 |
STATIC_ASSERT(sizeof(intptr_t) == sizeof(P*)); |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
629 |
STATIC_ASSERT(sizeof(uintptr_t) == sizeof(P*)); |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
630 |
typedef typename Conditional<IsSigned<I>::value, |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
631 |
intptr_t, |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
632 |
uintptr_t>::type CI; |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
633 |
CI addend = add_value; |
50029
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
49364
diff
changeset
|
634 |
return PlatformAdd<sizeof(P*)>()(addend, dest, order); |
46993
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
635 |
} |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
636 |
}; |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
637 |
|
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
638 |
template<typename Derived> |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
639 |
template<typename I, typename D> |
50029
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
49364
diff
changeset
|
640 |
inline D Atomic::FetchAndAdd<Derived>::operator()(I add_value, D volatile* dest, |
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
49364
diff
changeset
|
641 |
atomic_memory_order order) const { |
46993
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
642 |
I addend = add_value; |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
643 |
// If D is a pointer type P*, scale by sizeof(P). |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
644 |
if (IsPointer<D>::value) { |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
645 |
addend *= sizeof(typename RemovePointer<D>::type); |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
646 |
} |
50029
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
49364
diff
changeset
|
647 |
D old = static_cast<const Derived*>(this)->fetch_and_add(addend, dest, order); |
46993
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
648 |
return old + add_value; |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
649 |
} |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
650 |
|
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
651 |
template<typename Derived> |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
652 |
template<typename I, typename D> |
50029
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
49364
diff
changeset
|
653 |
inline D Atomic::AddAndFetch<Derived>::operator()(I add_value, D volatile* dest, |
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
49364
diff
changeset
|
654 |
atomic_memory_order order) const { |
46993
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
655 |
// If D is a pointer type P*, scale by sizeof(P). |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
656 |
if (IsPointer<D>::value) { |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
657 |
add_value *= sizeof(typename RemovePointer<D>::type); |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
658 |
} |
50029
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
49364
diff
changeset
|
659 |
return static_cast<const Derived*>(this)->add_and_fetch(add_value, dest, order); |
46993
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
660 |
} |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
661 |
|
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
662 |
template<typename Type, typename Fn, typename I, typename D> |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
663 |
inline D Atomic::add_using_helper(Fn fn, I add_value, D volatile* dest) { |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
664 |
return PrimitiveConversions::cast<D>( |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
665 |
fn(PrimitiveConversions::cast<Type>(add_value), |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
666 |
reinterpret_cast<Type volatile*>(dest))); |
40655
9f644073d3a0
8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents:
39404
diff
changeset
|
667 |
} |
9f644073d3a0
8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents:
39404
diff
changeset
|
668 |
|
46958
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
669 |
template<typename T, typename D, typename U> |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
670 |
inline D Atomic::cmpxchg(T exchange_value, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
671 |
D volatile* dest, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
672 |
U compare_value, |
50029
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
49364
diff
changeset
|
673 |
atomic_memory_order order) { |
46958
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
674 |
return CmpxchgImpl<T, D, U>()(exchange_value, dest, compare_value, order); |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
675 |
} |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
676 |
|
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
677 |
template<typename T, typename D> |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
678 |
inline bool Atomic::replace_if_null(T* value, D* volatile* dest, |
50029
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
49364
diff
changeset
|
679 |
atomic_memory_order order) { |
46958
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
680 |
// Presently using a trivial implementation in terms of cmpxchg. |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
681 |
// Consider adding platform support, to permit the use of compiler |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
682 |
// intrinsics like gcc's __sync_bool_compare_and_swap. |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
683 |
D* expected_null = NULL; |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
684 |
return expected_null == cmpxchg(value, dest, expected_null, order); |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
685 |
} |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
686 |
|
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
687 |
// Handle cmpxchg for integral and enum types. |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
688 |
// |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
689 |
// All the involved types must be identical. |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
690 |
template<typename T> |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
691 |
struct Atomic::CmpxchgImpl< |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
692 |
T, T, T, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
693 |
typename EnableIf<IsIntegral<T>::value || IsRegisteredEnum<T>::value>::type> |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
694 |
{ |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
695 |
T operator()(T exchange_value, T volatile* dest, T compare_value, |
50029
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
49364
diff
changeset
|
696 |
atomic_memory_order order) const { |
46958
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
697 |
// Forward to the platform handler for the size of T. |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
698 |
return PlatformCmpxchg<sizeof(T)>()(exchange_value, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
699 |
dest, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
700 |
compare_value, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
701 |
order); |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
702 |
} |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
703 |
}; |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
704 |
|
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
705 |
// Handle cmpxchg for pointer types. |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
706 |
// |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
707 |
// The destination's type and the compare_value type must be the same, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
708 |
// ignoring cv-qualifiers; we don't care about the cv-qualifiers of |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
709 |
// the compare_value. |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
710 |
// |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
711 |
// The exchange_value must be implicitly convertible to the |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
712 |
// destination's type; it must be type-correct to store the |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
713 |
// exchange_value in the destination. |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
714 |
template<typename T, typename D, typename U> |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
715 |
struct Atomic::CmpxchgImpl< |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
716 |
T*, D*, U*, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
717 |
typename EnableIf<Atomic::IsPointerConvertible<T*, D*>::value && |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
718 |
IsSame<typename RemoveCV<D>::type, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
719 |
typename RemoveCV<U>::type>::value>::type> |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
720 |
{ |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
721 |
D* operator()(T* exchange_value, D* volatile* dest, U* compare_value, |
50029
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
49364
diff
changeset
|
722 |
atomic_memory_order order) const { |
46958
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
723 |
// Allow derived to base conversion, and adding cv-qualifiers. |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
724 |
D* new_value = exchange_value; |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
725 |
// Don't care what the CV qualifiers for compare_value are, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
726 |
// but we need to match D* when calling platform support. |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
727 |
D* old_value = const_cast<D*>(compare_value); |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
728 |
return PlatformCmpxchg<sizeof(D*)>()(new_value, dest, old_value, order); |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
729 |
} |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
730 |
}; |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
731 |
|
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
732 |
// Handle cmpxchg for types that have a translator. |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
733 |
// |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
734 |
// All the involved types must be identical. |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
735 |
// |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
736 |
// This translates the original call into a call on the decayed |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
737 |
// arguments, and returns the recovered result of that translated |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
738 |
// call. |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
739 |
template<typename T> |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
740 |
struct Atomic::CmpxchgImpl< |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
741 |
T, T, T, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
742 |
typename EnableIf<PrimitiveConversions::Translate<T>::value>::type> |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
743 |
{ |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
744 |
T operator()(T exchange_value, T volatile* dest, T compare_value, |
50029
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
49364
diff
changeset
|
745 |
atomic_memory_order order) const { |
46958
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
746 |
typedef PrimitiveConversions::Translate<T> Translator; |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
747 |
typedef typename Translator::Decayed Decayed; |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
748 |
STATIC_ASSERT(sizeof(T) == sizeof(Decayed)); |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
749 |
return Translator::recover( |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
750 |
cmpxchg(Translator::decay(exchange_value), |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
751 |
reinterpret_cast<Decayed volatile*>(dest), |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
752 |
Translator::decay(compare_value), |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
753 |
order)); |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
754 |
} |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
755 |
}; |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
756 |
|
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
757 |
template<typename Type, typename Fn, typename T> |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
758 |
inline T Atomic::cmpxchg_using_helper(Fn fn, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
759 |
T exchange_value, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
760 |
T volatile* dest, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
761 |
T compare_value) { |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
762 |
STATIC_ASSERT(sizeof(Type) == sizeof(T)); |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
763 |
return PrimitiveConversions::cast<T>( |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
764 |
fn(PrimitiveConversions::cast<Type>(exchange_value), |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
765 |
reinterpret_cast<Type volatile*>(dest), |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
766 |
PrimitiveConversions::cast<Type>(compare_value))); |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
767 |
} |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
768 |
|
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
769 |
template<typename T> |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
770 |
inline T Atomic::CmpxchgByteUsingInt::operator()(T exchange_value, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
771 |
T volatile* dest, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
772 |
T compare_value, |
50029
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
49364
diff
changeset
|
773 |
atomic_memory_order order) const { |
46958
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
774 |
STATIC_ASSERT(sizeof(T) == sizeof(uint8_t)); |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
775 |
uint8_t canon_exchange_value = exchange_value; |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
776 |
uint8_t canon_compare_value = compare_value; |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
777 |
volatile uint32_t* aligned_dest |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
778 |
= reinterpret_cast<volatile uint32_t*>(align_down(dest, sizeof(uint32_t))); |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
779 |
size_t offset = pointer_delta(dest, aligned_dest, 1); |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
780 |
uint32_t cur = *aligned_dest; |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
781 |
uint8_t* cur_as_bytes = reinterpret_cast<uint8_t*>(&cur); |
40669
252f9d8272af
8157904: Atomic::cmpxchg for jbyte is missing a fence on initial failure
dholmes
parents:
40655
diff
changeset
|
782 |
|
252f9d8272af
8157904: Atomic::cmpxchg for jbyte is missing a fence on initial failure
dholmes
parents:
40655
diff
changeset
|
783 |
// current value may not be what we are looking for, so force it |
252f9d8272af
8157904: Atomic::cmpxchg for jbyte is missing a fence on initial failure
dholmes
parents:
40655
diff
changeset
|
784 |
// to that value so the initial cmpxchg will fail if it is different |
46958
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
785 |
cur_as_bytes[offset] = canon_compare_value; |
40669
252f9d8272af
8157904: Atomic::cmpxchg for jbyte is missing a fence on initial failure
dholmes
parents:
40655
diff
changeset
|
786 |
|
252f9d8272af
8157904: Atomic::cmpxchg for jbyte is missing a fence on initial failure
dholmes
parents:
40655
diff
changeset
|
787 |
// always execute a real cmpxchg so that we get the required memory |
252f9d8272af
8157904: Atomic::cmpxchg for jbyte is missing a fence on initial failure
dholmes
parents:
40655
diff
changeset
|
788 |
// barriers even on initial failure |
252f9d8272af
8157904: Atomic::cmpxchg for jbyte is missing a fence on initial failure
dholmes
parents:
40655
diff
changeset
|
789 |
do { |
252f9d8272af
8157904: Atomic::cmpxchg for jbyte is missing a fence on initial failure
dholmes
parents:
40655
diff
changeset
|
790 |
// value to swap in matches current value ... |
46958
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
791 |
uint32_t new_value = cur; |
48468 | 792 |
// ... except for the one byte we want to update |
46958
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
793 |
reinterpret_cast<uint8_t*>(&new_value)[offset] = canon_exchange_value; |
40669
252f9d8272af
8157904: Atomic::cmpxchg for jbyte is missing a fence on initial failure
dholmes
parents:
40655
diff
changeset
|
794 |
|
46958
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
795 |
uint32_t res = cmpxchg(new_value, aligned_dest, cur, order); |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
796 |
if (res == cur) break; // success |
40669
252f9d8272af
8157904: Atomic::cmpxchg for jbyte is missing a fence on initial failure
dholmes
parents:
40655
diff
changeset
|
797 |
|
46958
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
798 |
// at least one byte in the int changed value, so update |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
799 |
// our view of the current int |
40655
9f644073d3a0
8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents:
39404
diff
changeset
|
800 |
cur = res; |
46958
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
801 |
// if our byte is still as cur we loop and try again |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
802 |
} while (cur_as_bytes[offset] == canon_compare_value); |
40669
252f9d8272af
8157904: Atomic::cmpxchg for jbyte is missing a fence on initial failure
dholmes
parents:
40655
diff
changeset
|
803 |
|
46958
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
804 |
return PrimitiveConversions::cast<T>(cur_as_bytes[offset]); |
40655
9f644073d3a0
8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents:
39404
diff
changeset
|
805 |
} |
40669
252f9d8272af
8157904: Atomic::cmpxchg for jbyte is missing a fence on initial failure
dholmes
parents:
40655
diff
changeset
|
806 |
|
47578
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
807 |
// Handle xchg for integral and enum types. |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
808 |
// |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
809 |
// All the involved types must be identical. |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
810 |
template<typename T> |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
811 |
struct Atomic::XchgImpl< |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
812 |
T, T, |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
813 |
typename EnableIf<IsIntegral<T>::value || IsRegisteredEnum<T>::value>::type> |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
814 |
{ |
50029
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
49364
diff
changeset
|
815 |
T operator()(T exchange_value, T volatile* dest, atomic_memory_order order) const { |
47578
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
816 |
// Forward to the platform handler for the size of T. |
50029
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
49364
diff
changeset
|
817 |
return PlatformXchg<sizeof(T)>()(exchange_value, dest, order); |
47578
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
818 |
} |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
819 |
}; |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
820 |
|
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
821 |
// Handle xchg for pointer types. |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
822 |
// |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
823 |
// The exchange_value must be implicitly convertible to the |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
824 |
// destination's type; it must be type-correct to store the |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
825 |
// exchange_value in the destination. |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
826 |
template<typename T, typename D> |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
827 |
struct Atomic::XchgImpl< |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
828 |
T*, D*, |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
829 |
typename EnableIf<Atomic::IsPointerConvertible<T*, D*>::value>::type> |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
830 |
{ |
50029
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
49364
diff
changeset
|
831 |
D* operator()(T* exchange_value, D* volatile* dest, atomic_memory_order order) const { |
47578
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
832 |
// Allow derived to base conversion, and adding cv-qualifiers. |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
833 |
D* new_value = exchange_value; |
50029
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
49364
diff
changeset
|
834 |
return PlatformXchg<sizeof(D*)>()(new_value, dest, order); |
47578
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
835 |
} |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
836 |
}; |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
837 |
|
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
838 |
// Handle xchg for types that have a translator. |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
839 |
// |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
840 |
// All the involved types must be identical. |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
841 |
// |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
842 |
// This translates the original call into a call on the decayed |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
843 |
// arguments, and returns the recovered result of that translated |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
844 |
// call. |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
845 |
template<typename T> |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
846 |
struct Atomic::XchgImpl< |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
847 |
T, T, |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
848 |
typename EnableIf<PrimitiveConversions::Translate<T>::value>::type> |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
849 |
{ |
50029
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
49364
diff
changeset
|
850 |
T operator()(T exchange_value, T volatile* dest, atomic_memory_order order) const { |
47578
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
851 |
typedef PrimitiveConversions::Translate<T> Translator; |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
852 |
typedef typename Translator::Decayed Decayed; |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
853 |
STATIC_ASSERT(sizeof(T) == sizeof(Decayed)); |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
854 |
return Translator::recover( |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
855 |
xchg(Translator::decay(exchange_value), |
50029
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
49364
diff
changeset
|
856 |
reinterpret_cast<Decayed volatile*>(dest), |
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
49364
diff
changeset
|
857 |
order)); |
47578
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
858 |
} |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
859 |
}; |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
860 |
|
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
861 |
template<typename Type, typename Fn, typename T> |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
862 |
inline T Atomic::xchg_using_helper(Fn fn, |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
863 |
T exchange_value, |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
864 |
T volatile* dest) { |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
865 |
STATIC_ASSERT(sizeof(Type) == sizeof(T)); |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
866 |
return PrimitiveConversions::cast<T>( |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
867 |
fn(PrimitiveConversions::cast<Type>(exchange_value), |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
868 |
reinterpret_cast<Type volatile*>(dest))); |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
869 |
} |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
870 |
|
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
871 |
template<typename T, typename D> |
50029
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
49364
diff
changeset
|
872 |
inline D Atomic::xchg(T exchange_value, volatile D* dest, atomic_memory_order order) { |
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
49364
diff
changeset
|
873 |
return XchgImpl<T, D>()(exchange_value, dest, order); |
40655
9f644073d3a0
8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents:
39404
diff
changeset
|
874 |
} |
9f644073d3a0
8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents:
39404
diff
changeset
|
875 |
|
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
51330
diff
changeset
|
876 |
#endif // SHARE_RUNTIME_ATOMIC_HPP |