1 // Copyright 2014 Google Inc. All rights reserved.
2 // https://developers.google.com/protocol-buffers/
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above
11 // copyright notice, this list of conditions and the following disclaimer
12 // in the documentation and/or other materials provided with the
14 // * Neither the name of Google Inc. nor the names of its
15 // contributors may be used to endorse or promote products derived from
16 // this software without specific prior written permission.
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 // This file is an internal atomic implementation, use atomicops.h instead.
32 #ifndef GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_SPARC_GCC_H_
33 #define GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_SPARC_GCC_H_
41 inline Atomic32 NoBarrier_CompareAndSwap(volatile Atomic32* ptr,
44 return (Atomic32)atomic_cas_32((volatile uint32_t*)ptr, (uint32_t)old_value, (uint32_t)new_value);
47 inline Atomic32 NoBarrier_AtomicExchange(volatile Atomic32* ptr,
49 return (Atomic32)atomic_swap_32((volatile uint32_t*)ptr, (uint32_t)new_value);
52 inline Atomic32 NoBarrier_AtomicIncrement(volatile Atomic32* ptr,
54 return (Atomic32)atomic_add_32_nv((volatile uint32_t*)ptr, (uint32_t)increment);
57 inline void MemoryBarrier(void) {
62 inline Atomic32 Barrier_AtomicIncrement(volatile Atomic32* ptr,
65 Atomic32 ret = NoBarrier_AtomicIncrement(ptr, increment);
71 inline Atomic32 Acquire_CompareAndSwap(volatile Atomic32* ptr,
74 Atomic32 ret = NoBarrier_CompareAndSwap(ptr, old_value, new_value);
80 inline Atomic32 Release_CompareAndSwap(volatile Atomic32* ptr,
84 return NoBarrier_CompareAndSwap(ptr, old_value, new_value);
87 inline void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value) {
91 inline void Acquire_Store(volatile Atomic32* ptr, Atomic32 value) {
96 inline void Release_Store(volatile Atomic32* ptr, Atomic32 value) {
101 inline Atomic32 NoBarrier_Load(volatile const Atomic32* ptr) {
105 inline Atomic32 Acquire_Load(volatile const Atomic32* ptr) {
111 inline Atomic32 Release_Load(volatile const Atomic32* ptr) {
116 #ifdef GOOGLE_PROTOBUF_ARCH_64_BIT
117 inline Atomic64 NoBarrier_CompareAndSwap(volatile Atomic64* ptr,
119 Atomic64 new_value) {
120 return atomic_cas_64((volatile uint64_t*)ptr, (uint64_t)old_value, (uint64_t)new_value);
123 inline Atomic64 NoBarrier_AtomicExchange(volatile Atomic64* ptr, Atomic64 new_value) {
124 return atomic_swap_64((volatile uint64_t*)ptr, (uint64_t)new_value);
127 inline Atomic64 NoBarrier_AtomicIncrement(volatile Atomic64* ptr, Atomic64 increment) {
128 return atomic_add_64_nv((volatile uint64_t*)ptr, increment);
131 inline Atomic64 Barrier_AtomicIncrement(volatile Atomic64* ptr, Atomic64 increment) {
133 Atomic64 ret = atomic_add_64_nv((volatile uint64_t*)ptr, increment);
138 inline Atomic64 Acquire_CompareAndSwap(volatile Atomic64* ptr,
140 Atomic64 new_value) {
141 Atomic64 ret = NoBarrier_CompareAndSwap(ptr, old_value, new_value);
146 inline Atomic64 Release_CompareAndSwap(volatile Atomic64* ptr,
148 Atomic64 new_value) {
150 return NoBarrier_CompareAndSwap(ptr, old_value, new_value);
153 inline void NoBarrier_Store(volatile Atomic64* ptr, Atomic64 value) {
157 inline void Acquire_Store(volatile Atomic64* ptr, Atomic64 value) {
162 inline void Release_Store(volatile Atomic64* ptr, Atomic64 value) {
167 inline Atomic64 NoBarrier_Load(volatile const Atomic64* ptr) {
171 inline Atomic64 Acquire_Load(volatile const Atomic64* ptr) {
177 inline Atomic64 Release_Load(volatile const Atomic64* ptr) {
183 } // namespace internal
184 } // namespace protobuf
185 } // namespace google
187 #endif // GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_SPARC_GCC_H_