gcc_x86_fenced_block.hpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. //
  2. // gcc_x86_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_GCC_X86_FENCED_BLOCK_HPP
  11. #define ASIO_DETAIL_GCC_X86_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(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
  20. namespace asio {
  21. namespace detail {
  22. class gcc_x86_fenced_block
  23. : private noncopyable
  24. {
  25. public:
  26. // Constructor.
  27. gcc_x86_fenced_block()
  28. {
  29. barrier();
  30. }
  31. // Destructor.
  32. ~gcc_x86_fenced_block()
  33. {
  34. barrier();
  35. }
  36. private:
  37. static int barrier()
  38. {
  39. int r = 0;
  40. __asm__ __volatile__ ("xchgl %%eax, %0" : "=m" (r) : : "memory", "cc");
  41. return r;
  42. }
  43. };
  44. } // namespace detail
  45. } // namespace asio
  46. #endif // defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
  47. #include "asio/detail/pop_options.hpp"
  48. #endif // ASIO_DETAIL_GCC_X86_FENCED_BLOCK_HPP