Lines 1-17
Link Here
|
|
|
1 |
Move vlc_atomic.h closer to the git version (post-2.2.4), especially revision |
2 |
ab550d60dd8d8 ("include: stick to a single version (2011) C/C++ atomics") by |
3 |
assuming C++ builds are being done in C++11 mode or later and include <atomic>. |
4 |
For C usages, use <stdatomic.h> in C11 mode and define some shims otherwise. |
5 |
|
6 |
The original 2.2.4 version does not have C++11 support and breaks with Qt5, as |
7 |
Qt 5.7+ requires C++11 support. |
1 |
--- include/vlc_atomic.h.orig 2014-08-14 07:20:03 UTC |
8 |
--- include/vlc_atomic.h.orig 2014-08-14 07:20:03 UTC |
2 |
+++ include/vlc_atomic.h |
9 |
+++ include/vlc_atomic.h |
3 |
@@ -32,6 +32,14 @@ |
10 |
@@ -26,13 +26,13 @@ |
|
|
11 |
* Atomic operations do not require locking, but they are not very powerful. |
12 |
*/ |
13 |
|
14 |
-# if !defined (__cplusplus) && (__STDC_VERSION__ >= 201112L) \ |
15 |
- && !defined (__STDC_NO_ATOMICS__) |
16 |
+# ifndef __cplusplus |
17 |
+# if (__STDC_VERSION__ >= 201112L) && !defined (__STDC_NO_ATOMICS__) |
18 |
|
4 |
/*** Native C11 atomics ***/ |
19 |
/*** Native C11 atomics ***/ |
5 |
# include <stdatomic.h> |
20 |
# include <stdatomic.h> |
6 |
|
21 |
|
7 |
+# elif defined (__cplusplus) && defined(_LIBCPP_VERSION) && _LIBCPP_VERSION >= 3800 |
22 |
-# else |
8 |
+ |
23 |
+# else |
|
|
24 |
|
25 |
# define ATOMIC_FLAG_INIT false |
26 |
|
27 |
@@ -57,7 +57,7 @@ |
28 |
* unsigned equivalents, i.e. 4-bytes and 8-bytes types, although GCC also |
29 |
* supports 1 and 2-bytes types. Some non-x86 architectures do not support |
30 |
* 8-byte atomic types (or not efficiently). */ |
31 |
-# if defined (_MSC_VER) |
32 |
+# if defined (_MSC_VER) |
33 |
/* Some atomic operations of the Interlocked API are only |
34 |
available for desktop apps. Thus we define the atomic types to |
35 |
be at least 32 bits wide. */ |
36 |
@@ -68,7 +68,7 @@ |
37 |
typedef uint_least32_t atomic_uchar; |
38 |
typedef int_least32_t atomic_short; |
39 |
typedef uint_least32_t atomic_ushort; |
40 |
-# else |
41 |
+# else |
42 |
typedef bool atomic_flag; |
43 |
typedef bool atomic_bool; |
44 |
typedef char atomic_char; |
45 |
@@ -76,7 +76,7 @@ |
46 |
typedef unsigned char atomic_uchar; |
47 |
typedef short atomic_short; |
48 |
typedef unsigned short atomic_ushort; |
49 |
-# endif |
50 |
+# endif |
51 |
typedef int atomic_int; |
52 |
typedef unsigned int atomic_uint; |
53 |
typedef long atomic_long; |
54 |
@@ -109,7 +109,7 @@ |
55 |
typedef intmax_t atomic_intmax_t; |
56 |
typedef uintmax_t atomic_uintmax_t; |
57 |
|
58 |
-# if defined (__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4) || (defined (__clang__) && (defined (__x86_64__) || defined (__i386__))) |
59 |
+# if defined (__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4) || (defined (__clang__) && (defined (__x86_64__) || defined (__i386__))) |
60 |
|
61 |
/*** Intel/GCC atomics ***/ |
62 |
|
63 |
@@ -203,7 +203,7 @@ |
64 |
# define atomic_flag_clear_explicit(object,order) \ |
65 |
atomic_flag_clear(object) |
66 |
|
67 |
-# elif defined (__GNUC__) |
68 |
+# elif defined (__GNUC__) |
69 |
|
70 |
/*** No atomics ***/ |
71 |
|
72 |
@@ -315,7 +315,7 @@ |
73 |
# define atomic_flag_clear_explicit(object,order) \ |
74 |
atomic_flag_clear(object) |
75 |
|
76 |
-# elif defined (_MSC_VER) |
77 |
+# elif defined (_MSC_VER) |
78 |
|
79 |
# include <windows.h> |
80 |
|
81 |
@@ -397,10 +397,8 @@ |
82 |
# define atomic_flag_clear_explicit(object,order) \ |
83 |
atomic_flag_clear(object) |
84 |
|
85 |
-# else |
86 |
-# error FIXME: implement atomic operations for this compiler. |
87 |
-# endif |
88 |
-# endif |
89 |
+# endif |
90 |
+# endif |
91 |
|
92 |
typedef atomic_uint_least32_t vlc_atomic_float; |
93 |
|
94 |
@@ -427,4 +425,9 @@ |
95 |
atomic_store(atom, u.i); |
96 |
} |
97 |
|
98 |
+# else /* C++ */ |
99 |
+/*** Native C++11 atomics ***/ |
9 |
+# include <atomic> |
100 |
+# include <atomic> |
|
|
101 |
+# endif |
10 |
+ |
102 |
+ |
11 |
+using std::atomic_uint_least32_t; |
103 |
#endif |
12 |
+using std::atomic_uintptr_t; |
|
|
13 |
+using std::atomic_int; |
14 |
+ |
15 |
# else |
16 |
|
17 |
# define ATOMIC_FLAG_INIT false |