1 // Copyright (c) 2011 Google Inc. All rights reserved.
2 //
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are
5 // met:
6 //
7 // * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 // * Redistributions in binary form must reproduce the above
10 // copyright notice, this list of conditions and the following disclaimer
11 // in the documentation and/or other materials provided with the
12 // distribution.
13 // * Neither the name of Google Inc. nor the name Chromium Embedded
14 // Framework nor the names of its contributors may be used to endorse
15 // or promote products derived from this software without specific prior
16 // written permission.
17 //
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.
29
30 // Do not include this header file directly. Use base/cef_atomicops.h
31 // instead.
32
33 #ifndef CEF_INCLUDE_BASE_INTERNAL_CEF_ATOMICOPS_ATOMICWORD_COMPAT_H_
34 #define CEF_INCLUDE_BASE_INTERNAL_CEF_ATOMICOPS_ATOMICWORD_COMPAT_H_
35
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.
40 //
41 // This file defines function overloads to allow both AtomicWord and Atomic32
42 // data to be used with this interface.
43 //
44 // On LP64 platforms, AtomicWord and Atomic64 are both always long,
45 // so this problem doesn't occur.
46
47 #if !defined(ARCH_CPU_64_BITS)
48
49 namespace base {
50 namespace subtle {
51
NoBarrier_CompareAndSwap(volatile AtomicWord * ptr,AtomicWord old_value,AtomicWord new_value)52 inline AtomicWord NoBarrier_CompareAndSwap(volatile AtomicWord* ptr,
53 AtomicWord old_value,
54 AtomicWord new_value) {
55 return NoBarrier_CompareAndSwap(reinterpret_cast<volatile Atomic32*>(ptr),
56 old_value, new_value);
57 }
58
NoBarrier_AtomicExchange(volatile AtomicWord * ptr,AtomicWord new_value)59 inline AtomicWord NoBarrier_AtomicExchange(volatile AtomicWord* ptr,
60 AtomicWord new_value) {
61 return NoBarrier_AtomicExchange(reinterpret_cast<volatile Atomic32*>(ptr),
62 new_value);
63 }
64
NoBarrier_AtomicIncrement(volatile AtomicWord * ptr,AtomicWord increment)65 inline AtomicWord NoBarrier_AtomicIncrement(volatile AtomicWord* ptr,
66 AtomicWord increment) {
67 return NoBarrier_AtomicIncrement(reinterpret_cast<volatile Atomic32*>(ptr),
68 increment);
69 }
70
Barrier_AtomicIncrement(volatile AtomicWord * ptr,AtomicWord increment)71 inline AtomicWord Barrier_AtomicIncrement(volatile AtomicWord* ptr,
72 AtomicWord increment) {
73 return Barrier_AtomicIncrement(reinterpret_cast<volatile Atomic32*>(ptr),
74 increment);
75 }
76
Acquire_CompareAndSwap(volatile AtomicWord * ptr,AtomicWord old_value,AtomicWord new_value)77 inline AtomicWord Acquire_CompareAndSwap(volatile AtomicWord* ptr,
78 AtomicWord old_value,
79 AtomicWord new_value) {
80 return base::subtle::Acquire_CompareAndSwap(
81 reinterpret_cast<volatile Atomic32*>(ptr), old_value, new_value);
82 }
83
Release_CompareAndSwap(volatile AtomicWord * ptr,AtomicWord old_value,AtomicWord new_value)84 inline AtomicWord Release_CompareAndSwap(volatile AtomicWord* ptr,
85 AtomicWord old_value,
86 AtomicWord new_value) {
87 return base::subtle::Release_CompareAndSwap(
88 reinterpret_cast<volatile Atomic32*>(ptr), old_value, new_value);
89 }
90
NoBarrier_Store(volatile AtomicWord * ptr,AtomicWord value)91 inline void NoBarrier_Store(volatile AtomicWord* ptr, AtomicWord value) {
92 NoBarrier_Store(reinterpret_cast<volatile Atomic32*>(ptr), value);
93 }
94
Acquire_Store(volatile AtomicWord * ptr,AtomicWord value)95 inline void Acquire_Store(volatile AtomicWord* ptr, AtomicWord value) {
96 return base::subtle::Acquire_Store(reinterpret_cast<volatile Atomic32*>(ptr),
97 value);
98 }
99
Release_Store(volatile AtomicWord * ptr,AtomicWord value)100 inline void Release_Store(volatile AtomicWord* ptr, AtomicWord value) {
101 return base::subtle::Release_Store(reinterpret_cast<volatile Atomic32*>(ptr),
102 value);
103 }
104
NoBarrier_Load(volatile const AtomicWord * ptr)105 inline AtomicWord NoBarrier_Load(volatile const AtomicWord* ptr) {
106 return NoBarrier_Load(reinterpret_cast<volatile const Atomic32*>(ptr));
107 }
108
Acquire_Load(volatile const AtomicWord * ptr)109 inline AtomicWord Acquire_Load(volatile const AtomicWord* ptr) {
110 return base::subtle::Acquire_Load(
111 reinterpret_cast<volatile const Atomic32*>(ptr));
112 }
113
Release_Load(volatile const AtomicWord * ptr)114 inline AtomicWord Release_Load(volatile const AtomicWord* ptr) {
115 return base::subtle::Release_Load(
116 reinterpret_cast<volatile const Atomic32*>(ptr));
117 }
118
119 } // namespace base::subtle
120 } // namespace base
121
122 #endif // !defined(ARCH_CPU_64_BITS)
123
124 #endif // CEF_INCLUDE_BASE_INTERNAL_CEF_ATOMICOPS_ATOMICWORD_COMPAT_H_
125