fence_arch_ops_msvc_x86.hpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. * Copyright (c) 2020 Andrey Semashev
  7. */
  8. /*!
  9. * \file atomic/detail/fence_arch_ops_msvc_x86.hpp
  10. *
  11. * This header contains implementation of the \c fence_arch_operations struct.
  12. */
  13. #ifndef BOOST_ATOMIC_DETAIL_FENCE_ARCH_OPS_MSVC_X86_HPP_INCLUDED_
  14. #define BOOST_ATOMIC_DETAIL_FENCE_ARCH_OPS_MSVC_X86_HPP_INCLUDED_
  15. #include <boost/cstdint.hpp>
  16. #include <boost/memory_order.hpp>
  17. #include <boost/atomic/detail/config.hpp>
  18. #include <boost/atomic/detail/interlocked.hpp>
  19. #include <boost/atomic/detail/ops_msvc_common.hpp>
  20. #include <boost/atomic/detail/header.hpp>
  21. #ifdef BOOST_HAS_PRAGMA_ONCE
  22. #pragma once
  23. #endif
  24. namespace boost {
  25. namespace atomics {
  26. namespace detail {
  27. //! Fence operations for x86
  28. struct fence_arch_operations_msvc_x86
  29. {
  30. static BOOST_FORCEINLINE void thread_fence(memory_order order) BOOST_NOEXCEPT
  31. {
  32. if (order == memory_order_seq_cst)
  33. {
  34. // See the comment in fence_ops_gcc_x86.hpp as to why we're not using mfence here.
  35. // We're not using __faststorefence() here because it generates an atomic operation
  36. // on [rsp]/[esp] location, which may alias valid data and cause false data dependency.
  37. boost::uint32_t dummy;
  38. BOOST_ATOMIC_INTERLOCKED_INCREMENT(&dummy);
  39. }
  40. else if (order != memory_order_relaxed)
  41. {
  42. BOOST_ATOMIC_DETAIL_COMPILER_BARRIER();
  43. }
  44. }
  45. static BOOST_FORCEINLINE void signal_fence(memory_order order) BOOST_NOEXCEPT
  46. {
  47. if (order != memory_order_relaxed)
  48. BOOST_ATOMIC_DETAIL_COMPILER_BARRIER();
  49. }
  50. };
  51. typedef fence_arch_operations_msvc_x86 fence_arch_operations;
  52. } // namespace detail
  53. } // namespace atomics
  54. } // namespace boost
  55. #include <boost/atomic/detail/footer.hpp>
  56. #endif // BOOST_ATOMIC_DETAIL_FENCE_ARCH_OPS_MSVC_X86_HPP_INCLUDED_