win_fenced_block.hpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. //
  2. // win_fenced_block.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2010 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/push_options.hpp"
  16. #include "asio/detail/push_options.hpp"
  17. #include <boost/config.hpp>
  18. #include "asio/detail/pop_options.hpp"
  19. #if defined(BOOST_WINDOWS) && !defined(UNDER_CE)
  20. #include "asio/detail/socket_types.hpp"
  21. namespace asio {
  22. namespace detail {
  23. class win_fenced_block
  24. : private noncopyable
  25. {
  26. public:
  27. // Constructor.
  28. win_fenced_block()
  29. {
  30. #if defined(BOOST_MSVC) && (BOOST_MSVC < 1400)
  31. # if defined(_M_IX86)
  32. # pragma warning(push)
  33. # pragma warning(disable:4793)
  34. LONG barrier;
  35. __asm { xchg barrier, eax }
  36. # pragma warning(pop)
  37. # endif // defined(_M_IX86)
  38. #else // defined(BOOST_MSVC) && (BOOST_MSVC < 1400)
  39. MemoryBarrier();
  40. #endif // defined(BOOST_MSVC) && (BOOST_MSVC < 1400)
  41. }
  42. // Destructor.
  43. ~win_fenced_block()
  44. {
  45. #if defined(BOOST_MSVC) && (BOOST_MSVC < 1400)
  46. # if defined(_M_IX86)
  47. # pragma warning(push)
  48. # pragma warning(disable:4793)
  49. LONG barrier;
  50. __asm { xchg barrier, eax }
  51. # pragma warning(pop)
  52. # endif // defined(_M_IX86)
  53. #else // defined(BOOST_MSVC) && (BOOST_MSVC < 1400)
  54. MemoryBarrier();
  55. #endif // defined(BOOST_MSVC) && (BOOST_MSVC < 1400)
  56. }
  57. };
  58. } // namespace detail
  59. } // namespace asio
  60. #endif // defined(BOOST_WINDOWS) && !defined(UNDER_CE)
  61. #include "asio/detail/pop_options.hpp"
  62. #endif // ASIO_DETAIL_WIN_FENCED_BLOCK_HPP