1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 // This file is an internal atomic implementation, use atomicops.h instead.
30 #ifndef V8_ATOMICOPS_INTERNALS_ATOMICWORD_COMPAT_H_
31 #define V8_ATOMICOPS_INTERNALS_ATOMICWORD_COMPAT_H_
33 // AtomicWord is a synonym for intptr_t, and Atomic32 is a synonym for int32,
34 // which in turn means int. On some LP32 platforms, intptr_t is an int, but
35 // on others, it's a long. When AtomicWord and Atomic32 are based on different
36 // fundamental types, their pointers are incompatible.
38 // This file defines function overloads to allow both AtomicWord and Atomic32
39 // data to be used with this interface.
41 // On LP64 platforms, AtomicWord and Atomic64 are both always long,
42 // so this problem doesn't occur.
44 #if !defined(V8_HOST_ARCH_64_BIT)
49 inline AtomicWord NoBarrier_CompareAndSwap(volatile AtomicWord* ptr,
51 AtomicWord new_value) {
52 return NoBarrier_CompareAndSwap(
53 reinterpret_cast<volatile Atomic32*>(ptr), old_value, new_value);
56 inline AtomicWord NoBarrier_AtomicExchange(volatile AtomicWord* ptr,
57 AtomicWord new_value) {
58 return NoBarrier_AtomicExchange(
59 reinterpret_cast<volatile Atomic32*>(ptr), new_value);
62 inline AtomicWord NoBarrier_AtomicIncrement(volatile AtomicWord* ptr,
63 AtomicWord increment) {
64 return NoBarrier_AtomicIncrement(
65 reinterpret_cast<volatile Atomic32*>(ptr), increment);
68 inline AtomicWord Barrier_AtomicIncrement(volatile AtomicWord* ptr,
69 AtomicWord increment) {
70 return Barrier_AtomicIncrement(
71 reinterpret_cast<volatile Atomic32*>(ptr), increment);
74 inline AtomicWord Acquire_CompareAndSwap(volatile AtomicWord* ptr,
76 AtomicWord new_value) {
77 return v8::internal::Acquire_CompareAndSwap(
78 reinterpret_cast<volatile Atomic32*>(ptr), old_value, new_value);
81 inline AtomicWord Release_CompareAndSwap(volatile AtomicWord* ptr,
83 AtomicWord new_value) {
84 return v8::internal::Release_CompareAndSwap(
85 reinterpret_cast<volatile Atomic32*>(ptr), old_value, new_value);
88 inline void NoBarrier_Store(volatile AtomicWord *ptr, AtomicWord value) {
90 reinterpret_cast<volatile Atomic32*>(ptr), value);
93 inline void Acquire_Store(volatile AtomicWord* ptr, AtomicWord value) {
94 return v8::internal::Acquire_Store(
95 reinterpret_cast<volatile Atomic32*>(ptr), value);
98 inline void Release_Store(volatile AtomicWord* ptr, AtomicWord value) {
99 return v8::internal::Release_Store(
100 reinterpret_cast<volatile Atomic32*>(ptr), value);
103 inline AtomicWord NoBarrier_Load(volatile const AtomicWord *ptr) {
104 return NoBarrier_Load(
105 reinterpret_cast<volatile const Atomic32*>(ptr));
108 inline AtomicWord Acquire_Load(volatile const AtomicWord* ptr) {
109 return v8::internal::Acquire_Load(
110 reinterpret_cast<volatile const Atomic32*>(ptr));
113 inline AtomicWord Release_Load(volatile const AtomicWord* ptr) {
114 return v8::internal::Release_Load(
115 reinterpret_cast<volatile const Atomic32*>(ptr));
118 } } // namespace v8::internal
120 #endif // !defined(V8_HOST_ARCH_64_BIT)
122 #endif // V8_ATOMICOPS_INTERNALS_ATOMICWORD_COMPAT_H_