1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2012 Google Inc. All rights reserved.
3 // http://code.google.com/p/protobuf/
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_ATOMICWORD_COMPAT_H_
34 #define GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_ATOMICWORD_COMPAT_H_
36 // AtomicWord is a synonym for intptr_t, and Atomic32 is a synonym for int32,
37 // which in turn means int. On some LP32 platforms, intptr_t is an int, but
38 // on others, it's a long. When AtomicWord and Atomic32 are based on different
39 // fundamental types, their pointers are incompatible.
41 // This file defines function overloads to allow both AtomicWord and Atomic32
42 // data to be used with this interface.
44 // On LP64 platforms, AtomicWord and Atomic64 are both always long,
45 // so this problem doesn't occur.
47 #if !defined(GOOGLE_PROTOBUF_ARCH_64_BIT)
53 inline AtomicWord NoBarrier_CompareAndSwap(volatile AtomicWord* ptr,
55 AtomicWord new_value) {
56 return NoBarrier_CompareAndSwap(
57 reinterpret_cast<volatile Atomic32*>(ptr), old_value, new_value);
60 inline AtomicWord NoBarrier_AtomicExchange(volatile AtomicWord* ptr,
61 AtomicWord new_value) {
62 return NoBarrier_AtomicExchange(
63 reinterpret_cast<volatile Atomic32*>(ptr), new_value);
66 inline AtomicWord NoBarrier_AtomicIncrement(volatile AtomicWord* ptr,
67 AtomicWord increment) {
68 return NoBarrier_AtomicIncrement(
69 reinterpret_cast<volatile Atomic32*>(ptr), increment);
72 inline AtomicWord Barrier_AtomicIncrement(volatile AtomicWord* ptr,
73 AtomicWord increment) {
74 return Barrier_AtomicIncrement(
75 reinterpret_cast<volatile Atomic32*>(ptr), increment);
78 inline AtomicWord Acquire_CompareAndSwap(volatile AtomicWord* ptr,
80 AtomicWord new_value) {
81 return Acquire_CompareAndSwap(
82 reinterpret_cast<volatile Atomic32*>(ptr), old_value, new_value);
85 inline AtomicWord Release_CompareAndSwap(volatile AtomicWord* ptr,
87 AtomicWord new_value) {
88 return Release_CompareAndSwap(
89 reinterpret_cast<volatile Atomic32*>(ptr), old_value, new_value);
92 inline void NoBarrier_Store(volatile AtomicWord *ptr, AtomicWord value) {
93 NoBarrier_Store(reinterpret_cast<volatile Atomic32*>(ptr), value);
96 inline void Acquire_Store(volatile AtomicWord* ptr, AtomicWord value) {
97 return Acquire_Store(reinterpret_cast<volatile Atomic32*>(ptr), value);
100 inline void Release_Store(volatile AtomicWord* ptr, AtomicWord value) {
101 return Release_Store(reinterpret_cast<volatile Atomic32*>(ptr), value);
104 inline AtomicWord NoBarrier_Load(volatile const AtomicWord *ptr) {
105 return NoBarrier_Load(reinterpret_cast<volatile const Atomic32*>(ptr));
108 inline AtomicWord Acquire_Load(volatile const AtomicWord* ptr) {
109 return Acquire_Load(reinterpret_cast<volatile const Atomic32*>(ptr));
112 inline AtomicWord Release_Load(volatile const AtomicWord* ptr) {
113 return Release_Load(reinterpret_cast<volatile const Atomic32*>(ptr));
116 } // namespace internal
117 } // namespace protobuf
118 } // namespace google
120 #endif // !defined(GOOGLE_PROTOBUF_ARCH_64_BIT)
122 #endif // GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_ATOMICWORD_COMPAT_H_