win_fenced_block.hpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. //
  2. // detail/win_fenced_block.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2018 Christopher M. Kohlhoff (chris at kohlhoff dot com)
  6. //
  7. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  8. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  9. //
  10. #ifndef BOOST_ASIO_DETAIL_WIN_FENCED_BLOCK_HPP
  11. #define BOOST_ASIO_DETAIL_WIN_FENCED_BLOCK_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include <boost/asio/detail/config.hpp>
  16. #if defined(BOOST_ASIO_WINDOWS) && !defined(UNDER_CE)
  17. #include <boost/asio/detail/socket_types.hpp>
  18. #include <boost/asio/detail/noncopyable.hpp>
  19. #include <boost/asio/detail/push_options.hpp>
  20. namespace boost {
  21. namespace asio {
  22. namespace detail {
  23. class win_fenced_block
  24. : private noncopyable
  25. {
  26. public:
  27. enum half_t { half };
  28. enum full_t { full };
  29. // Constructor for a half fenced block.
  30. explicit win_fenced_block(half_t)
  31. {
  32. }
  33. // Constructor for a full fenced block.
  34. explicit win_fenced_block(full_t)
  35. {
  36. #if defined(__BORLANDC__)
  37. LONG barrier = 0;
  38. ::InterlockedExchange(&barrier, 1);
  39. #elif defined(BOOST_ASIO_MSVC) \
  40. && ((BOOST_ASIO_MSVC < 1400) || !defined(MemoryBarrier))
  41. # if defined(_M_IX86)
  42. # pragma warning(push)
  43. # pragma warning(disable:4793)
  44. LONG barrier;
  45. __asm { xchg barrier, eax }
  46. # pragma warning(pop)
  47. # endif // defined(_M_IX86)
  48. #else
  49. MemoryBarrier();
  50. #endif
  51. }
  52. // Destructor.
  53. ~win_fenced_block()
  54. {
  55. #if defined(__BORLANDC__)
  56. LONG barrier = 0;
  57. ::InterlockedExchange(&barrier, 1);
  58. #elif defined(BOOST_ASIO_MSVC) \
  59. && ((BOOST_ASIO_MSVC < 1400) || !defined(MemoryBarrier))
  60. # if defined(_M_IX86)
  61. # pragma warning(push)
  62. # pragma warning(disable:4793)
  63. LONG barrier;
  64. __asm { xchg barrier, eax }
  65. # pragma warning(pop)
  66. # endif // defined(_M_IX86)
  67. #else
  68. MemoryBarrier();
  69. #endif
  70. }
  71. };
  72. } // namespace detail
  73. } // namespace asio
  74. } // namespace boost
  75. #include <boost/asio/detail/pop_options.hpp>
  76. #endif // defined(BOOST_ASIO_WINDOWS) && !defined(UNDER_CE)
  77. #endif // BOOST_ASIO_DETAIL_WIN_FENCED_BLOCK_HPP