fence_ops_windows.hpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. #ifndef BOOST_ATOMIC_DETAIL_FENCE_OPS_WINDOWS_HPP_INCLUDED_
  14. #define BOOST_ATOMIC_DETAIL_FENCE_OPS_WINDOWS_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 based on Windows-specific system calls or intrinsics
  28. struct fence_operations_windows
  29. {
  30. static BOOST_FORCEINLINE void thread_fence(memory_order order) BOOST_NOEXCEPT
  31. {
  32. if (order != memory_order_relaxed)
  33. {
  34. BOOST_ATOMIC_DETAIL_COMPILER_BARRIER();
  35. if (order == memory_order_seq_cst)
  36. hardware_full_fence();
  37. BOOST_ATOMIC_DETAIL_COMPILER_BARRIER();
  38. }
  39. }
  40. static BOOST_FORCEINLINE void signal_fence(memory_order order) BOOST_NOEXCEPT
  41. {
  42. if (order != memory_order_relaxed)
  43. BOOST_ATOMIC_DETAIL_COMPILER_BARRIER();
  44. }
  45. static BOOST_FORCEINLINE void hardware_full_fence() BOOST_NOEXCEPT
  46. {
  47. boost::uint32_t tmp;
  48. BOOST_ATOMIC_INTERLOCKED_INCREMENT(&tmp);
  49. }
  50. };
  51. typedef fence_operations_windows fence_operations;
  52. } // namespace detail
  53. } // namespace atomics
  54. } // namespace boost
  55. #include <boost/atomic/detail/footer.hpp>
  56. #endif // BOOST_ATOMIC_DETAIL_FENCE_OPS_WINDOWS_HPP_INCLUDED_