60 #error "this stdatomic.h does not support your compiler" 61 #endif // !defined(_WIN32) 63 #ifndef RCUTILS__STDATOMIC_HELPER__WIN32__STDATOMIC_H_ 64 #define RCUTILS__STDATOMIC_HELPER__WIN32__STDATOMIC_H_ 75 #define _Atomic(T) struct { T __val; } 81 #define ATOMIC_VAR_INIT(value) {.__val = (value)} 82 #define atomic_init(obj, value) do { \ 83 (obj)->__val = (value); \ 92 #ifndef __ATOMIC_RELAXED 93 #define __ATOMIC_RELAXED 0 95 #ifndef __ATOMIC_CONSUME 96 #define __ATOMIC_CONSUME 1 98 #ifndef __ATOMIC_ACQUIRE 99 #define __ATOMIC_ACQUIRE 2 101 #ifndef __ATOMIC_RELEASE 102 #define __ATOMIC_RELEASE 3 104 #ifndef __ATOMIC_ACQ_REL 105 #define __ATOMIC_ACQ_REL 4 107 #ifndef __ATOMIC_SEQ_CST 108 #define __ATOMIC_SEQ_CST 5 134 #define atomic_thread_fence(order) MemoryBarrier() 135 #define atomic_signal_fence(order) _ReadWriteBarrier() 141 #define atomic_is_lock_free(obj) (sizeof((obj)->__val) <= sizeof(void *)) 147 typedef _Atomic (_Bool) atomic_bool;
148 typedef _Atomic (
char) atomic_char;
149 typedef _Atomic (
signed char) atomic_schar;
150 typedef _Atomic (
unsigned char) atomic_uchar;
151 typedef _Atomic (
short) atomic_short;
152 typedef _Atomic (
unsigned short) atomic_ushort;
153 typedef _Atomic (
int) atomic_int;
154 typedef _Atomic (
unsigned int) atomic_uint;
155 typedef _Atomic (
long) atomic_long;
156 typedef _Atomic (
unsigned long) atomic_ulong;
157 typedef _Atomic (
long long) atomic_llong;
158 typedef _Atomic (
unsigned long long) atomic_ullong;
160 typedef _Atomic (char16_t) atomic_char16_t;
161 typedef _Atomic (char32_t) atomic_char32_t;
162 typedef _Atomic (
wchar_t) atomic_wchar_t;
163 typedef _Atomic (int_least8_t) atomic_int_least8_t;
164 typedef _Atomic (uint_least8_t) atomic_uint_least8_t;
166 typedef _Atomic (int_least16_t) atomic_int_least16_t;
167 typedef _Atomic (uint_least16_t) atomic_uint_least16_t;
168 typedef _Atomic (int_least32_t) atomic_int_least32_t;
169 typedef _Atomic (uint_least32_t) atomic_uint_least32_t;
170 typedef _Atomic (int_least64_t) atomic_int_least64_t;
171 typedef _Atomic (uint_least64_t) atomic_uint_least64_t;
173 typedef _Atomic (int_fast8_t) atomic_int_fast8_t;
174 typedef _Atomic (uint_fast8_t) atomic_uint_fast8_t;
176 typedef _Atomic (int_fast16_t) atomic_int_fast16_t;
177 typedef _Atomic (uint_fast16_t) atomic_uint_fast16_t;
178 typedef _Atomic (int_fast32_t) atomic_int_fast32_t;
179 typedef _Atomic (uint_fast32_t) atomic_uint_fast32_t;
180 typedef _Atomic (int_fast64_t) atomic_int_fast64_t;
181 typedef _Atomic (uint_fast64_t) atomic_uint_fast64_t;
182 typedef _Atomic (intptr_t) atomic_intptr_t;
183 typedef _Atomic (uintptr_t) atomic_uintptr_t;
184 typedef _Atomic (
size_t) atomic_size_t;
185 typedef _Atomic (ptrdiff_t) atomic_ptrdiff_t;
186 typedef _Atomic (intmax_t) atomic_intmax_t;
187 typedef _Atomic (uintmax_t) atomic_uintmax_t;
193 #define rcutils_win32_atomic_compare_exchange_strong(object, out, expected, desired) \ 194 __pragma(warning(push)) \ 195 __pragma(warning(disable: 4244)) \ 197 switch (sizeof(out)) { \ 198 case sizeof(uint64_t): \ 199 out = _InterlockedCompareExchange64((LONGLONG *) object, desired, *expected); \ 201 case sizeof(uint32_t): \ 202 out = _InterlockedCompareExchange((LONG *) object, desired, *expected); \ 204 case sizeof(uint16_t): \ 205 out = _InterlockedCompareExchange16((SHORT *) object, desired, *expected); \ 207 case sizeof(uint8_t): \ 208 out = _InterlockedCompareExchange8((char *) object, desired, *expected); \ 211 RCUTILS_LOG_ERROR_NAMED( \ 212 ROS_PACKAGE_NAME, "Unsupported integer type in atomic_compare_exchange_strong"); \ 217 __pragma(warning(pop)) 219 #define rcutils_win32_atomic_compare_exchange_weak(object, out, expected, desired) \ 220 rcutils_win32_atomic_compare_exchange_strong(object, out, expected, desired) 222 #define rcutils_win32_atomic_exchange(object, out, desired) \ 223 __pragma(warning(push)) \ 224 __pragma(warning(disable: 4244)) \ 226 switch (sizeof(out)) { \ 227 case sizeof(uint64_t): \ 228 out = _InterlockedExchange64((LONGLONG *) object, desired); \ 230 case sizeof(uint32_t): \ 231 out = _InterlockedExchange((LONG *) object, desired); \ 233 case sizeof(uint16_t): \ 234 out = _InterlockedExchange16((SHORT *) object, desired); \ 236 case sizeof(uint8_t): \ 237 out = _InterlockedExchange8((char *) object, desired); \ 240 RCUTILS_LOG_ERROR_NAMED( \ 241 ROS_PACKAGE_NAME, "Unsupported integer type in atomic_exchange_strong"); \ 246 __pragma(warning(pop)) 248 #define rcutils_win32_atomic_fetch_add(object, out, operand) \ 249 __pragma(warning(push)) \ 250 __pragma(warning(disable: 4244)) \ 252 switch (sizeof(out)) { \ 253 case sizeof(uint64_t): \ 254 out = _InterlockedExchangeAdd64((LONGLONG *) object, operand); \ 256 case sizeof(uint32_t): \ 257 out = _InterlockedExchangeAdd((LONG *) object, operand); \ 259 case sizeof(uint16_t): \ 260 out = _InterlockedExchangeAdd16((SHORT *) object, operand); \ 262 case sizeof(uint8_t): \ 263 out = _InterlockedExchangeAdd8((char *) object, operand); \ 266 RCUTILS_LOG_ERROR_NAMED( \ 267 ROS_PACKAGE_NAME, "Unsupported integer type in atomic_fetch_add"); \ 272 __pragma(warning(pop)) 274 #define rcutils_win32_atomic_fetch_and(object, out, operand) \ 275 __pragma(warning(push)) \ 276 __pragma(warning(disable: 4244)) \ 278 switch (sizeof(out)) { \ 279 case sizeof(uint64_t): \ 280 out = _InterlockedAnd64((LONGLONG *) object, operand); \ 282 case sizeof(uint32_t): \ 283 out = _InterlockedAnd((LONG *) object, operand); \ 285 case sizeof(uint16_t): \ 286 out = _InterlockedAnd16((SHORT *) object, operand); \ 288 case sizeof(uint8_t): \ 289 out = _InterlockedAnd8((char *) object, operand); \ 292 RCUTILS_LOG_ERROR_NAMED( \ 293 ROS_PACKAGE_NAME, "Unsupported integer type in atomic_fetch_and"); \ 298 __pragma(warning(pop)) 300 #define rcutils_win32_atomic_fetch_or(object, out, operand) \ 301 __pragma(warning(push)) \ 302 __pragma(warning(disable: 4244)) \ 304 switch (sizeof(out)) { \ 305 case sizeof(uint64_t): \ 306 out = _InterlockedOr64((LONGLONG *) object, operand); \ 308 case sizeof(uint32_t): \ 309 out = _InterlockedOr((LONG *) object, operand); \ 311 case sizeof(uint16_t): \ 312 out = _InterlockedOr16((SHORT *) object, operand); \ 314 case sizeof(uint8_t): \ 315 out = _InterlockedOr8((char *) object, operand); \ 318 RCUTILS_LOG_ERROR_NAMED( \ 319 ROS_PACKAGE_NAME, "Unsupported integer type in atomic_fetch_or"); \ 324 __pragma(warning(pop)) 326 #define rcutils_win32_atomic_fetch_sub(object, out, operand) \ 327 rcutils_win32_atomic_fetch_add(object, out, -(operand)) 329 #define rcutils_win32_atomic_fetch_xor(object, out, operand) \ 330 __pragma(warning(push)) \ 331 __pragma(warning(disable: 4244)) \ 333 switch (sizeof(out)) { \ 334 case sizeof(uint64_t): \ 335 out = _InterlockedXor64((LONGLONG *) object, operand); \ 337 case sizeof(uint32_t): \ 338 out = _InterlockedXor((LONG *) object, operand); \ 340 case sizeof(uint16_t): \ 341 out = _InterlockedXor16((SHORT *) object, operand); \ 343 case sizeof(uint8_t): \ 344 out = _InterlockedXor8((char *) object, operand); \ 347 RCUTILS_LOG_ERROR_NAMED( \ 348 ROS_PACKAGE_NAME, "Unsupported integer type in atomic_fetch_xor"); \ 353 __pragma(warning(pop)) 355 #define rcutils_win32_atomic_load(object, out) \ 356 __pragma(warning(push)) \ 357 __pragma(warning(disable: 4244)) \ 359 switch (sizeof(out)) { \ 360 case sizeof(uint64_t): \ 361 out = _InterlockedExchangeAdd64((LONGLONG *) object, 0); \ 363 case sizeof(uint32_t): \ 364 out = _InterlockedExchangeAdd((LONG *) object, 0); \ 366 case sizeof(uint16_t): \ 367 out = _InterlockedExchangeAdd16((SHORT *) object, 0); \ 369 case sizeof(uint8_t): \ 370 out = _InterlockedExchangeAdd8((char *) object, 0); \ 373 RCUTILS_LOG_ERROR_NAMED( \ 374 ROS_PACKAGE_NAME, "Unsupported integer type in atomic_load"); \ 379 __pragma(warning(pop)) 381 #define rcutils_win32_atomic_store(object, desired) \ 384 (object)->__val = (desired); \ 406 #endif // RCUTILS__STDATOMIC_HELPER__WIN32__STDATOMIC_H_ #define __ATOMIC_SEQ_CST
Definition: stdatomic.h:108
Definition: stdatomic.h:163
Definition: stdatomic.h:164
Definition: stdatomic.h:165
Definition: stdatomic.h:166
memory_order
Definition: stdatomic.h:160
Definition: stdatomic.h:161
#define __ATOMIC_RELEASE
Definition: stdatomic.h:102
#define _Atomic(T)
Definition: stdatomic.h:75
#define __ATOMIC_ACQ_REL
Definition: stdatomic.h:105
Definition: stdatomic.h:162
#define __ATOMIC_ACQUIRE
Definition: stdatomic.h:99
#define __ATOMIC_CONSUME
Definition: stdatomic.h:96
#define __ATOMIC_RELAXED
Definition: stdatomic.h:93