atomicops_internals_atomicword_compat.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 Acquire_Store(volatile AtomicWord* ptr, AtomicWord value) {
  60. return base::subtle::Acquire_Store(
  61. reinterpret_cast<volatile Atomic32*>(ptr), value);
  62. }
  63. inline void Release_Store(volatile AtomicWord* ptr, AtomicWord value) {
  64. return base::subtle::Release_Store(
  65. reinterpret_cast<volatile Atomic32*>(ptr), value);
  66. }
  67. inline AtomicWord NoBarrier_Load(volatile const AtomicWord *ptr) {
  68. return NoBarrier_Load(
  69. reinterpret_cast<volatile const Atomic32*>(ptr));
  70. }
  71. inline AtomicWord Acquire_Load(volatile const AtomicWord* ptr) {
  72. return base::subtle::Acquire_Load(
  73. reinterpret_cast<volatile const Atomic32*>(ptr));
  74. }
  75. inline AtomicWord Release_Load(volatile const AtomicWord* ptr) {
  76. return base::subtle::Release_Load(
  77. reinterpret_cast<volatile const Atomic32*>(ptr));
  78. }
  79. } // namespace subtle
  80. } // namespace base
  81. #endif // !defined(ARCH_CPU_64_BITS)
  82. #endif // BASE_ATOMICOPS_INTERNALS_ATOMICWORD_COMPAT_H_