Blame SOURCES/0001-Add-generic-GCC-support-for-atomic-operations.patch

628e06
From d099ec11fc8c2eb97df2bf2fbb6996066eefca46 Mon Sep 17 00:00:00 2001
628e06
From: Stanislav Ochotnicky <sochotnicky@redhat.com>
628e06
Date: Thu, 2 May 2013 10:43:47 +0200
628e06
Subject: [PATCH] Add generic GCC support for atomic operations
628e06
628e06
This is useful for architectures where no specialized code has been
628e06
written.
628e06
---
628e06
 src/google/protobuf/stubs/atomicops.h              |   2 +-
628e06
 .../stubs/atomicops_internals_generic_gcc.h        | 139 +++++++++++++++++++++
628e06
 src/google/protobuf/stubs/platform_macros.h        |  14 ++-
628e06
 3 files changed, 153 insertions(+), 2 deletions(-)
628e06
 create mode 100644 src/google/protobuf/stubs/atomicops_internals_generic_gcc.h
628e06
628e06
diff --git a/src/google/protobuf/stubs/atomicops.h b/src/google/protobuf/stubs/atomicops.h
628e06
index b8581fa..883b125 100644
628e06
--- a/src/google/protobuf/stubs/atomicops.h
628e06
+++ b/src/google/protobuf/stubs/atomicops.h
628e06
@@ -185,7 +185,7 @@ GOOGLE_PROTOBUF_ATOMICOPS_ERROR
628e06
 #elif defined(__pnacl__)
628e06
 #include <google/protobuf/stubs/atomicops_internals_pnacl.h>
628e06
 #else
628e06
-GOOGLE_PROTOBUF_ATOMICOPS_ERROR
628e06
+#include <google/protobuf/stubs/atomicops_internals_generic_gcc.h>
628e06
 #endif
628e06
 
628e06
 // Unknown.
628e06
diff --git a/src/google/protobuf/stubs/atomicops_internals_generic_gcc.h b/src/google/protobuf/stubs/atomicops_internals_generic_gcc.h
628e06
new file mode 100644
628e06
index 0000000..3fc2a9b
628e06
--- /dev/null
628e06
+++ b/src/google/protobuf/stubs/atomicops_internals_generic_gcc.h
628e06
@@ -0,0 +1,139 @@
628e06
+// Protocol Buffers - Google's data interchange format
628e06
+// Copyright 2013 Red Hat Inc.  All rights reserved.
628e06
+// http://code.google.com/p/protobuf/
628e06
+//
628e06
+// Redistribution and use in source and binary forms, with or without
628e06
+// modification, are permitted provided that the following conditions are
628e06
+// met:
628e06
+//
628e06
+//     * Redistributions of source code must retain the above copyright
628e06
+// notice, this list of conditions and the following disclaimer.
628e06
+//     * Redistributions in binary form must reproduce the above
628e06
+// copyright notice, this list of conditions and the following disclaimer
628e06
+// in the documentation and/or other materials provided with the
628e06
+// distribution.
628e06
+//     * Neither the name of Red Hat Inc. nor the names of its
628e06
+// contributors may be used to endorse or promote products derived from
628e06
+// this software without specific prior written permission.
628e06
+//
628e06
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
628e06
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
628e06
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
628e06
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
628e06
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
628e06
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
628e06
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
628e06
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
628e06
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
628e06
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
628e06
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
628e06
+
628e06
+// This file is an internal atomic implementation, use atomicops.h instead.
628e06
+
628e06
+#ifndef GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_GENERIC_GCC_H_
628e06
+#define GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_GENERIC_GCC_H_
628e06
+
628e06
+namespace google {
628e06
+namespace protobuf {
628e06
+namespace internal {
628e06
+
628e06
+inline Atomic32 NoBarrier_CompareAndSwap(volatile Atomic32* ptr,
628e06
+                                         Atomic32 old_value,
628e06
+                                         Atomic32 new_value) {
628e06
+  __atomic_compare_exchange_n(ptr, &old_value, new_value, true,
628e06
+                              __ATOMIC_RELAXED, __ATOMIC_RELAXED);
628e06
+  return old_value;
628e06
+}
628e06
+
628e06
+inline Atomic32 NoBarrier_AtomicExchange(volatile Atomic32* ptr,
628e06
+                                         Atomic32 new_value) {
628e06
+  return __atomic_exchange_n(ptr, new_value, __ATOMIC_RELAXED);
628e06
+}
628e06
+
628e06
+inline Atomic32 NoBarrier_AtomicIncrement(volatile Atomic32* ptr,
628e06
+                                          Atomic32 increment) {
628e06
+  return __atomic_add_fetch(ptr, increment, __ATOMIC_RELAXED);
628e06
+}
628e06
+
628e06
+inline Atomic32 Barrier_AtomicIncrement(volatile Atomic32* ptr,
628e06
+                                        Atomic32 increment) {
628e06
+  return __atomic_add_fetch(ptr, increment, __ATOMIC_SEQ_CST);
628e06
+}
628e06
+
628e06
+inline Atomic32 Acquire_CompareAndSwap(volatile Atomic32* ptr,
628e06
+                                       Atomic32 old_value,
628e06
+                                       Atomic32 new_value) {
628e06
+  __atomic_compare_exchange(ptr, &old_value, &new_value, true,
628e06
+                            __ATOMIC_ACQUIRE, __ATOMIC_ACQUIRE);
628e06
+  return old_value;
628e06
+}
628e06
+
628e06
+inline Atomic32 Release_CompareAndSwap(volatile Atomic32* ptr,
628e06
+                                       Atomic32 old_value,
628e06
+                                       Atomic32 new_value) {
628e06
+  __atomic_compare_exchange_n(ptr, &old_value, new_value, true,
628e06
+                            __ATOMIC_RELEASE, __ATOMIC_ACQUIRE);
628e06
+  return old_value;
628e06
+}
628e06
+
628e06
+inline void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value) {
628e06
+  __atomic_store_n(ptr, value, __ATOMIC_RELAXED);
628e06
+}
628e06
+
628e06
+inline void MemoryBarrier() {
628e06
+  __sync_synchronize();
628e06
+}
628e06
+
628e06
+inline void Acquire_Store(volatile Atomic32* ptr, Atomic32 value) {
628e06
+  __atomic_store_n(ptr, value, __ATOMIC_ACQUIRE);
628e06
+}
628e06
+
628e06
+inline void Release_Store(volatile Atomic32* ptr, Atomic32 value) {
628e06
+  __atomic_store_n(ptr, value, __ATOMIC_RELEASE);
628e06
+}
628e06
+
628e06
+inline Atomic32 NoBarrier_Load(volatile const Atomic32* ptr) {
628e06
+  return __atomic_load_n(ptr, __ATOMIC_RELAXED);
628e06
+}
628e06
+
628e06
+inline Atomic32 Acquire_Load(volatile const Atomic32* ptr) {
628e06
+  return __atomic_load_n(ptr, __ATOMIC_ACQUIRE);
628e06
+}
628e06
+
628e06
+inline Atomic32 Release_Load(volatile const Atomic32* ptr) {
628e06
+  return __atomic_load_n(ptr, __ATOMIC_RELEASE);
628e06
+}
628e06
+
628e06
+#ifdef __LP64__
628e06
+
628e06
+inline void Release_Store(volatile Atomic64* ptr, Atomic64 value) {
628e06
+  __atomic_store_n(ptr, value, __ATOMIC_RELEASE);
628e06
+}
628e06
+
628e06
+inline Atomic64 Acquire_Load(volatile const Atomic64* ptr) {
628e06
+  return __atomic_load_n(ptr, __ATOMIC_ACQUIRE);
628e06
+}
628e06
+
628e06
+inline Atomic64 Acquire_CompareAndSwap(volatile Atomic64* ptr,
628e06
+                                       Atomic64 old_value,
628e06
+                                       Atomic64 new_value) {
628e06
+  __atomic_compare_exchange_n(ptr, &old_value, new_value, true,
628e06
+                              __ATOMIC_ACQUIRE, __ATOMIC_ACQUIRE);
628e06
+  return old_value;
628e06
+}
628e06
+
628e06
+inline Atomic64 NoBarrier_CompareAndSwap(volatile Atomic64* ptr,
628e06
+                                         Atomic64 old_value,
628e06
+                                         Atomic64 new_value) {
628e06
+  __atomic_compare_exchange_n(ptr, &old_value, new_value, true,
628e06
+                            __ATOMIC_RELAXED, __ATOMIC_RELAXED);
628e06
+  return old_value;
628e06
+}
628e06
+
628e06
+#endif // defined(__LP64__)
628e06
+
628e06
+}  // namespace internal
628e06
+}  // namespace protobuf
628e06
+}  // namespace google
628e06
+
628e06
+#endif  // GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_GENERIC_GCC_H_
628e06
diff --git a/src/google/protobuf/stubs/platform_macros.h b/src/google/protobuf/stubs/platform_macros.h
628e06
index b1df60e..db691d8 100644
628e06
--- a/src/google/protobuf/stubs/platform_macros.h
628e06
+++ b/src/google/protobuf/stubs/platform_macros.h
628e06
@@ -43,6 +43,9 @@
628e06
 #elif defined(_M_IX86) || defined(__i386__)
628e06
 #define GOOGLE_PROTOBUF_ARCH_IA32 1
628e06
 #define GOOGLE_PROTOBUF_ARCH_32_BIT 1
628e06
+#elif defined(__aarch64__)
628e06
+#define GOOGLE_PROTOBUF_ARCH_AARCH64 1
628e06
+#define GOOGLE_PROTOBUF_ARCH_64_BIT 1
628e06
 #elif defined(__QNX__)
628e06
 #define GOOGLE_PROTOBUF_ARCH_ARM_QNX 1
628e06
 #define GOOGLE_PROTOBUF_ARCH_32_BIT 1
628e06
@@ -54,9 +57,18 @@
628e06
 #define GOOGLE_PROTOBUF_ARCH_32_BIT 1
628e06
 #elif defined(__pnacl__)
628e06
 #define GOOGLE_PROTOBUF_ARCH_32_BIT 1
628e06
-#elif defined(__ppc__)
628e06
+#elif defined(__ppc64__) || defined(__PPC64__)
628e06
+#define GOOGLE_PROTOBUF_ARCH_PPC64 1
628e06
+#define GOOGLE_PROTOBUF_ARCH_64_BIT 1
628e06
+#elif defined(__ppc__) || defined(__PPC__)
628e06
 #define GOOGLE_PROTOBUF_ARCH_PPC 1
628e06
 #define GOOGLE_PROTOBUF_ARCH_32_BIT 1
628e06
+#elif defined(__s390x__)
628e06
+#define GOOGLE_PROTOBUF_ARCH_64_BIT 1
628e06
+#define GOOGLE_PROTOBUF_ARCH_S390X 1
628e06
+#elif defined(__s390__)
628e06
+#define GOOGLE_PROTOBUF_ARCH_32_BIT 1
628e06
+#define GOOGLE_PROTOBUF_ARCH_S390 1
628e06
 #else
628e06
 #error Host architecture was not detected as supported by protobuf
628e06
 #endif
628e06
-- 
628e06
1.8.1.4
628e06