BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bsls_atomicoperations_arm32_win_msvc.h
Go to the documentation of this file.
1/// @file bsls_atomicoperations_arm32_win_msvc.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bsls_atomicoperations_arm32_win_msvc.h -*-C++-*-
8#ifndef INCLUDED_BSLS_ATOMICOPERATIONS_ARM32_WIN_MSVC
9#define INCLUDED_BSLS_ATOMICOPERATIONS_ARM32_WIN_MSVC
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bsls_atomicoperations_arm32_win_msvc bsls_atomicoperations_arm32_win_msvc
15/// @brief Provide implementations of atomic operations for arm32/MSVC/Win.
16/// @addtogroup bsl
17/// @{
18/// @addtogroup bsls
19/// @{
20/// @addtogroup bsls_atomicoperations_arm32_win_msvc
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bsls_atomicoperations_arm32_win_msvc-purpose"> Purpose</a>
25/// * <a href="#bsls_atomicoperations_arm32_win_msvc-classes"> Classes </a>
26/// * <a href="#bsls_atomicoperations_arm32_win_msvc-description"> Description </a>
27///
28/// # Purpose {#bsls_atomicoperations_arm32_win_msvc-purpose}
29/// Provide implementations of atomic operations for arm32/MSVC/Win.
30///
31/// # Classes {#bsls_atomicoperations_arm32_win_msvc-classes}
32///
33/// - bsls::AtomicOperations_ARM32_WIN_MSVC: atomics for arm32/MSVC/Windows
34///
35/// # Description {#bsls_atomicoperations_arm32_win_msvc-description}
36/// This component provides classes necessary to implement atomics
37/// on the Windows platform with MSVC compiler for ARM CPUs. The classes are
38/// for private use only. See @ref bsls_atomicoperations and @ref bsls_atomic for
39/// the public interface to atomics.
40/// @}
41/** @} */
42/** @} */
43
44/** @addtogroup bsl
45 * @{
46 */
47/** @addtogroup bsls
48 * @{
49 */
50/** @addtogroup bsls_atomicoperations_arm32_win_msvc
51 * @{
52 */
53
54#include <bsls_atomicoperations_default.h>
55#include <bsls_platform.h>
56#include <bsls_types.h>
57
58#if defined(BSLS_PLATFORM_CPU_ARM) && defined(BSLS_PLATFORM_CPU_32_BIT) && \
59 defined(BSLS_PLATFORM_CMP_MSVC)
60#include <intrin.h>
61
62
63
64namespace bsls {
65
66struct AtomicOperations_ARM32_WIN_MSVC;
67typedef AtomicOperations_ARM32_WIN_MSVC AtomicOperations_Imp;
68
69 // =========================================================
70 // struct Atomic_TypeTraits<AtomicOperations_ARM32_WIN_MSVC>
71 // =========================================================
72
73template<>
74struct Atomic_TypeTraits<AtomicOperations_ARM32_WIN_MSVC>
75{
76 struct Int
77 {
78 __declspec(align(4))
79 volatile int d_value;
80 };
81
82 struct Int64
83 {
84 __declspec(align(8))
85 volatile Types::Int64 d_value;
86 };
87
88 struct Uint
89 {
90 __declspec(align(4))
91 volatile unsigned int d_value;
92 };
93
94 struct Uint64
95 {
96 __declspec(align(8))
97 volatile Types::Uint64 d_value;
98 };
99
100 struct Pointer
101 {
102 __declspec(align(4))
103 void * volatile d_value;
104 };
105};
106
107 // ======================================
108 // struct AtomicOperations_ARM32_WIN_MSVC
109 // ======================================
110
111struct AtomicOperations_ARM32_WIN_MSVC
112 : AtomicOperations_Default32<AtomicOperations_ARM32_WIN_MSVC>
113{
114 typedef Atomic_TypeTraits<AtomicOperations_ARM32_WIN_MSVC> AtomicTypes;
115
116 // *** atomic functions for int ***
117
118 static int getInt(const AtomicTypes::Int *atomicInt);
119
120 static int getIntAcquire(const AtomicTypes::Int *atomicInt);
121
122 static void setInt(AtomicTypes::Int *atomicInt, int value);
123
124 static void setIntRelease(AtomicTypes::Int *atomicInt, int value);
125
126 static int swapInt(AtomicTypes::Int *atomicInt, int swapValue);
127
128 static int testAndSwapInt(AtomicTypes::Int *atomicInt,
129 int compareValue,
130 int swapValue);
131
132 static int addIntNv(AtomicTypes::Int *atomicInt, int value);
133
134 // *** atomic functions for Int64 ***
135
136 static Types::Int64 getInt64(const AtomicTypes::Int64 *atomicInt);
137
138 static void setInt64(AtomicTypes::Int64 *atomicInt, Types::Int64 value);
139
140 static Types::Int64 swapInt64(AtomicTypes::Int64 *atomicInt,
141 Types::Int64 swapValue);
142
143 static Types::Int64 testAndSwapInt64(AtomicTypes::Int64 *atomicInt,
144 Types::Int64 compareValue,
145 Types::Int64 swapValue);
146
147 static Types::Int64 addInt64Nv(AtomicTypes::Int64 *atomicInt,
148 Types::Int64 value);
149};
150
151// ===========================================================================
152// INLINE FUNCTION DEFINITIONS
153// ===========================================================================
154
155 // --------------------------------------
156 // struct AtomicOperations_ARM32_WIN_MSVC
157 // --------------------------------------
158
159// Memory barrier for atomic operations with sequential consistency.
160#define BSLS_ATOMIC_FENCE() \
161 __dmb(_ARM_BARRIER_ISH)
162
163inline
164int AtomicOperations_ARM32_WIN_MSVC::
165 getInt(const AtomicTypes::Int *atomicInt)
166{
167 int result = __iso_volatile_load32(&atomicInt->d_value);
168 BSLS_ATOMIC_FENCE();
169 return result;
170}
171
172inline
173int AtomicOperations_ARM32_WIN_MSVC::
174 getIntAcquire(const AtomicTypes::Int *atomicInt)
175{
176 int result = __iso_volatile_load32(&atomicInt->d_value);
177 BSLS_ATOMIC_FENCE();
178 return result;
179}
180
181inline
182void AtomicOperations_ARM32_WIN_MSVC::
183 setInt(AtomicTypes::Int *atomicInt, int value)
184{
185 BSLS_ATOMIC_FENCE();
186 __iso_volatile_store32(&atomicInt->d_value, value);
187 BSLS_ATOMIC_FENCE();
188}
189
190inline
191void AtomicOperations_ARM32_WIN_MSVC::
192 setIntRelease(AtomicTypes::Int *atomicInt, int value)
193{
194 BSLS_ATOMIC_FENCE();
195 __iso_volatile_store32(&atomicInt->d_value, value);
196}
197
198inline
199int AtomicOperations_ARM32_WIN_MSVC::
200 swapInt(AtomicTypes::Int *atomicInt, int swapValue)
201{
202 return _InterlockedExchange(
203 reinterpret_cast<long volatile *>(&atomicInt->d_value),
204 swapValue);
205}
206
207inline
208int AtomicOperations_ARM32_WIN_MSVC::
209 testAndSwapInt(AtomicTypes::Int *atomicInt,
210 int compareValue,
211 int swapValue)
212{
213 return _InterlockedCompareExchange(
214 reinterpret_cast<long volatile *>(&atomicInt->d_value),
215 swapValue,
216 compareValue);
217}
218
219inline
220int AtomicOperations_ARM32_WIN_MSVC::
221 addIntNv(AtomicTypes::Int *atomicInt, int value)
222{
223 return static_cast<int>(
224 static_cast<unsigned int>(_InterlockedExchangeAdd(
225 reinterpret_cast<long volatile *>(&atomicInt->d_value),
226 value)) +
227 value);
228}
229 // *** atomic functions for Int64 ***
230
231inline
232Types::Int64 AtomicOperations_ARM32_WIN_MSVC::
233 getInt64(const AtomicTypes::Int64 *atomicInt)
234{
235 Types::Int64 result = __iso_volatile_load64(&atomicInt->d_value);
236 BSLS_ATOMIC_FENCE();
237 return result;
238}
239
240inline
241void AtomicOperations_ARM32_WIN_MSVC::
242 setInt64(AtomicTypes::Int64 *atomicInt, Types::Int64 value)
243{
244 BSLS_ATOMIC_FENCE();
245 __iso_volatile_store64(&atomicInt->d_value, value);
246 BSLS_ATOMIC_FENCE();
247}
248
249inline
250Types::Int64 AtomicOperations_ARM32_WIN_MSVC::
251 swapInt64(AtomicTypes::Int64 *atomicInt,
252 Types::Int64 swapValue)
253{
254 return _InterlockedExchange64(
255 &atomicInt->d_value,
256 swapValue);
257}
258
259inline
260Types::Int64 AtomicOperations_ARM32_WIN_MSVC::
261 testAndSwapInt64(AtomicTypes::Int64 *atomicInt,
262 Types::Int64 compareValue,
263 Types::Int64 swapValue)
264{
265 return _InterlockedCompareExchange64(
266 &atomicInt->d_value,
267 swapValue,
268 compareValue);
269}
270
271inline
272Types::Int64 AtomicOperations_ARM32_WIN_MSVC::
273 addInt64Nv(AtomicTypes::Int64 *atomicInt,
274 Types::Int64 value)
275{
276 return static_cast<Types::Int64>(
277 static_cast<Types::Uint64>(
278 _InterlockedExchangeAdd64(&atomicInt->d_value, value)) +
279 value);
280
281}
282
283#undef BSLS_ATOMIC_FENCE
284
285} // close package namespace
286
287
288
289#endif // arm32 && MSVC
290
291#endif
292
293// ----------------------------------------------------------------------------
294// Copyright 2024 Bloomberg Finance L.P.
295//
296// Licensed under the Apache License, Version 2.0 (the "License");
297// you may not use this file except in compliance with the License.
298// You may obtain a copy of the License at
299//
300// http://www.apache.org/licenses/LICENSE-2.0
301//
302// Unless required by applicable law or agreed to in writing, software
303// distributed under the License is distributed on an "AS IS" BASIS,
304// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
305// See the License for the specific language governing permissions and
306// limitations under the License.
307// ----------------------------- END-OF-FILE ----------------------------------
308
309/** @} */
310/** @} */
311/** @} */
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition bdlt_iso8601util.h:691