interlocked_read.hpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #ifndef BOOST_THREAD_DETAIL_INTERLOCKED_READ_WIN32_HPP
  2. #define BOOST_THREAD_DETAIL_INTERLOCKED_READ_WIN32_HPP
  3. // interlocked_read_win32.hpp
  4. //
  5. // (C) Copyright 2005-8 Anthony Williams
  6. // (C) Copyright 2012 Vicente J. Botet Escriba
  7. //
  8. // Distributed under the Boost Software License, Version 1.0. (See
  9. // accompanying file LICENSE_1_0.txt or copy at
  10. // http://www.boost.org/LICENSE_1_0.txt)
  11. #include <boost/detail/interlocked.hpp>
  12. #include <boost/thread/detail/config.hpp>
  13. #include <boost/config/abi_prefix.hpp>
  14. #ifdef BOOST_MSVC
  15. extern "C" void _ReadWriteBarrier(void);
  16. #pragma intrinsic(_ReadWriteBarrier)
  17. namespace boost
  18. {
  19. namespace detail
  20. {
  21. inline long interlocked_read_acquire(long volatile* x) BOOST_NOEXCEPT
  22. {
  23. long const res=*x;
  24. _ReadWriteBarrier();
  25. return res;
  26. }
  27. inline void* interlocked_read_acquire(void* volatile* x) BOOST_NOEXCEPT
  28. {
  29. void* const res=*x;
  30. _ReadWriteBarrier();
  31. return res;
  32. }
  33. inline void interlocked_write_release(long volatile* x,long value) BOOST_NOEXCEPT
  34. {
  35. _ReadWriteBarrier();
  36. *x=value;
  37. }
  38. inline void interlocked_write_release(void* volatile* x,void* value) BOOST_NOEXCEPT
  39. {
  40. _ReadWriteBarrier();
  41. *x=value;
  42. }
  43. }
  44. }
  45. #else
  46. namespace boost
  47. {
  48. namespace detail
  49. {
  50. inline long interlocked_read_acquire(long volatile* x) BOOST_NOEXCEPT
  51. {
  52. return BOOST_INTERLOCKED_COMPARE_EXCHANGE(x,0,0);
  53. }
  54. inline void* interlocked_read_acquire(void* volatile* x) BOOST_NOEXCEPT
  55. {
  56. return BOOST_INTERLOCKED_COMPARE_EXCHANGE_POINTER(x,0,0);
  57. }
  58. inline void interlocked_write_release(long volatile* x,long value) BOOST_NOEXCEPT
  59. {
  60. BOOST_INTERLOCKED_EXCHANGE(x,value);
  61. }
  62. inline void interlocked_write_release(void* volatile* x,void* value) BOOST_NOEXCEPT
  63. {
  64. BOOST_INTERLOCKED_EXCHANGE_POINTER(x,value);
  65. }
  66. }
  67. }
  68. #endif
  69. #include <boost/config/abi_suffix.hpp>
  70. #endif