1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2012 Google Inc. All rights reserved.
3 // https://developers.google.com/protocol-buffers/
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 // * Redistributions in binary form must reproduce the above
12 // copyright notice, this list of conditions and the following disclaimer
13 // in the documentation and/or other materials provided with the
15 // * Neither the name of Google Inc. nor the names of its
16 // contributors may be used to endorse or promote products derived from
17 // this software without specific prior written permission.
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 // This file is an internal atomic implementation, use atomicops.h instead.
33 #ifndef GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_ARM_QNX_H_
34 #define GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_ARM_QNX_H_
43 inline Atomic32 QNXCmpxchg(Atomic32 old_value,
45 volatile Atomic32* ptr) {
46 return static_cast<Atomic32>(
47 _smp_cmpxchg((volatile unsigned *)ptr,
49 (unsigned)new_value));
53 inline Atomic32 NoBarrier_CompareAndSwap(volatile Atomic32* ptr,
56 Atomic32 prev_value = *ptr;
58 if (!QNXCmpxchg(old_value, new_value,
59 const_cast<Atomic32*>(ptr))) {
63 } while (prev_value == old_value);
67 inline Atomic32 NoBarrier_AtomicExchange(volatile Atomic32* ptr,
72 } while (QNXCmpxchg(old_value, new_value,
73 const_cast<Atomic32*>(ptr)));
77 inline Atomic32 NoBarrier_AtomicIncrement(volatile Atomic32* ptr,
79 return Barrier_AtomicIncrement(ptr, increment);
82 inline Atomic32 Barrier_AtomicIncrement(volatile Atomic32* ptr,
85 // Atomic exchange the old value with an incremented one.
86 Atomic32 old_value = *ptr;
87 Atomic32 new_value = old_value + increment;
88 if (QNXCmpxchg(old_value, new_value,
89 const_cast<Atomic32*>(ptr)) == 0) {
90 // The exchange took place as expected.
93 // Otherwise, *ptr changed mid-loop and we need to retry.
97 inline Atomic32 Acquire_CompareAndSwap(volatile Atomic32* ptr,
100 return NoBarrier_CompareAndSwap(ptr, old_value, new_value);
103 inline Atomic32 Release_CompareAndSwap(volatile Atomic32* ptr,
105 Atomic32 new_value) {
106 return NoBarrier_CompareAndSwap(ptr, old_value, new_value);
109 inline void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value) {
113 inline void MemoryBarrier() {
114 __sync_synchronize();
117 inline void Acquire_Store(volatile Atomic32* ptr, Atomic32 value) {
122 inline void Release_Store(volatile Atomic32* ptr, Atomic32 value) {
127 inline Atomic32 NoBarrier_Load(volatile const Atomic32* ptr) {
131 inline Atomic32 Acquire_Load(volatile const Atomic32* ptr) {
132 Atomic32 value = *ptr;
137 inline Atomic32 Release_Load(volatile const Atomic32* ptr) {
142 } // namespace internal
143 } // namespace protobuf
144 } // namespace google
146 #endif // GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_ARM_QNX_H_