pause.hpp 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /*
  2. * Distributed under the Boost Software License, Version 1.0.
  3. * (See accompanying file LICENSE_1_0.txt or copy at
  4. * http://www.boost.org/LICENSE_1_0.txt)
  5. *
  6. * (C) Copyright 2013 Tim Blechmann
  7. * (C) Copyright 2013 Andrey Semashev
  8. */
  9. #ifndef BOOST_ATOMIC_DETAIL_PAUSE_HPP_INCLUDED_
  10. #define BOOST_ATOMIC_DETAIL_PAUSE_HPP_INCLUDED_
  11. #include <boost/atomic/detail/config.hpp>
  12. #ifdef BOOST_HAS_PRAGMA_ONCE
  13. #pragma once
  14. #endif
  15. #if defined(_MSC_VER) && (defined(_M_AMD64) || defined(_M_IX86))
  16. extern "C" void _mm_pause(void);
  17. #if defined(BOOST_MSVC)
  18. #pragma intrinsic(_mm_pause)
  19. #endif
  20. #endif
  21. namespace boost {
  22. namespace atomics {
  23. namespace detail {
  24. BOOST_FORCEINLINE void pause() BOOST_NOEXCEPT
  25. {
  26. #if defined(_MSC_VER) && (defined(_M_AMD64) || defined(_M_IX86))
  27. _mm_pause();
  28. #elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
  29. __asm__ __volatile__("pause;");
  30. #endif
  31. }
  32. } // namespace detail
  33. } // namespace atomics
  34. } // namespace boost
  35. #endif // BOOST_ATOMIC_DETAIL_PAUSE_HPP_INCLUDED_