1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // This file is an internal atomic implementation, use atomicops.h instead.
6
7 #ifndef V8_BASE_ATOMICOPS_INTERNALS_ATOMICWORD_COMPAT_H_
8 #define V8_BASE_ATOMICOPS_INTERNALS_ATOMICWORD_COMPAT_H_
9
10 // AtomicWord is a synonym for intptr_t, and Atomic32 is a synonym for int32,
11 // which in turn means int. On some LP32 platforms, intptr_t is an int, but
12 // on others, it's a long. When AtomicWord and Atomic32 are based on different
13 // fundamental types, their pointers are incompatible.
14 //
15 // This file defines function overloads to allow both AtomicWord and Atomic32
16 // data to be used with this interface.
17 //
18 // On LP64 platforms, AtomicWord and Atomic64 are both always long,
19 // so this problem doesn't occur.
20
21 #if !defined(V8_HOST_ARCH_64_BIT)
22
23 namespace v8 {
24 namespace base {
25
Relaxed_CompareAndSwap(volatile AtomicWord * ptr,AtomicWord old_value,AtomicWord new_value)26 inline AtomicWord Relaxed_CompareAndSwap(volatile AtomicWord* ptr,
27 AtomicWord old_value,
28 AtomicWord new_value) {
29 return Relaxed_CompareAndSwap(reinterpret_cast<volatile Atomic32*>(ptr),
30 old_value, new_value);
31 }
32
Relaxed_AtomicExchange(volatile AtomicWord * ptr,AtomicWord new_value)33 inline AtomicWord Relaxed_AtomicExchange(volatile AtomicWord* ptr,
34 AtomicWord new_value) {
35 return Relaxed_AtomicExchange(reinterpret_cast<volatile Atomic32*>(ptr),
36 new_value);
37 }
38
Relaxed_AtomicIncrement(volatile AtomicWord * ptr,AtomicWord increment)39 inline AtomicWord Relaxed_AtomicIncrement(volatile AtomicWord* ptr,
40 AtomicWord increment) {
41 return Relaxed_AtomicIncrement(reinterpret_cast<volatile Atomic32*>(ptr),
42 increment);
43 }
44
Acquire_CompareAndSwap(volatile AtomicWord * ptr,AtomicWord old_value,AtomicWord new_value)45 inline AtomicWord Acquire_CompareAndSwap(volatile AtomicWord* ptr,
46 AtomicWord old_value,
47 AtomicWord new_value) {
48 return v8::base::Acquire_CompareAndSwap(
49 reinterpret_cast<volatile Atomic32*>(ptr), old_value, new_value);
50 }
51
Release_CompareAndSwap(volatile AtomicWord * ptr,AtomicWord old_value,AtomicWord new_value)52 inline AtomicWord Release_CompareAndSwap(volatile AtomicWord* ptr,
53 AtomicWord old_value,
54 AtomicWord new_value) {
55 return v8::base::Release_CompareAndSwap(
56 reinterpret_cast<volatile Atomic32*>(ptr), old_value, new_value);
57 }
58
AcquireRelease_CompareAndSwap(volatile AtomicWord * ptr,AtomicWord old_value,AtomicWord new_value)59 inline AtomicWord AcquireRelease_CompareAndSwap(volatile AtomicWord* ptr,
60 AtomicWord old_value,
61 AtomicWord new_value) {
62 return v8::base::AcquireRelease_CompareAndSwap(
63 reinterpret_cast<volatile Atomic32*>(ptr), old_value, new_value);
64 }
65
Relaxed_Store(volatile AtomicWord * ptr,AtomicWord value)66 inline void Relaxed_Store(volatile AtomicWord* ptr, AtomicWord value) {
67 Relaxed_Store(reinterpret_cast<volatile Atomic32*>(ptr), value);
68 }
69
Release_Store(volatile AtomicWord * ptr,AtomicWord value)70 inline void Release_Store(volatile AtomicWord* ptr, AtomicWord value) {
71 return v8::base::Release_Store(
72 reinterpret_cast<volatile Atomic32*>(ptr), value);
73 }
74
Relaxed_Load(volatile const AtomicWord * ptr)75 inline AtomicWord Relaxed_Load(volatile const AtomicWord* ptr) {
76 return Relaxed_Load(reinterpret_cast<volatile const Atomic32*>(ptr));
77 }
78
Acquire_Load(volatile const AtomicWord * ptr)79 inline AtomicWord Acquire_Load(volatile const AtomicWord* ptr) {
80 return v8::base::Acquire_Load(
81 reinterpret_cast<volatile const Atomic32*>(ptr));
82 }
83
84 } // namespace base
85 } // namespace v8
86
87 #endif // !defined(V8_HOST_ARCH_64_BIT)
88
89 #endif // V8_BASE_ATOMICOPS_INTERNALS_ATOMICWORD_COMPAT_H_
90