wait_on_address.hpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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) 2021 Andrey Semashev
  7. */
  8. /*!
  9. * \file atomic/detail/wait_on_address.hpp
  10. *
  11. * This header contains declaration of runtime detection of \c WaitOnAddress and related APIs on Windows.
  12. */
  13. #ifndef BOOST_ATOMIC_DETAIL_WAIT_ON_ADDRESS_HPP_INCLUDED_
  14. #define BOOST_ATOMIC_DETAIL_WAIT_ON_ADDRESS_HPP_INCLUDED_
  15. #include <boost/atomic/detail/config.hpp>
  16. #include <boost/memory_order.hpp>
  17. #include <boost/winapi/basic_types.hpp>
  18. #include <boost/atomic/detail/link.hpp>
  19. #include <boost/atomic/detail/once_flag.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. typedef boost::winapi::BOOL_ BOOST_WINAPI_WINAPI_CC
  28. wait_on_address_t(
  29. volatile boost::winapi::VOID_* addr,
  30. boost::winapi::PVOID_ compare_addr,
  31. boost::winapi::SIZE_T_ size,
  32. boost::winapi::DWORD_ timeout_ms);
  33. typedef boost::winapi::VOID_ BOOST_WINAPI_WINAPI_CC
  34. wake_by_address_t(boost::winapi::PVOID_ addr);
  35. extern BOOST_ATOMIC_DECL wait_on_address_t* wait_on_address;
  36. extern BOOST_ATOMIC_DECL wake_by_address_t* wake_by_address_single;
  37. extern BOOST_ATOMIC_DECL wake_by_address_t* wake_by_address_all;
  38. extern BOOST_ATOMIC_DECL once_flag wait_functions_once_flag;
  39. BOOST_ATOMIC_DECL void initialize_wait_functions() BOOST_NOEXCEPT;
  40. BOOST_FORCEINLINE void ensure_wait_functions_initialized() BOOST_NOEXCEPT
  41. {
  42. static_assert(once_flag_operations::is_always_lock_free, "Boost.Atomic unsupported target platform: native atomic operations not implemented for bytes");
  43. if (BOOST_LIKELY(once_flag_operations::load(wait_functions_once_flag.m_flag, boost::memory_order_acquire) == 0u))
  44. return;
  45. initialize_wait_functions();
  46. }
  47. } // namespace detail
  48. } // namespace atomics
  49. } // namespace boost
  50. #include <boost/atomic/detail/footer.hpp>
  51. #endif // BOOST_ATOMIC_DETAIL_WAIT_ON_ADDRESS_HPP_INCLUDED_