gcc_x86_fenced_block.hpp 1.2 KB

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