[email protected] | 0c6f3b0c | 2011-04-15 06:15:04 | [diff] [blame] | 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. |
| 4 | |
| 5 | // This file is an internal atomic implementation, use base/atomicops.h instead. |
| 6 | |
| 7 | #ifndef BASE_ATOMICOPS_INTERNALS_ATOMICWORD_COMPAT_H_ |
| 8 | #define BASE_ATOMICOPS_INTERNALS_ATOMICWORD_COMPAT_H_ |
[email protected] | 0c6f3b0c | 2011-04-15 06:15:04 | [diff] [blame] | 9 | |
avi | 9b6f4293 | 2015-12-26 22:15:14 | [diff] [blame] | 10 | #include <stdint.h> |
| 11 | |
| 12 | #include "build/build_config.h" |
| 13 | |
| 14 | // AtomicWord is a synonym for intptr_t, and Atomic32 is a synonym for int32_t, |
[email protected] | 0c6f3b0c | 2011-04-15 06:15:04 | [diff] [blame] | 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. |
| 18 | // |
| 19 | // This file defines function overloads to allow both AtomicWord and Atomic32 |
| 20 | // data to be used with this interface. |
| 21 | // |
| 22 | // On LP64 platforms, AtomicWord and Atomic64 are both always long, |
| 23 | // so this problem doesn't occur. |
| 24 | |
| 25 | #if !defined(ARCH_CPU_64_BITS) |
| 26 | |
| 27 | namespace base { |
| 28 | namespace subtle { |
| 29 | |
| 30 | inline AtomicWord NoBarrier_CompareAndSwap(volatile AtomicWord* ptr, |
| 31 | AtomicWord old_value, |
| 32 | AtomicWord new_value) { |
| 33 | return NoBarrier_CompareAndSwap( |
| 34 | reinterpret_cast<volatile Atomic32*>(ptr), old_value, new_value); |
| 35 | } |
| 36 | |
| 37 | inline AtomicWord NoBarrier_AtomicExchange(volatile AtomicWord* ptr, |
| 38 | AtomicWord new_value) { |
| 39 | return NoBarrier_AtomicExchange( |
| 40 | reinterpret_cast<volatile Atomic32*>(ptr), new_value); |
| 41 | } |
| 42 | |
| 43 | inline AtomicWord NoBarrier_AtomicIncrement(volatile AtomicWord* ptr, |
| 44 | AtomicWord increment) { |
| 45 | return NoBarrier_AtomicIncrement( |
| 46 | reinterpret_cast<volatile Atomic32*>(ptr), increment); |
| 47 | } |
| 48 | |
| 49 | inline AtomicWord Barrier_AtomicIncrement(volatile AtomicWord* ptr, |
| 50 | AtomicWord increment) { |
| 51 | return Barrier_AtomicIncrement( |
| 52 | reinterpret_cast<volatile Atomic32*>(ptr), increment); |
| 53 | } |
| 54 | |
| 55 | inline AtomicWord Acquire_CompareAndSwap(volatile AtomicWord* ptr, |
| 56 | AtomicWord old_value, |
| 57 | AtomicWord new_value) { |
| 58 | return base::subtle::Acquire_CompareAndSwap( |
| 59 | reinterpret_cast<volatile Atomic32*>(ptr), old_value, new_value); |
| 60 | } |
| 61 | |
| 62 | inline AtomicWord Release_CompareAndSwap(volatile AtomicWord* ptr, |
| 63 | AtomicWord old_value, |
| 64 | AtomicWord new_value) { |
| 65 | return base::subtle::Release_CompareAndSwap( |
| 66 | reinterpret_cast<volatile Atomic32*>(ptr), old_value, new_value); |
| 67 | } |
| 68 | |
| 69 | inline void NoBarrier_Store(volatile AtomicWord *ptr, AtomicWord value) { |
| 70 | NoBarrier_Store( |
| 71 | reinterpret_cast<volatile Atomic32*>(ptr), value); |
| 72 | } |
| 73 | |
| 74 | inline void Acquire_Store(volatile AtomicWord* ptr, AtomicWord value) { |
| 75 | return base::subtle::Acquire_Store( |
| 76 | reinterpret_cast<volatile Atomic32*>(ptr), value); |
| 77 | } |
| 78 | |
| 79 | inline void Release_Store(volatile AtomicWord* ptr, AtomicWord value) { |
| 80 | return base::subtle::Release_Store( |
| 81 | reinterpret_cast<volatile Atomic32*>(ptr), value); |
| 82 | } |
| 83 | |
| 84 | inline AtomicWord NoBarrier_Load(volatile const AtomicWord *ptr) { |
| 85 | return NoBarrier_Load( |
| 86 | reinterpret_cast<volatile const Atomic32*>(ptr)); |
| 87 | } |
| 88 | |
| 89 | inline AtomicWord Acquire_Load(volatile const AtomicWord* ptr) { |
| 90 | return base::subtle::Acquire_Load( |
| 91 | reinterpret_cast<volatile const Atomic32*>(ptr)); |
| 92 | } |
| 93 | |
| 94 | inline AtomicWord Release_Load(volatile const AtomicWord* ptr) { |
| 95 | return base::subtle::Release_Load( |
| 96 | reinterpret_cast<volatile const Atomic32*>(ptr)); |
| 97 | } |
| 98 | |
danakj | c3762b9 | 2015-03-07 01:51:42 | [diff] [blame] | 99 | } // namespace subtle |
| 100 | } // namespace base |
[email protected] | 0c6f3b0c | 2011-04-15 06:15:04 | [diff] [blame] | 101 | |
| 102 | #endif // !defined(ARCH_CPU_64_BITS) |
| 103 | |
| 104 | #endif // BASE_ATOMICOPS_INTERNALS_ATOMICWORD_COMPAT_H_ |