author | erikj |
Tue, 12 Sep 2017 19:03:39 +0200 | |
changeset 47216 | 71c04702a3d5 |
parent 46993 | hotspot/src/share/vm/runtime/atomic.hpp@dd0f91c85ffc |
child 47552 | 8a3599d60996 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
46266
d5ccf56195af
8157709: NMT should use size_t version of Atomic::add
dholmes
parents:
40860
diff
changeset
|
2 |
* Copyright (c) 1999, 2017, 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 |
||
7397 | 25 |
#ifndef SHARE_VM_RUNTIME_ATOMIC_HPP |
26 |
#define SHARE_VM_RUNTIME_ATOMIC_HPP |
|
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 |
|
39404 | 40 |
enum cmpxchg_memory_order { |
41 |
memory_order_relaxed, |
|
42 |
// Use value which doesn't interfere with C++2011. We need to be more conservative. |
|
43 |
memory_order_conservative = 8 |
|
44 |
}; |
|
45 |
||
1 | 46 |
class Atomic : AllStatic { |
47 |
public: |
|
15803
9328492899cc
8008314: Unimplemented() Atomic::load breaks the applications
jwilhelm
parents:
14626
diff
changeset
|
48 |
// Atomic operations on jlong types are not available on all 32-bit |
9328492899cc
8008314: Unimplemented() Atomic::load breaks the applications
jwilhelm
parents:
14626
diff
changeset
|
49 |
// platforms. If atomic ops on jlongs are defined here they must only |
9328492899cc
8008314: Unimplemented() Atomic::load breaks the applications
jwilhelm
parents:
14626
diff
changeset
|
50 |
// 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
|
51 |
// can provide an alternative action if not - see supports_cx8() for |
9328492899cc
8008314: Unimplemented() Atomic::load breaks the applications
jwilhelm
parents:
14626
diff
changeset
|
52 |
// a means to test availability. |
9328492899cc
8008314: Unimplemented() Atomic::load breaks the applications
jwilhelm
parents:
14626
diff
changeset
|
53 |
|
25625
00dca966711e
8049104: resolve atomic.hpp wording issues from JDK-8047104 code review
dcubed
parents:
25069
diff
changeset
|
54 |
// 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
|
55 |
// 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
|
56 |
// 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
|
57 |
// 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
|
58 |
// on the Memory Access Ordering Model. |
00dca966711e
8049104: resolve atomic.hpp wording issues from JDK-8047104 code review
dcubed
parents:
25069
diff
changeset
|
59 |
|
00dca966711e
8049104: resolve atomic.hpp wording issues from JDK-8047104 code review
dcubed
parents:
25069
diff
changeset
|
60 |
// 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
|
61 |
// 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
|
62 |
// 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
|
63 |
// 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
|
64 |
// 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
|
65 |
|
1 | 66 |
// Atomically store to a location |
14626
0cf4eccf130f
8003240: x86: move MacroAssembler into separate file
twisti
parents:
9990
diff
changeset
|
67 |
inline static void store (jbyte store_value, jbyte* dest); |
0cf4eccf130f
8003240: x86: move MacroAssembler into separate file
twisti
parents:
9990
diff
changeset
|
68 |
inline static void store (jshort store_value, jshort* dest); |
0cf4eccf130f
8003240: x86: move MacroAssembler into separate file
twisti
parents:
9990
diff
changeset
|
69 |
inline static void store (jint store_value, jint* dest); |
15803
9328492899cc
8008314: Unimplemented() Atomic::load breaks the applications
jwilhelm
parents:
14626
diff
changeset
|
70 |
// See comment above about using jlong atomics on 32-bit platforms |
14626
0cf4eccf130f
8003240: x86: move MacroAssembler into separate file
twisti
parents:
9990
diff
changeset
|
71 |
inline static void store (jlong store_value, jlong* dest); |
0cf4eccf130f
8003240: x86: move MacroAssembler into separate file
twisti
parents:
9990
diff
changeset
|
72 |
inline static void store_ptr(intptr_t store_value, intptr_t* dest); |
0cf4eccf130f
8003240: x86: move MacroAssembler into separate file
twisti
parents:
9990
diff
changeset
|
73 |
inline static void store_ptr(void* store_value, void* dest); |
1 | 74 |
|
14626
0cf4eccf130f
8003240: x86: move MacroAssembler into separate file
twisti
parents:
9990
diff
changeset
|
75 |
inline static void store (jbyte store_value, volatile jbyte* dest); |
0cf4eccf130f
8003240: x86: move MacroAssembler into separate file
twisti
parents:
9990
diff
changeset
|
76 |
inline static void store (jshort store_value, volatile jshort* dest); |
0cf4eccf130f
8003240: x86: move MacroAssembler into separate file
twisti
parents:
9990
diff
changeset
|
77 |
inline static void store (jint store_value, volatile jint* dest); |
15803
9328492899cc
8008314: Unimplemented() Atomic::load breaks the applications
jwilhelm
parents:
14626
diff
changeset
|
78 |
// See comment above about using jlong atomics on 32-bit platforms |
14626
0cf4eccf130f
8003240: x86: move MacroAssembler into separate file
twisti
parents:
9990
diff
changeset
|
79 |
inline static void store (jlong store_value, volatile jlong* dest); |
0cf4eccf130f
8003240: x86: move MacroAssembler into separate file
twisti
parents:
9990
diff
changeset
|
80 |
inline static void store_ptr(intptr_t store_value, volatile intptr_t* dest); |
0cf4eccf130f
8003240: x86: move MacroAssembler into separate file
twisti
parents:
9990
diff
changeset
|
81 |
inline static void store_ptr(void* store_value, volatile void* dest); |
1 | 82 |
|
15803
9328492899cc
8008314: Unimplemented() Atomic::load breaks the applications
jwilhelm
parents:
14626
diff
changeset
|
83 |
// See comment above about using jlong atomics on 32-bit platforms |
46523
cbcc0ebaa044
8166651: OrderAccess::load_acquire &etc should have const parameters
kbarrett
parents:
46266
diff
changeset
|
84 |
inline static jlong load(const volatile jlong* src); |
3594
0ce9158bc84c
6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
670
diff
changeset
|
85 |
|
25625
00dca966711e
8049104: resolve atomic.hpp wording issues from JDK-8047104 code review
dcubed
parents:
25069
diff
changeset
|
86 |
// 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
|
87 |
// <fence> add-value-to-dest <membar StoreLoad|StoreStore> |
46993
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
88 |
|
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
89 |
template<typename I, typename D> |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
90 |
inline static D add(I add_value, D volatile* dest); |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
91 |
|
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
92 |
inline static intptr_t add_ptr(intptr_t add_value, volatile intptr_t* dest) { |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
93 |
return add(add_value, dest); |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
94 |
} |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
95 |
|
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
96 |
inline static void* add_ptr(intptr_t add_value, volatile void* dest) { |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
97 |
return add(add_value, reinterpret_cast<char* volatile*>(dest)); |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
98 |
} |
9990
c8683968c01b
6941923: RFE: Handling large log files produced by long running Java Applications
minqi
parents:
7397
diff
changeset
|
99 |
|
25625
00dca966711e
8049104: resolve atomic.hpp wording issues from JDK-8047104 code review
dcubed
parents:
25069
diff
changeset
|
100 |
// Atomically increment location. inc*() provide: |
00dca966711e
8049104: resolve atomic.hpp wording issues from JDK-8047104 code review
dcubed
parents:
25069
diff
changeset
|
101 |
// <fence> increment-dest <membar StoreLoad|StoreStore> |
14626
0cf4eccf130f
8003240: x86: move MacroAssembler into separate file
twisti
parents:
9990
diff
changeset
|
102 |
inline static void inc (volatile jint* dest); |
39404 | 103 |
inline static void inc (volatile jshort* dest); |
23523
75f522e33395
8037295: Add size_t versions of Atomic::add, dec, and inc
mgronlun
parents:
22234
diff
changeset
|
104 |
inline static void inc (volatile size_t* dest); |
14626
0cf4eccf130f
8003240: x86: move MacroAssembler into separate file
twisti
parents:
9990
diff
changeset
|
105 |
inline static void inc_ptr(volatile intptr_t* dest); |
0cf4eccf130f
8003240: x86: move MacroAssembler into separate file
twisti
parents:
9990
diff
changeset
|
106 |
inline static void inc_ptr(volatile void* dest); |
1 | 107 |
|
25625
00dca966711e
8049104: resolve atomic.hpp wording issues from JDK-8047104 code review
dcubed
parents:
25069
diff
changeset
|
108 |
// Atomically decrement a location. dec*() provide: |
00dca966711e
8049104: resolve atomic.hpp wording issues from JDK-8047104 code review
dcubed
parents:
25069
diff
changeset
|
109 |
// <fence> decrement-dest <membar StoreLoad|StoreStore> |
14626
0cf4eccf130f
8003240: x86: move MacroAssembler into separate file
twisti
parents:
9990
diff
changeset
|
110 |
inline static void dec (volatile jint* dest); |
39404 | 111 |
inline static void dec (volatile jshort* dest); |
23523
75f522e33395
8037295: Add size_t versions of Atomic::add, dec, and inc
mgronlun
parents:
22234
diff
changeset
|
112 |
inline static void dec (volatile size_t* dest); |
14626
0cf4eccf130f
8003240: x86: move MacroAssembler into separate file
twisti
parents:
9990
diff
changeset
|
113 |
inline static void dec_ptr(volatile intptr_t* dest); |
0cf4eccf130f
8003240: x86: move MacroAssembler into separate file
twisti
parents:
9990
diff
changeset
|
114 |
inline static void dec_ptr(volatile void* dest); |
1 | 115 |
|
25625
00dca966711e
8049104: resolve atomic.hpp wording issues from JDK-8047104 code review
dcubed
parents:
25069
diff
changeset
|
116 |
// 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
|
117 |
// prior value of *dest. xchg*() provide: |
00dca966711e
8049104: resolve atomic.hpp wording issues from JDK-8047104 code review
dcubed
parents:
25069
diff
changeset
|
118 |
// <fence> exchange-value-with-dest <membar StoreLoad|StoreStore> |
39404 | 119 |
inline static jint xchg (jint exchange_value, volatile jint* dest); |
120 |
inline static unsigned int xchg (unsigned int exchange_value, volatile unsigned int* dest); |
|
121 |
inline static intptr_t xchg_ptr(intptr_t exchange_value, volatile intptr_t* dest); |
|
122 |
inline static void* xchg_ptr(void* exchange_value, volatile void* dest); |
|
1 | 123 |
|
25625
00dca966711e
8049104: resolve atomic.hpp wording issues from JDK-8047104 code review
dcubed
parents:
25069
diff
changeset
|
124 |
// 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
|
125 |
// *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
|
126 |
// value of *dest. cmpxchg*() provide: |
00dca966711e
8049104: resolve atomic.hpp wording issues from JDK-8047104 code review
dcubed
parents:
25069
diff
changeset
|
127 |
// <fence> compare-and-exchange <membar StoreLoad|StoreStore> |
46958
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
128 |
|
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
129 |
template<typename T, typename D, typename U> |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
130 |
inline static D cmpxchg(T exchange_value, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
131 |
D volatile* dest, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
132 |
U compare_value, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
133 |
cmpxchg_memory_order order = memory_order_conservative); |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
134 |
|
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
135 |
// Performs atomic compare of *dest and NULL, and replaces *dest |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
136 |
// with exchange_value if the comparison succeeded. Returns true if |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
137 |
// the comparison succeeded and the exchange occurred. This is |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
138 |
// often used as part of lazy initialization, as a lock-free |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
139 |
// alternative to the Double-Checked Locking Pattern. |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
140 |
template<typename T, typename D> |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
141 |
inline static bool replace_if_null(T* value, D* volatile* dest, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
142 |
cmpxchg_memory_order order = memory_order_conservative); |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
143 |
|
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
144 |
inline static intptr_t cmpxchg_ptr(intptr_t exchange_value, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
145 |
volatile intptr_t* dest, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
146 |
intptr_t compare_value, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
147 |
cmpxchg_memory_order order = memory_order_conservative) { |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
148 |
return cmpxchg(exchange_value, dest, compare_value, order); |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
149 |
} |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
150 |
|
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
151 |
inline static void* cmpxchg_ptr(void* exchange_value, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
152 |
volatile void* dest, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
153 |
void* compare_value, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
154 |
cmpxchg_memory_order order = memory_order_conservative) { |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
155 |
return cmpxchg(exchange_value, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
156 |
reinterpret_cast<void* volatile*>(dest), |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
157 |
compare_value, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
158 |
order); |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
159 |
} |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
160 |
|
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
161 |
private: |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
162 |
// Test whether From is implicitly convertible to To. |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
163 |
// From and To must be pointer types. |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
164 |
// Note: Provides the limited subset of C++11 std::is_convertible |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
165 |
// that is needed here. |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
166 |
template<typename From, typename To> struct IsPointerConvertible; |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
167 |
|
46993
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
168 |
// Dispatch handler for add. Provides type-based validity checking |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
169 |
// and limited conversions around calls to the platform-specific |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
170 |
// implementation layer provided by PlatformAdd. |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
171 |
template<typename I, typename D, typename Enable = void> |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
172 |
struct AddImpl; |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
173 |
|
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
174 |
// Platform-specific implementation of add. Support for sizes of 4 |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
175 |
// bytes and (if different) pointer size bytes are required. The |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
176 |
// class is a function object that must be default constructable, |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
177 |
// with these requirements: |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
178 |
// |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
179 |
// - dest is of type D*, an integral or pointer type. |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
180 |
// - add_value is of type I, an integral type. |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
181 |
// - sizeof(I) == sizeof(D). |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
182 |
// - if D is an integral type, I == D. |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
183 |
// - platform_add is an object of type PlatformAdd<sizeof(D)>. |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
184 |
// |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
185 |
// Then |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
186 |
// platform_add(add_value, dest) |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
187 |
// must be a valid expression, returning a result convertible to D. |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
188 |
// |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
189 |
// No definition is provided; all platforms must explicitly define |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
190 |
// this class and any needed specializations. |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
191 |
template<size_t byte_size> struct PlatformAdd; |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
192 |
|
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
193 |
// Helper base classes for defining PlatformAdd. To use, define |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
194 |
// PlatformAdd or a specialization that derives from one of these, |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
195 |
// and include in the PlatformAdd definition the support function |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
196 |
// (described below) required by the base class. |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
197 |
// |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
198 |
// These classes implement the required function object protocol for |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
199 |
// PlatformAdd, using a support function template provided by the |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
200 |
// 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
|
201 |
// 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
|
202 |
// P*, then let addend (of type I) be add_value * sizeof(P); |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
203 |
// otherwise, addend is add_value. |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
204 |
// |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
205 |
// FetchAndAdd requires the derived class to provide |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
206 |
// fetch_and_add(addend, dest) |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
207 |
// atomically adding addend to the value of dest, and returning the |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
208 |
// old value. |
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 |
// AddAndFetch requires the derived class to provide |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
211 |
// add_and_fetch(addend, dest) |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
212 |
// atomically adding addend to the value of dest, and returning the |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
213 |
// new value. |
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 |
// 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
|
216 |
// 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
|
217 |
// scaling of the addend, as that has already been done by the |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
218 |
// caller. |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
219 |
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
|
220 |
template<typename Derived> struct FetchAndAdd; |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
221 |
template<typename Derived> struct AddAndFetch; |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
222 |
private: |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
223 |
|
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
224 |
// Support for platforms that implement some variants of add using a |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
225 |
// (typically out of line) non-template helper function. The |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
226 |
// generic arguments passed to PlatformAdd need to be translated to |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
227 |
// the appropriate type for the helper function, the helper function |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
228 |
// invoked on the translated arguments, and the result translated |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
229 |
// back. Type is the parameter / return type of the helper |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
230 |
// 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
|
231 |
// type, so this function can be used to implement the support function |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
232 |
// required by AddAndFetch. |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
233 |
template<typename Type, typename Fn, typename I, typename D> |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
234 |
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
|
235 |
|
46958
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
236 |
// Dispatch handler for cmpxchg. Provides type-based validity |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
237 |
// checking and limited conversions around calls to the |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
238 |
// platform-specific implementation layer provided by |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
239 |
// PlatformCmpxchg. |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
240 |
template<typename T, typename D, typename U, typename Enable = void> |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
241 |
struct CmpxchgImpl; |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
242 |
|
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
243 |
// Platform-specific implementation of cmpxchg. Support for sizes |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
244 |
// 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
|
245 |
// must be default constructable, with these requirements: |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
246 |
// |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
247 |
// - dest is of type T*. |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
248 |
// - exchange_value and compare_value are of type T. |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
249 |
// - order is of type cmpxchg_memory_order. |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
250 |
// - platform_cmpxchg is an object of type PlatformCmpxchg<sizeof(T)>. |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
251 |
// |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
252 |
// Then |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
253 |
// platform_cmpxchg(exchange_value, dest, compare_value, order) |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
254 |
// must be a valid expression, returning a result convertible to T. |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
255 |
// |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
256 |
// A default definition is provided, which declares a function template |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
257 |
// T operator()(T, T volatile*, T, cmpxchg_memory_order) const |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
258 |
// |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
259 |
// For each required size, a platform must either provide an |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
260 |
// appropriate definition of that function, or must entirely |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
261 |
// specialize the class template for that size. |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
262 |
template<size_t byte_size> struct PlatformCmpxchg; |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
263 |
|
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
264 |
// Support for platforms that implement some variants of cmpxchg |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
265 |
// using a (typically out of line) non-template helper function. |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
266 |
// The generic arguments passed to PlatformCmpxchg need to be |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
267 |
// translated to the appropriate type for the helper function, the |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
268 |
// helper invoked on the translated arguments, and the result |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
269 |
// translated back. Type is the parameter / return type of the |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
270 |
// helper function. |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
271 |
template<typename Type, typename Fn, typename T> |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
272 |
static T cmpxchg_using_helper(Fn fn, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
273 |
T exchange_value, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
274 |
T volatile* dest, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
275 |
T compare_value); |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
276 |
|
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
277 |
// Support platforms that do not provide Read-Modify-Write |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
278 |
// byte-level atomic access. To use, derive PlatformCmpxchg<1> from |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
279 |
// this class. |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
280 |
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
|
281 |
struct CmpxchgByteUsingInt; |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
282 |
private: |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
283 |
}; |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
284 |
|
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
285 |
template<typename From, typename To> |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
286 |
struct Atomic::IsPointerConvertible<From*, To*> : AllStatic { |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
287 |
// Determine whether From* is implicitly convertible to To*, using |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
288 |
// the "sizeof trick". |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
289 |
typedef char yes; |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
290 |
typedef char (&no)[2]; |
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 |
static yes test(To*); |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
293 |
static no test(...); |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
294 |
static From* test_value; |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
295 |
|
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
296 |
static const bool value = (sizeof(yes) == sizeof(test(test_value))); |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
297 |
}; |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
298 |
|
46993
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
299 |
// Define FetchAndAdd and AddAndFetch helper classes before including |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
300 |
// platform file, which may use these as base classes, requiring they |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
301 |
// be complete. |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
302 |
|
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
303 |
template<typename Derived> |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
304 |
struct Atomic::FetchAndAdd VALUE_OBJ_CLASS_SPEC { |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
305 |
template<typename I, typename D> |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
306 |
D operator()(I add_value, D volatile* dest) const; |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
307 |
}; |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
308 |
|
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
309 |
template<typename Derived> |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
310 |
struct Atomic::AddAndFetch VALUE_OBJ_CLASS_SPEC { |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
311 |
template<typename I, typename D> |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
312 |
D operator()(I add_value, D volatile* dest) const; |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
313 |
}; |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
314 |
|
46958
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
315 |
// Define the class before including platform file, which may specialize |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
316 |
// the operator definition. No generic definition of specializations |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
317 |
// of the operator template are provided, nor are there any generic |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
318 |
// specializations of the class. The platform file is responsible for |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
319 |
// providing those. |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
320 |
template<size_t byte_size> |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
321 |
struct Atomic::PlatformCmpxchg VALUE_OBJ_CLASS_SPEC { |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
322 |
template<typename T> |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
323 |
T operator()(T exchange_value, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
324 |
T volatile* dest, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
325 |
T compare_value, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
326 |
cmpxchg_memory_order order) const; |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
327 |
}; |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
328 |
|
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
329 |
// Define the class before including platform file, which may use this |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
330 |
// as a base class, requiring it be complete. The definition is later |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
331 |
// in this file, near the other definitions related to cmpxchg. |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
332 |
struct Atomic::CmpxchgByteUsingInt VALUE_OBJ_CLASS_SPEC { |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
333 |
template<typename T> |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
334 |
T operator()(T exchange_value, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
335 |
T volatile* dest, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
336 |
T compare_value, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
337 |
cmpxchg_memory_order order) const; |
1 | 338 |
}; |
7397 | 339 |
|
40655
9f644073d3a0
8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents:
39404
diff
changeset
|
340 |
// 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
|
341 |
|
9f644073d3a0
8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents:
39404
diff
changeset
|
342 |
#include OS_CPU_HEADER(atomic) |
18438
9ea6bbfe0b83
8009575: Reduce Symbol::_refcount from 4 bytes to 2 bytes
iklam
parents:
15803
diff
changeset
|
343 |
|
40655
9f644073d3a0
8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents:
39404
diff
changeset
|
344 |
// shared in-line definitions |
9f644073d3a0
8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents:
39404
diff
changeset
|
345 |
|
9f644073d3a0
8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents:
39404
diff
changeset
|
346 |
// size_t casts... |
9f644073d3a0
8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents:
39404
diff
changeset
|
347 |
#if (SIZE_MAX != UINTPTR_MAX) |
9f644073d3a0
8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents:
39404
diff
changeset
|
348 |
#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
|
349 |
#endif |
9ea6bbfe0b83
8009575: Reduce Symbol::_refcount from 4 bytes to 2 bytes
iklam
parents:
15803
diff
changeset
|
350 |
|
46993
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
351 |
template<typename I, typename D> |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
352 |
inline D Atomic::add(I add_value, D volatile* dest) { |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
353 |
return AddImpl<I, D>()(add_value, dest); |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
354 |
} |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
355 |
|
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
356 |
template<typename I, typename D> |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
357 |
struct Atomic::AddImpl< |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
358 |
I, D, |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
359 |
typename EnableIf<IsIntegral<I>::value && |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
360 |
IsIntegral<D>::value && |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
361 |
(sizeof(I) <= sizeof(D)) && |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
362 |
(IsSigned<I>::value == IsSigned<D>::value)>::type> |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
363 |
VALUE_OBJ_CLASS_SPEC |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
364 |
{ |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
365 |
D operator()(I add_value, D volatile* dest) const { |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
366 |
D addend = add_value; |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
367 |
return PlatformAdd<sizeof(D)>()(addend, dest); |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
368 |
} |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
369 |
}; |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
370 |
|
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
371 |
template<typename I, typename P> |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
372 |
struct Atomic::AddImpl< |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
373 |
I, P*, |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
374 |
typename EnableIf<IsIntegral<I>::value && (sizeof(I) <= sizeof(P*))>::type> |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
375 |
VALUE_OBJ_CLASS_SPEC |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
376 |
{ |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
377 |
P* operator()(I add_value, P* volatile* dest) const { |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
378 |
STATIC_ASSERT(sizeof(intptr_t) == sizeof(P*)); |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
379 |
STATIC_ASSERT(sizeof(uintptr_t) == sizeof(P*)); |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
380 |
typedef typename Conditional<IsSigned<I>::value, |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
381 |
intptr_t, |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
382 |
uintptr_t>::type CI; |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
383 |
CI addend = add_value; |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
384 |
return PlatformAdd<sizeof(P*)>()(addend, dest); |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
385 |
} |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
386 |
}; |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
387 |
|
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
388 |
// Most platforms do not support atomic add on a 2-byte value. However, |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
389 |
// if the value occupies the most significant 16 bits of an aligned 32-bit |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
390 |
// word, then we can do this with an atomic add of (add_value << 16) |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
391 |
// to the 32-bit word. |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
392 |
// |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
393 |
// The least significant parts of this 32-bit word will never be affected, even |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
394 |
// in case of overflow/underflow. |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
395 |
// |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
396 |
// Use the ATOMIC_SHORT_PAIR macro (see macros.hpp) to get the desired alignment. |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
397 |
template<> |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
398 |
struct Atomic::AddImpl<jshort, jshort> VALUE_OBJ_CLASS_SPEC { |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
399 |
jshort operator()(jshort add_value, jshort volatile* dest) const { |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
400 |
#ifdef VM_LITTLE_ENDIAN |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
401 |
assert((intx(dest) & 0x03) == 0x02, "wrong alignment"); |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
402 |
jint new_value = Atomic::add(add_value << 16, (volatile jint*)(dest-1)); |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
403 |
#else |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
404 |
assert((intx(dest) & 0x03) == 0x00, "wrong alignment"); |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
405 |
jint new_value = Atomic::add(add_value << 16, (volatile jint*)(dest)); |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
406 |
#endif |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
407 |
return (jshort)(new_value >> 16); // preserves sign |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
408 |
} |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
409 |
}; |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
410 |
|
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
411 |
template<typename Derived> |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
412 |
template<typename I, typename D> |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
413 |
inline D Atomic::FetchAndAdd<Derived>::operator()(I add_value, D volatile* dest) const { |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
414 |
I addend = add_value; |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
415 |
// If D is a pointer type P*, scale by sizeof(P). |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
416 |
if (IsPointer<D>::value) { |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
417 |
addend *= sizeof(typename RemovePointer<D>::type); |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
418 |
} |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
419 |
D old = static_cast<const Derived*>(this)->fetch_and_add(addend, dest); |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
420 |
return old + add_value; |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
421 |
} |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
422 |
|
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
423 |
template<typename Derived> |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
424 |
template<typename I, typename D> |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
425 |
inline D Atomic::AddAndFetch<Derived>::operator()(I add_value, D volatile* dest) const { |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
426 |
// If D is a pointer type P*, scale by sizeof(P). |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
427 |
if (IsPointer<D>::value) { |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
428 |
add_value *= sizeof(typename RemovePointer<D>::type); |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
429 |
} |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
430 |
return static_cast<const Derived*>(this)->add_and_fetch(add_value, dest); |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
431 |
} |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
432 |
|
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
433 |
template<typename Type, typename Fn, typename I, typename D> |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
434 |
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
|
435 |
return PrimitiveConversions::cast<D>( |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
436 |
fn(PrimitiveConversions::cast<Type>(add_value), |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
437 |
reinterpret_cast<Type volatile*>(dest))); |
40655
9f644073d3a0
8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents:
39404
diff
changeset
|
438 |
} |
9f644073d3a0
8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents:
39404
diff
changeset
|
439 |
|
9f644073d3a0
8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents:
39404
diff
changeset
|
440 |
inline void Atomic::inc(volatile size_t* dest) { |
9f644073d3a0
8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents:
39404
diff
changeset
|
441 |
inc_ptr((volatile intptr_t*) dest); |
9f644073d3a0
8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents:
39404
diff
changeset
|
442 |
} |
9f644073d3a0
8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents:
39404
diff
changeset
|
443 |
|
9f644073d3a0
8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents:
39404
diff
changeset
|
444 |
inline void Atomic::dec(volatile size_t* dest) { |
9f644073d3a0
8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents:
39404
diff
changeset
|
445 |
dec_ptr((volatile intptr_t*) dest); |
9f644073d3a0
8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents:
39404
diff
changeset
|
446 |
} |
9f644073d3a0
8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents:
39404
diff
changeset
|
447 |
|
46958
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
448 |
template<typename T, typename D, typename U> |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
449 |
inline D Atomic::cmpxchg(T exchange_value, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
450 |
D volatile* dest, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
451 |
U compare_value, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
452 |
cmpxchg_memory_order order) { |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
453 |
return CmpxchgImpl<T, D, U>()(exchange_value, dest, compare_value, order); |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
454 |
} |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
455 |
|
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
456 |
template<typename T, typename D> |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
457 |
inline bool Atomic::replace_if_null(T* value, D* volatile* dest, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
458 |
cmpxchg_memory_order order) { |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
459 |
// Presently using a trivial implementation in terms of cmpxchg. |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
460 |
// Consider adding platform support, to permit the use of compiler |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
461 |
// intrinsics like gcc's __sync_bool_compare_and_swap. |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
462 |
D* expected_null = NULL; |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
463 |
return expected_null == cmpxchg(value, dest, expected_null, order); |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
464 |
} |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
465 |
|
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
466 |
// Handle cmpxchg for integral and enum types. |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
467 |
// |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
468 |
// All the involved types must be identical. |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
469 |
template<typename T> |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
470 |
struct Atomic::CmpxchgImpl< |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
471 |
T, T, T, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
472 |
typename EnableIf<IsIntegral<T>::value || IsRegisteredEnum<T>::value>::type> |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
473 |
VALUE_OBJ_CLASS_SPEC |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
474 |
{ |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
475 |
T operator()(T exchange_value, T volatile* dest, T compare_value, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
476 |
cmpxchg_memory_order order) const { |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
477 |
// Forward to the platform handler for the size of T. |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
478 |
return PlatformCmpxchg<sizeof(T)>()(exchange_value, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
479 |
dest, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
480 |
compare_value, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
481 |
order); |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
482 |
} |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
483 |
}; |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
484 |
|
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
485 |
// Handle cmpxchg for pointer types. |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
486 |
// |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
487 |
// 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
|
488 |
// ignoring cv-qualifiers; we don't care about the cv-qualifiers of |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
489 |
// the compare_value. |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
490 |
// |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
491 |
// The exchange_value must be implicitly convertible to the |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
492 |
// destination's type; it must be type-correct to store the |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
493 |
// exchange_value in the destination. |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
494 |
template<typename T, typename D, typename U> |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
495 |
struct Atomic::CmpxchgImpl< |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
496 |
T*, D*, U*, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
497 |
typename EnableIf<Atomic::IsPointerConvertible<T*, D*>::value && |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
498 |
IsSame<typename RemoveCV<D>::type, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
499 |
typename RemoveCV<U>::type>::value>::type> |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
500 |
VALUE_OBJ_CLASS_SPEC |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
501 |
{ |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
502 |
D* operator()(T* exchange_value, D* volatile* dest, U* compare_value, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
503 |
cmpxchg_memory_order order) const { |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
504 |
// Allow derived to base conversion, and adding cv-qualifiers. |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
505 |
D* new_value = exchange_value; |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
506 |
// Don't care what the CV qualifiers for compare_value are, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
507 |
// but we need to match D* when calling platform support. |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
508 |
D* old_value = const_cast<D*>(compare_value); |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
509 |
return PlatformCmpxchg<sizeof(D*)>()(new_value, dest, old_value, order); |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
510 |
} |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
511 |
}; |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
512 |
|
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
513 |
// Handle cmpxchg for types that have a translator. |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
514 |
// |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
515 |
// All the involved types must be identical. |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
516 |
// |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
517 |
// This translates the original call into a call on the decayed |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
518 |
// arguments, and returns the recovered result of that translated |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
519 |
// call. |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
520 |
template<typename T> |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
521 |
struct Atomic::CmpxchgImpl< |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
522 |
T, T, T, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
523 |
typename EnableIf<PrimitiveConversions::Translate<T>::value>::type> |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
524 |
VALUE_OBJ_CLASS_SPEC |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
525 |
{ |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
526 |
T operator()(T exchange_value, T volatile* dest, T compare_value, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
527 |
cmpxchg_memory_order order) const { |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
528 |
typedef PrimitiveConversions::Translate<T> Translator; |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
529 |
typedef typename Translator::Decayed Decayed; |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
530 |
STATIC_ASSERT(sizeof(T) == sizeof(Decayed)); |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
531 |
return Translator::recover( |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
532 |
cmpxchg(Translator::decay(exchange_value), |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
533 |
reinterpret_cast<Decayed volatile*>(dest), |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
534 |
Translator::decay(compare_value), |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
535 |
order)); |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
536 |
} |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
537 |
}; |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
538 |
|
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
539 |
template<typename Type, typename Fn, typename T> |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
540 |
inline T Atomic::cmpxchg_using_helper(Fn fn, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
541 |
T exchange_value, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
542 |
T volatile* dest, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
543 |
T compare_value) { |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
544 |
STATIC_ASSERT(sizeof(Type) == sizeof(T)); |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
545 |
return PrimitiveConversions::cast<T>( |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
546 |
fn(PrimitiveConversions::cast<Type>(exchange_value), |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
547 |
reinterpret_cast<Type volatile*>(dest), |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
548 |
PrimitiveConversions::cast<Type>(compare_value))); |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
549 |
} |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
550 |
|
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
551 |
template<typename T> |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
552 |
inline T Atomic::CmpxchgByteUsingInt::operator()(T exchange_value, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
553 |
T volatile* dest, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
554 |
T compare_value, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
555 |
cmpxchg_memory_order order) const { |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
556 |
STATIC_ASSERT(sizeof(T) == sizeof(uint8_t)); |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
557 |
uint8_t canon_exchange_value = exchange_value; |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
558 |
uint8_t canon_compare_value = compare_value; |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
559 |
volatile uint32_t* aligned_dest |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
560 |
= reinterpret_cast<volatile uint32_t*>(align_down(dest, sizeof(uint32_t))); |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
561 |
size_t offset = pointer_delta(dest, aligned_dest, 1); |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
562 |
uint32_t cur = *aligned_dest; |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
563 |
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
|
564 |
|
252f9d8272af
8157904: Atomic::cmpxchg for jbyte is missing a fence on initial failure
dholmes
parents:
40655
diff
changeset
|
565 |
// 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
|
566 |
// 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
|
567 |
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
|
568 |
|
252f9d8272af
8157904: Atomic::cmpxchg for jbyte is missing a fence on initial failure
dholmes
parents:
40655
diff
changeset
|
569 |
// 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
|
570 |
// barriers even on initial failure |
252f9d8272af
8157904: Atomic::cmpxchg for jbyte is missing a fence on initial failure
dholmes
parents:
40655
diff
changeset
|
571 |
do { |
252f9d8272af
8157904: Atomic::cmpxchg for jbyte is missing a fence on initial failure
dholmes
parents:
40655
diff
changeset
|
572 |
// value to swap in matches current value ... |
46958
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
573 |
uint32_t new_value = cur; |
40669
252f9d8272af
8157904: Atomic::cmpxchg for jbyte is missing a fence on initial failure
dholmes
parents:
40655
diff
changeset
|
574 |
// ... except for the one jbyte we want to update |
46958
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
575 |
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
|
576 |
|
46958
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
577 |
uint32_t res = cmpxchg(new_value, aligned_dest, cur, order); |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
578 |
if (res == cur) break; // success |
40669
252f9d8272af
8157904: Atomic::cmpxchg for jbyte is missing a fence on initial failure
dholmes
parents:
40655
diff
changeset
|
579 |
|
46958
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
580 |
// at least one byte in the int changed value, so update |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
581 |
// our view of the current int |
40655
9f644073d3a0
8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents:
39404
diff
changeset
|
582 |
cur = res; |
46958
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
583 |
// if our byte is still as cur we loop and try again |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
584 |
} 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
|
585 |
|
46958
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46625
diff
changeset
|
586 |
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
|
587 |
} |
40669
252f9d8272af
8157904: Atomic::cmpxchg for jbyte is missing a fence on initial failure
dholmes
parents:
40655
diff
changeset
|
588 |
|
40655
9f644073d3a0
8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents:
39404
diff
changeset
|
589 |
inline unsigned Atomic::xchg(unsigned int exchange_value, volatile unsigned int* dest) { |
9f644073d3a0
8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents:
39404
diff
changeset
|
590 |
assert(sizeof(unsigned int) == sizeof(jint), "more work to do"); |
9f644073d3a0
8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents:
39404
diff
changeset
|
591 |
return (unsigned int)Atomic::xchg((jint)exchange_value, (volatile jint*)dest); |
9f644073d3a0
8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents:
39404
diff
changeset
|
592 |
} |
9f644073d3a0
8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents:
39404
diff
changeset
|
593 |
|
40860
34163901ad5f
8161280: assert failed: reference count underflow for symbol
iklam
parents:
40669
diff
changeset
|
594 |
inline void Atomic::inc(volatile jshort* dest) { |
46993
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
595 |
(void)add(jshort(1), dest); |
40860
34163901ad5f
8161280: assert failed: reference count underflow for symbol
iklam
parents:
40669
diff
changeset
|
596 |
} |
34163901ad5f
8161280: assert failed: reference count underflow for symbol
iklam
parents:
40669
diff
changeset
|
597 |
|
34163901ad5f
8161280: assert failed: reference count underflow for symbol
iklam
parents:
40669
diff
changeset
|
598 |
inline void Atomic::dec(volatile jshort* dest) { |
46993
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
599 |
(void)add(jshort(-1), dest); |
40655
9f644073d3a0
8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents:
39404
diff
changeset
|
600 |
} |
9f644073d3a0
8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents:
39404
diff
changeset
|
601 |
|
7397 | 602 |
#endif // SHARE_VM_RUNTIME_ATOMIC_HPP |