macos_fenced_block.hpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. //
  2. // detail/macos_fenced_block.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2021 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 BOOST_ASIO_DETAIL_MACOS_FENCED_BLOCK_HPP
  11. #define BOOST_ASIO_DETAIL_MACOS_FENCED_BLOCK_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include <boost/asio/detail/config.hpp>
  16. #if defined(__MACH__) && defined(__APPLE__)
  17. #include <libkern/OSAtomic.h>
  18. #include <boost/asio/detail/noncopyable.hpp>
  19. #include <boost/asio/detail/push_options.hpp>
  20. namespace boost {
  21. namespace asio {
  22. namespace detail {
  23. class macos_fenced_block
  24. : private noncopyable
  25. {
  26. public:
  27. enum half_t { half };
  28. enum full_t { full };
  29. // Constructor for a half fenced block.
  30. explicit macos_fenced_block(half_t)
  31. {
  32. }
  33. // Constructor for a full fenced block.
  34. explicit macos_fenced_block(full_t)
  35. {
  36. OSMemoryBarrier();
  37. }
  38. // Destructor.
  39. ~macos_fenced_block()
  40. {
  41. OSMemoryBarrier();
  42. }
  43. };
  44. } // namespace detail
  45. } // namespace asio
  46. } // namespace boost
  47. #include <boost/asio/detail/pop_options.hpp>
  48. #endif // defined(__MACH__) && defined(__APPLE__)
  49. #endif // BOOST_ASIO_DETAIL_MACOS_FENCED_BLOCK_HPP