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_ 9 #pragma once 10 11 // AtomicWord is a synonym for intptr_t, and Atomic32 is a synonym for int32, 12 // which in turn means int. On some LP32 platforms, intptr_t is an int, but 13 // on others, it's a long. When AtomicWord and Atomic32 are based on different 14 // fundamental types, their pointers are incompatible. 15 // 16 // This file defines function overloads to allow both AtomicWord and Atomic32 17 // data to be used with this interface. 18 // 19 // On LP64 platforms, AtomicWord and Atomic64 are both always long, 20 // so this problem doesn't occur. 21 22 #if !defined(ARCH_CPU_64_BITS) 23 24 namespace base { 25 namespace subtle { 26 27 inline AtomicWord NoBarrier_CompareAndSwap(volatile AtomicWord* ptr, 28 AtomicWord old_value, 29 AtomicWord new_value) { 30 return NoBarrier_CompareAndSwap( 31 reinterpret_cast<volatile Atomic32*>(ptr), old_value, new_value); 32 } 33 34 inline AtomicWord NoBarrier_AtomicExchange(volatile AtomicWord* ptr, 35 AtomicWord new_value) { 36 return NoBarrier_AtomicExchange( 37 reinterpret_cast<volatile Atomic32*>(ptr), new_value); 38 } 39 40 inline AtomicWord NoBarrier_AtomicIncrement(volatile AtomicWord* ptr, 41 AtomicWord increment) { 42 return NoBarrier_AtomicIncrement( 43 reinterpret_cast<volatile Atomic32*>(ptr), increment); 44 } 45 46 inline AtomicWord Barrier_AtomicIncrement(volatile AtomicWord* ptr, 47 AtomicWord increment) { 48 return Barrier_AtomicIncrement( 49 reinterpret_cast<volatile Atomic32*>(ptr), increment); 50 } 51 52 inline AtomicWord Acquire_CompareAndSwap(volatile AtomicWord* ptr, 53 AtomicWord old_value, 54 AtomicWord new_value) { 55 return base::subtle::Acquire_CompareAndSwap( 56 reinterpret_cast<volatile Atomic32*>(ptr), old_value, new_value); 57 } 58 59 inline AtomicWord Release_CompareAndSwap(volatile AtomicWord* ptr, 60 AtomicWord old_value, 61 AtomicWord new_value) { 62 return base::subtle::Release_CompareAndSwap( 63 reinterpret_cast<volatile Atomic32*>(ptr), old_value, new_value); 64 } 65 66 inline void NoBarrier_Store(volatile AtomicWord *ptr, AtomicWord value) { 67 NoBarrier_Store( 68 reinterpret_cast<volatile Atomic32*>(ptr), value); 69 } 70 71 inline void Acquire_Store(volatile AtomicWord* ptr, AtomicWord value) { 72 return base::subtle::Acquire_Store( 73 reinterpret_cast<volatile Atomic32*>(ptr), value); 74 } 75 76 inline void Release_Store(volatile AtomicWord* ptr, AtomicWord value) { 77 return base::subtle::Release_Store( 78 reinterpret_cast<volatile Atomic32*>(ptr), value); 79 } 80 81 inline AtomicWord NoBarrier_Load(volatile const AtomicWord *ptr) { 82 return NoBarrier_Load( 83 reinterpret_cast<volatile const Atomic32*>(ptr)); 84 } 85 86 inline AtomicWord Acquire_Load(volatile const AtomicWord* ptr) { 87 return base::subtle::Acquire_Load( 88 reinterpret_cast<volatile const Atomic32*>(ptr)); 89 } 90 91 inline AtomicWord Release_Load(volatile const AtomicWord* ptr) { 92 return base::subtle::Release_Load( 93 reinterpret_cast<volatile const Atomic32*>(ptr)); 94 } 95 96 } // namespace base::subtle 97 } // namespace base 98 99 #endif // !defined(ARCH_CPU_64_BITS) 100 101 #endif // BASE_ATOMICOPS_INTERNALS_ATOMICWORD_COMPAT_H_ 102