win_fenced_block.hpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. //
  2. // detail/win_fenced_block.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2015 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 ASIO_DETAIL_WIN_FENCED_BLOCK_HPP
  11. #define 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 "asio/detail/config.hpp"
  16. #if defined(ASIO_WINDOWS) && !defined(UNDER_CE)
  17. #include "asio/detail/socket_types.hpp"
  18. #include "asio/detail/push_options.hpp"
  19. namespace asio {
  20. namespace detail {
  21. class win_fenced_block
  22. : private noncopyable
  23. {
  24. public:
  25. enum half_t { half };
  26. enum full_t { full };
  27. // Constructor for a half fenced block.
  28. explicit win_fenced_block(half_t)
  29. {
  30. }
  31. // Constructor for a full fenced block.
  32. explicit win_fenced_block(full_t)
  33. {
  34. #if defined(__BORLANDC__)
  35. LONG barrier = 0;
  36. ::InterlockedExchange(&barrier, 1);
  37. #elif defined(ASIO_MSVC) \
  38. && ((ASIO_MSVC < 1400) || !defined(MemoryBarrier))
  39. # if defined(_M_IX86)
  40. # pragma warning(push)
  41. # pragma warning(disable:4793)
  42. LONG barrier;
  43. __asm { xchg barrier, eax }
  44. # pragma warning(pop)
  45. # endif // defined(_M_IX86)
  46. #else
  47. MemoryBarrier();
  48. #endif
  49. }
  50. // Destructor.
  51. ~win_fenced_block()
  52. {
  53. #if defined(__BORLANDC__)
  54. LONG barrier = 0;
  55. ::InterlockedExchange(&barrier, 1);
  56. #elif defined(ASIO_MSVC) \
  57. && ((ASIO_MSVC < 1400) || !defined(MemoryBarrier))
  58. # if defined(_M_IX86)
  59. # pragma warning(push)
  60. # pragma warning(disable:4793)
  61. LONG barrier;
  62. __asm { xchg barrier, eax }
  63. # pragma warning(pop)
  64. # endif // defined(_M_IX86)
  65. #else
  66. MemoryBarrier();
  67. #endif
  68. }
  69. };
  70. } // namespace detail
  71. } // namespace asio
  72. #include "asio/detail/pop_options.hpp"
  73. #endif // defined(ASIO_WINDOWS) && !defined(UNDER_CE)
  74. #endif // ASIO_DETAIL_WIN_FENCED_BLOCK_HPP