atomicops_internals_atomicword_compat.h 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. // This file is an internal atomic implementation, use base/atomicops.h instead.
  5. #ifndef BASE_ATOMICOPS_INTERNALS_ATOMICWORD_COMPAT_H_
  6. #define BASE_ATOMICOPS_INTERNALS_ATOMICWORD_COMPAT_H_
  7. #include <stdint.h>
  8. #include "build/build_config.h"
  9. // AtomicWord is a synonym for intptr_t, and Atomic32 is a synonym for int32_t,
  10. // which in turn means int. On some LP32 platforms, intptr_t is an int, but
  11. // on others, it's a long. When AtomicWord and Atomic32 are based on different
  12. // fundamental types, their pointers are incompatible.
  13. //
  14. // This file defines function overloads to allow both AtomicWord and Atomic32
  15. // data to be used with this interface.
  16. //
  17. // On LP64 platforms, AtomicWord and Atomic64 are both always long,
  18. // so this problem doesn't occur.
  19. #if !defined(ARCH_CPU_64_BITS)
  20. namespace base {
  21. namespace subtle {
  22. inline AtomicWord NoBarrier_CompareAndSwap(volatile AtomicWord* ptr,
  23. AtomicWord old_value,
  24. AtomicWord new_value) {
  25. return NoBarrier_CompareAndSwap(
  26. reinterpret_cast<volatile Atomic32*>(ptr), old_value, new_value);
  27. }
  28. inline AtomicWord NoBarrier_AtomicExchange(volatile AtomicWord* ptr,
  29. AtomicWord new_value) {
  30. return NoBarrier_AtomicExchange(
  31. reinterpret_cast<volatile Atomic32*>(ptr), new_value);
  32. }
  33. inline AtomicWord NoBarrier_AtomicIncrement(volatile AtomicWord* ptr,
  34. AtomicWord increment) {
  35. return NoBarrier_AtomicIncrement(
  36. reinterpret_cast<volatile Atomic32*>(ptr), increment);
  37. }
  38. inline AtomicWord Barrier_AtomicIncrement(volatile AtomicWord* ptr,
  39. AtomicWord increment) {
  40. return Barrier_AtomicIncrement(
  41. reinterpret_cast<volatile Atomic32*>(ptr), increment);
  42. }
  43. inline AtomicWord Acquire_CompareAndSwap(volatile AtomicWord* ptr,
  44. AtomicWord old_value,
  45. AtomicWord new_value) {
  46. return base::subtle::Acquire_CompareAndSwap(
  47. reinterpret_cast<volatile Atomic32*>(ptr), old_value, new_value);
  48. }
  49. inline AtomicWord Release_CompareAndSwap(volatile AtomicWord* ptr,
  50. AtomicWord old_value,
  51. AtomicWord new_value) {
  52. return base::subtle::Release_CompareAndSwap(
  53. reinterpret_cast<volatile Atomic32*>(ptr), old_value, new_value);
  54. }
  55. inline void NoBarrier_Store(volatile AtomicWord *ptr, AtomicWord value) {
  56. NoBarrier_Store(
  57. reinterpret_cast<volatile Atomic32*>(ptr), value);
  58. }
  59. inline void Release_Store(volatile AtomicWord* ptr, AtomicWord value) {
  60. return base::subtle::Release_Store(
  61. reinterpret_cast<volatile Atomic32*>(ptr), value);
  62. }
  63. inline AtomicWord NoBarrier_Load(volatile const AtomicWord *ptr) {
  64. return NoBarrier_Load(
  65. reinterpret_cast<volatile const Atomic32*>(ptr));
  66. }
  67. inline AtomicWord Acquire_Load(volatile const AtomicWord* ptr) {
  68. return base::subtle::Acquire_Load(
  69. reinterpret_cast<volatile const Atomic32*>(ptr));
  70. }
  71. } // namespace subtle
  72. } // namespace base
  73. #endif // !defined(ARCH_CPU_64_BITS)
  74. #endif // BASE_ATOMICOPS_INTERNALS_ATOMICWORD_COMPAT_H_