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_ops_windows.hpp
10  *
11  * This header contains implementation of the \c fence_operations struct.
12  */
13 
14 #ifndef BOOST_ATOMIC_DETAIL_FENCE_OPS_WINDOWS_HPP_INCLUDED_
15 #define BOOST_ATOMIC_DETAIL_FENCE_OPS_WINDOWS_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 based on Windows-specific system calls or intrinsics
33 struct fence_operations_windows
34 {
thread_fenceboost::atomics::detail::fence_operations_windows35     static BOOST_FORCEINLINE void thread_fence(memory_order order) BOOST_NOEXCEPT
36     {
37         if (order != memory_order_relaxed)
38         {
39             BOOST_ATOMIC_DETAIL_COMPILER_BARRIER();
40             if (order == memory_order_seq_cst)
41                 hardware_full_fence();
42             BOOST_ATOMIC_DETAIL_COMPILER_BARRIER();
43         }
44     }
45 
signal_fenceboost::atomics::detail::fence_operations_windows46     static BOOST_FORCEINLINE void signal_fence(memory_order order) BOOST_NOEXCEPT
47     {
48         if (order != memory_order_relaxed)
49             BOOST_ATOMIC_DETAIL_COMPILER_BARRIER();
50     }
51 
hardware_full_fenceboost::atomics::detail::fence_operations_windows52     static BOOST_FORCEINLINE void hardware_full_fence() BOOST_NOEXCEPT
53     {
54         boost::uint32_t tmp;
55         BOOST_ATOMIC_INTERLOCKED_INCREMENT(&tmp);
56     }
57 };
58 
59 typedef fence_operations_windows fence_operations;
60 
61 } // namespace detail
62 } // namespace atomics
63 } // namespace boost
64 
65 #include <boost/atomic/detail/footer.hpp>
66 
67 #endif // BOOST_ATOMIC_DETAIL_FENCE_OPS_WINDOWS_HPP_INCLUDED_
68