1 // Copyright (c) 2011 The Chromium 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.
5 // This file is an internal atomic implementation, use base/atomicops.h instead.
7 #ifndef BASE_ATOMICOPS_INTERNALS_ATOMICWORD_COMPAT_H_
8 #define BASE_ATOMICOPS_INTERNALS_ATOMICWORD_COMPAT_H_
12 #include "build/build_config.h"
14 // AtomicWord is a synonym for intptr_t, and Atomic32 is a synonym for int32_t,
15 // which in turn means int. On some LP32 platforms, intptr_t is an int, but
16 // on others, it's a long. When AtomicWord and Atomic32 are based on different
17 // fundamental types, their pointers are incompatible.
19 // This file defines function overloads to allow both AtomicWord and Atomic32
20 // data to be used with this interface.
22 // On LP64 platforms, AtomicWord and Atomic64 are both always long,
23 // so this problem doesn't occur.
25 #if !defined(ARCH_CPU_64_BITS)
30 inline AtomicWord NoBarrier_CompareAndSwap(volatile AtomicWord* ptr,
32 AtomicWord new_value) {
33 return NoBarrier_CompareAndSwap(
34 reinterpret_cast<volatile Atomic32*>(ptr), old_value, new_value);
37 inline AtomicWord NoBarrier_AtomicExchange(volatile AtomicWord* ptr,
38 AtomicWord new_value) {
39 return NoBarrier_AtomicExchange(
40 reinterpret_cast<volatile Atomic32*>(ptr), new_value);
43 inline AtomicWord NoBarrier_AtomicIncrement(volatile AtomicWord* ptr,
44 AtomicWord increment) {
45 return NoBarrier_AtomicIncrement(
46 reinterpret_cast<volatile Atomic32*>(ptr), increment);
49 inline AtomicWord Barrier_AtomicIncrement(volatile AtomicWord* ptr,
50 AtomicWord increment) {
51 return Barrier_AtomicIncrement(
52 reinterpret_cast<volatile Atomic32*>(ptr), increment);
55 inline AtomicWord Acquire_CompareAndSwap(volatile AtomicWord* ptr,
57 AtomicWord new_value) {
58 return base::subtle::Acquire_CompareAndSwap(
59 reinterpret_cast<volatile Atomic32*>(ptr), old_value, new_value);
62 inline AtomicWord Release_CompareAndSwap(volatile AtomicWord* ptr,
64 AtomicWord new_value) {
65 return base::subtle::Release_CompareAndSwap(
66 reinterpret_cast<volatile Atomic32*>(ptr), old_value, new_value);
69 inline void NoBarrier_Store(volatile AtomicWord *ptr, AtomicWord value) {
71 reinterpret_cast<volatile Atomic32*>(ptr), value);
74 inline void Release_Store(volatile AtomicWord* ptr, AtomicWord value) {
75 return base::subtle::Release_Store(
76 reinterpret_cast<volatile Atomic32*>(ptr), value);
79 inline AtomicWord NoBarrier_Load(volatile const AtomicWord *ptr) {
80 return NoBarrier_Load(
81 reinterpret_cast<volatile const Atomic32*>(ptr));
84 inline AtomicWord Acquire_Load(volatile const AtomicWord* ptr) {
85 return base::subtle::Acquire_Load(
86 reinterpret_cast<volatile const Atomic32*>(ptr));
92 #endif // !defined(ARCH_CPU_64_BITS)
94 #endif // BASE_ATOMICOPS_INTERNALS_ATOMICWORD_COMPAT_H_