std_fenced_block.hpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. //
  2. // detail/std_fenced_block.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2023 Christopher M. Kohlhoff (chris at kohlhoff dot com)
  6. //
  7. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  8. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  9. //
  10. #ifndef ASIO_DETAIL_STD_FENCED_BLOCK_HPP
  11. #define ASIO_DETAIL_STD_FENCED_BLOCK_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include "asio/detail/config.hpp"
  16. #include <atomic>
  17. #include "asio/detail/noncopyable.hpp"
  18. #include "asio/detail/push_options.hpp"
  19. namespace asio {
  20. namespace detail {
  21. class std_fenced_block
  22. : private noncopyable
  23. {
  24. public:
  25. enum half_t { half };
  26. enum full_t { full };
  27. // Constructor for a half fenced block.
  28. explicit std_fenced_block(half_t)
  29. {
  30. }
  31. // Constructor for a full fenced block.
  32. explicit std_fenced_block(full_t)
  33. {
  34. std::atomic_thread_fence(std::memory_order_acquire);
  35. }
  36. // Destructor.
  37. ~std_fenced_block()
  38. {
  39. std::atomic_thread_fence(std::memory_order_release);
  40. }
  41. };
  42. } // namespace detail
  43. } // namespace asio
  44. #include "asio/detail/pop_options.hpp"
  45. #endif // ASIO_DETAIL_STD_FENCED_BLOCK_HPP