fence_ops_windows.hpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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-2025 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 <cstdint>
  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) 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) noexcept
  41. {
  42. if (order != memory_order_relaxed)
  43. BOOST_ATOMIC_DETAIL_COMPILER_BARRIER();
  44. }
  45. static BOOST_FORCEINLINE void hardware_full_fence() noexcept
  46. {
  47. std::uint32_t tmp;
  48. BOOST_ATOMIC_INTERLOCKED_INCREMENT(&tmp);
  49. }
  50. };
  51. using fence_operations = fence_operations_windows;
  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_