9
9
10
10
#include "numpy/npy_common.h"
11
11
12
- #if defined(__STDC_VERSION__ ) && __STDC_VERSION__ >= 201112L \
12
+ #ifdef __cplusplus
13
+ extern "C++" {
14
+ #include <atomic>
15
+ }
16
+ #define _NPY_USING_STD using namespace std
17
+ #define _Atomic (tp ) atomic<tp>
18
+ #define STDC_ATOMICS
19
+ #elif defined(__STDC_VERSION__ ) && __STDC_VERSION__ >= 201112L \
13
20
&& !defined(__STDC_NO_ATOMICS__ )
14
- // TODO: support C++ atomics as well if this header is ever needed in C++
15
21
#include <stdatomic.h>
16
22
#include <stdint.h>
23
+ #define _NPY_USING_STD
17
24
#define STDC_ATOMICS
18
25
#elif _MSC_VER
19
26
#include <intrin.h>
35
42
static inline npy_uint8
36
43
npy_atomic_load_uint8 (const npy_uint8 * obj ) {
37
44
#ifdef STDC_ATOMICS
45
+ _NPY_USING_STD ;
38
46
return (npy_uint8 )atomic_load ((const _Atomic (uint8_t )* )obj );
39
47
#elif defined(MSC_ATOMICS )
40
48
#if defined(_M_X64 ) || defined(_M_IX86 )
@@ -50,6 +58,7 @@ npy_atomic_load_uint8(const npy_uint8 *obj) {
50
58
static inline void *
51
59
npy_atomic_load_ptr (const void * obj ) {
52
60
#ifdef STDC_ATOMICS
61
+ _NPY_USING_STD ;
53
62
return atomic_load ((const _Atomic (void * )* )obj );
54
63
#elif defined(MSC_ATOMICS )
55
64
#if SIZEOF_VOID_P == 8
@@ -73,6 +82,7 @@ npy_atomic_load_ptr(const void *obj) {
73
82
static inline void
74
83
npy_atomic_store_uint8 (npy_uint8 * obj , npy_uint8 value ) {
75
84
#ifdef STDC_ATOMICS
85
+ _NPY_USING_STD ;
76
86
atomic_store ((_Atomic (uint8_t )* )obj , value );
77
87
#elif defined(MSC_ATOMICS )
78
88
_InterlockedExchange8 ((volatile char * )obj , (char )value );
@@ -85,6 +95,7 @@ static inline void
85
95
npy_atomic_store_ptr (void * obj , void * value )
86
96
{
87
97
#ifdef STDC_ATOMICS
98
+ _NPY_USING_STD ;
88
99
atomic_store ((_Atomic (void * )* )obj , value );
89
100
#elif defined(MSC_ATOMICS )
90
101
_InterlockedExchangePointer ((void * volatile * )obj , (void * )value );
0 commit comments