tog-pegasus/pegasus-2.12.1-atomic-operations-on-arm.patch

82 lines
2.2 KiB
Diff
Raw Normal View History

2013-05-07 10:30:00 +00:00
Index: src/Pegasus/Common/AtomicInt.h
===================================================================
RCS file: /cvs/MSB/pegasus/src/Pegasus/Common/AtomicInt.h,v
retrieving revision 1.23
diff -u -r1.23 AtomicInt.h
--- src/Pegasus/Common/AtomicInt.h 30 Jul 2012 09:23:47 -0000 1.23
+++ src/Pegasus/Common/AtomicInt.h 30 Apr 2013 14:04:53 -0000
@@ -95,6 +95,64 @@
PEGASUS_NAMESPACE_END
+// if GNU GCC version >= 4.7.0, use the built-in atomic operations
+#if defined(GCC_VERSION) && GCC_VERSION >= 40700
+# define PEGASUS_ATOMIC_INT_DEFINED
+
+PEGASUS_NAMESPACE_BEGIN
+
+struct AtomicType
+{
+ volatile int n;
+};
+
+PEGASUS_TEMPLATE_SPECIALIZATION
+inline AtomicIntTemplate<AtomicType>::AtomicIntTemplate(Uint32 n)
+{
+ __atomic_store_n (&_rep.n, n, __ATOMIC_SEQ_CST);
+}
+
+PEGASUS_TEMPLATE_SPECIALIZATION
+inline AtomicIntTemplate<AtomicType>::~AtomicIntTemplate()
+{
+}
+
+PEGASUS_TEMPLATE_SPECIALIZATION
+inline Uint32 AtomicIntTemplate<AtomicType>::get() const
+{
+ return __atomic_load_n (&_rep.n, __ATOMIC_SEQ_CST);
+}
+
+PEGASUS_TEMPLATE_SPECIALIZATION
+inline void AtomicIntTemplate<AtomicType>::set(Uint32 n)
+{
+ __atomic_store_n (&_rep.n, n, __ATOMIC_SEQ_CST);
+}
+
+PEGASUS_TEMPLATE_SPECIALIZATION
+inline void AtomicIntTemplate<AtomicType>::inc()
+{
+ __atomic_fetch_add (&_rep.n, 1, __ATOMIC_SEQ_CST);
+}
+
+PEGASUS_TEMPLATE_SPECIALIZATION
+inline void AtomicIntTemplate<AtomicType>::dec()
+{
+ __atomic_fetch_sub (&_rep.n, 1, __ATOMIC_SEQ_CST);
+}
+
+PEGASUS_TEMPLATE_SPECIALIZATION
+inline bool AtomicIntTemplate<AtomicType>::decAndTestIfZero()
+{
+ return (__atomic_fetch_sub (&_rep.n, 1, __ATOMIC_SEQ_CST) == 1);
+}
+
+typedef AtomicIntTemplate<AtomicType> AtomicInt;
+
+PEGASUS_NAMESPACE_END
+
+#else //!(GCC_VERSION && GCC_VERSION >= 40700), use platform specific atomics
+
//==============================================================================
//
// PEGASUS_PLATFORM_LINUX_IX86_GNU
@@ -1056,6 +1114,8 @@
#endif /* PEGASUS_PLATFORM_AIX_RS_IBMCXX, \
PEGASUS_PLATFORM_PASE_ISERIES_IBMCXX */
+#endif /* GCC_VERSION && GCC_VERSION >= 40700 */
+
//==============================================================================
//
// Generic Implementation