/Src/Dependencies/Boost/boost/asio/detail/win_fenced_block.hpp

http://hadesmem.googlecode.com/ · C++ Header · 81 lines · 57 code · 13 blank · 11 comment · 8 complexity · 07c857fc492c3b370755ed0d4489431e MD5 · raw file

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