summaryrefslogtreecommitdiffstats
path: root/meta-oe/recipes-support/mongodb/mongodb/0005-GCC-4.7-supports-atomic-ops-for-armv5-and-up-but-onl.patch
diff options
context:
space:
mode:
Diffstat (limited to 'meta-oe/recipes-support/mongodb/mongodb/0005-GCC-4.7-supports-atomic-ops-for-armv5-and-up-but-onl.patch')
-rw-r--r--meta-oe/recipes-support/mongodb/mongodb/0005-GCC-4.7-supports-atomic-ops-for-armv5-and-up-but-onl.patch127
1 files changed, 127 insertions, 0 deletions
diff --git a/meta-oe/recipes-support/mongodb/mongodb/0005-GCC-4.7-supports-atomic-ops-for-armv5-and-up-but-onl.patch b/meta-oe/recipes-support/mongodb/mongodb/0005-GCC-4.7-supports-atomic-ops-for-armv5-and-up-but-onl.patch
new file mode 100644
index 000000000..490d56485
--- /dev/null
+++ b/meta-oe/recipes-support/mongodb/mongodb/0005-GCC-4.7-supports-atomic-ops-for-armv5-and-up-but-onl.patch
@@ -0,0 +1,127 @@
1From e31f85e6915d4bf6ed76c5da71c235525fa4ecc3 Mon Sep 17 00:00:00 2001
2From: Koen Kooi <koen.kooi@linaro.org>
3Date: Mon, 14 Apr 2014 10:29:42 +0200
4Subject: [PATCH 5/5] GCC 4.7+ supports atomic ops for armv5 and up, but only
5 exports the functions for armv6 and up. This patch works around the linker
6 problems associated with that.
7
8Forward ported from http://pkgs.fedoraproject.org/cgit/mongodb.git/tree/mongodb-2.4.5-atomics.patch
9
10Upstream-status: pending
11---
12 src/mongo/bson/util/atomic_int.h | 26 ++++++++++++
13 src/mongo/platform/atomic_intrinsics_gcc_generic.h | 47 ++++++++++++++++++++++
14 2 files changed, 73 insertions(+)
15
16diff --git a/src/mongo/bson/util/atomic_int.h b/src/mongo/bson/util/atomic_int.h
17index 0b85363..ed02c23 100644
18--- a/src/mongo/bson/util/atomic_int.h
19+++ b/src/mongo/bson/util/atomic_int.h
20@@ -24,6 +24,10 @@
21
22 #include "mongo/platform/compiler.h"
23
24+#define GCC_VERSION (__GNUC__ * 10000 \
25+ + __GNUC_MINOR__ * 100 \
26+ + __GNUC_PATCHLEVEL__)
27+
28 namespace mongo {
29
30 /**
31@@ -72,6 +76,28 @@ namespace mongo {
32 InterlockedAdd((volatile long *)&x,by);
33 }
34 # endif
35+#elif defined(GCC_VERSION) && GCC_VERSION >= 40700
36+// in GCC version >= 4.7.0 we can use the built-in atomic operations
37+
38+ inline void AtomicUInt::set(unsigned newX) {
39+ __atomic_store_n (&x, newX, __ATOMIC_SEQ_CST);
40+ }
41+ AtomicUInt AtomicUInt::operator++() { // ++prefix
42+ return __atomic_add_fetch(&x, 1, __ATOMIC_SEQ_CST);
43+ }
44+ AtomicUInt AtomicUInt::operator++(int) { // postfix++
45+ return __atomic_fetch_add(&x, 1, __ATOMIC_SEQ_CST);
46+ }
47+ AtomicUInt AtomicUInt::operator--() { // --prefix
48+ return __atomic_add_fetch(&x, -1, __ATOMIC_SEQ_CST);
49+ }
50+ AtomicUInt AtomicUInt::operator--(int) { // postfix--
51+ return __atomic_fetch_add(&x, -1, __ATOMIC_SEQ_CST);
52+ }
53+ void AtomicUInt::signedAdd(int by) {
54+ __atomic_fetch_add(&x, by, __ATOMIC_SEQ_CST);
55+ }
56+
57 #elif defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4)
58 // this is in GCC >= 4.1
59 inline void AtomicUInt::set(unsigned newX) { __sync_synchronize(); x = newX; }
60diff --git a/src/mongo/platform/atomic_intrinsics_gcc_generic.h b/src/mongo/platform/atomic_intrinsics_gcc_generic.h
61index 64a2499..b7cc176 100644
62--- a/src/mongo/platform/atomic_intrinsics_gcc_generic.h
63+++ b/src/mongo/platform/atomic_intrinsics_gcc_generic.h
64@@ -22,8 +22,53 @@
65
66 #include <boost/utility.hpp>
67
68+#define GCC_VERSION (__GNUC__ * 10000 \
69+ + __GNUC_MINOR__ * 100 \
70+ + __GNUC_PATCHLEVEL__)
71+
72 namespace mongo {
73
74+// If GCC version >= 4.7.0, we can use the built-in atomic operations
75+#if defined(GCC_VERSION) && GCC_VERSION >= 40700
76+
77+ /**
78+ * Instantiation of AtomicIntrinsics<>.
79+ */
80+ template <typename T>
81+ class AtomicIntrinsics {
82+ public:
83+
84+ static T compareAndSwap(volatile T* dest, T expected, T newValue) {
85+ return __atomic_compare_exchange_n (dest, &expected, newValue, 0, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
86+ }
87+
88+ static T swap(volatile T* dest, T newValue) {
89+ return __atomic_exchange_n (dest, newValue, __ATOMIC_SEQ_CST);
90+ }
91+
92+ static T load(volatile const T* value) {
93+ return __atomic_load_n (value, __ATOMIC_SEQ_CST);
94+ }
95+
96+ static T loadRelaxed(volatile const T* value) {
97+ return *value;
98+ }
99+
100+ static void store(volatile T* dest, T newValue) {
101+ __atomic_store_n (dest, newValue, __ATOMIC_SEQ_CST);
102+ }
103+
104+ static T fetchAndAdd(volatile T* dest, T increment) {
105+ return __atomic_fetch_add (dest, increment, __ATOMIC_SEQ_CST);
106+ }
107+
108+ private:
109+ AtomicIntrinsics();
110+ ~AtomicIntrinsics();
111+ };
112+
113+#else // GCC version < 4.7, so we must use legacy (platform-specific) atomic operations
114+
115 /**
116 * Instantiation of AtomicIntrinsics<> for all word types T.
117 */
118@@ -67,4 +112,6 @@ namespace mongo {
119 ~AtomicIntrinsics();
120 };
121
122+#endif // GCC_VERSION >= 40700
123+
124 } // namespace mongo
125--
1261.9.0
127