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 
14 #ifndef BOOST_ATOMIC_DETAIL_FENCE_ARCH_OPS_MSVC_X86_HPP_INCLUDED_
15 #define BOOST_ATOMIC_DETAIL_FENCE_ARCH_OPS_MSVC_X86_HPP_INCLUDED_
16 
17 #include <boost/cstdint.hpp>
18 #include <boost/memory_order.hpp>
19 #include <boost/atomic/detail/config.hpp>
20 #include <boost/atomic/detail/interlocked.hpp>
21 #include <boost/atomic/detail/ops_msvc_common.hpp>
22 #include <boost/atomic/detail/header.hpp>
23 
24 #ifdef BOOST_HAS_PRAGMA_ONCE
25 #pragma once
26 #endif
27 
28 namespace boost {
29 namespace atomics {
30 namespace detail {
31 
32 //! Fence operations for x86
33 struct fence_arch_operations_msvc_x86
34 {
thread_fenceboost::atomics::detail::fence_arch_operations_msvc_x8635     static BOOST_FORCEINLINE void thread_fence(memory_order order) BOOST_NOEXCEPT
36     {
37         if (order == memory_order_seq_cst)
38         {
39             // See the comment in fence_ops_gcc_x86.hpp as to why we're not using mfence here.
40             // We're not using __faststorefence() here because it generates an atomic operation
41             // on [rsp]/[esp] location, which may alias valid data and cause false data dependency.
42             boost::uint32_t dummy;
43             BOOST_ATOMIC_INTERLOCKED_INCREMENT(&dummy);
44         }
45         else if (order != memory_order_relaxed)
46         {
47             BOOST_ATOMIC_DETAIL_COMPILER_BARRIER();
48         }
49     }
50 
signal_fenceboost::atomics::detail::fence_arch_operations_msvc_x8651     static BOOST_FORCEINLINE void signal_fence(memory_order order) BOOST_NOEXCEPT
52     {
53         if (order != memory_order_relaxed)
54             BOOST_ATOMIC_DETAIL_COMPILER_BARRIER();
55     }
56 };
57 
58 typedef fence_arch_operations_msvc_x86 fence_arch_operations;
59 
60 } // namespace detail
61 } // namespace atomics
62 } // namespace boost
63 
64 #include <boost/atomic/detail/footer.hpp>
65 
66 #endif // BOOST_ATOMIC_DETAIL_FENCE_ARCH_OPS_MSVC_X86_HPP_INCLUDED_
67