concurrency_hint.hpp 4.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. //
  2. // detail/concurrency_hint.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2018 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_CONCURRENCY_HINT_HPP
  11. #define BOOST_ASIO_DETAIL_CONCURRENCY_HINT_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. #include <boost/asio/detail/noncopyable.hpp>
  17. // The concurrency hint ID and mask are used to identify when a "well-known"
  18. // concurrency hint value has been passed to the io_context.
  19. #define BOOST_ASIO_CONCURRENCY_HINT_ID 0xA5100000u
  20. #define BOOST_ASIO_CONCURRENCY_HINT_ID_MASK 0xFFFF0000u
  21. // If set, this bit indicates that the scheduler should perform locking.
  22. #define BOOST_ASIO_CONCURRENCY_HINT_LOCKING_SCHEDULER 0x1u
  23. // If set, this bit indicates that the reactor should perform locking when
  24. // managing descriptor registrations.
  25. #define BOOST_ASIO_CONCURRENCY_HINT_LOCKING_REACTOR_REGISTRATION 0x2u
  26. // If set, this bit indicates that the reactor should perform locking for I/O.
  27. #define BOOST_ASIO_CONCURRENCY_HINT_LOCKING_REACTOR_IO 0x4u
  28. // Helper macro to determine if we have a special concurrency hint.
  29. #define BOOST_ASIO_CONCURRENCY_HINT_IS_SPECIAL(hint) \
  30. ((static_cast<unsigned>(hint) \
  31. & BOOST_ASIO_CONCURRENCY_HINT_ID_MASK) \
  32. == BOOST_ASIO_CONCURRENCY_HINT_ID)
  33. // Helper macro to determine if locking is enabled for a given facility.
  34. #define BOOST_ASIO_CONCURRENCY_HINT_IS_LOCKING(facility, hint) \
  35. (((static_cast<unsigned>(hint) \
  36. & (BOOST_ASIO_CONCURRENCY_HINT_ID_MASK \
  37. | BOOST_ASIO_CONCURRENCY_HINT_LOCKING_ ## facility)) \
  38. ^ BOOST_ASIO_CONCURRENCY_HINT_ID) != 0)
  39. // This special concurrency hint disables locking in both the scheduler and
  40. // reactor I/O. This hint has the following restrictions:
  41. //
  42. // - Care must be taken to ensure that all operations on the io_context and any
  43. // of its associated I/O objects (such as sockets and timers) occur in only
  44. // one thread at a time.
  45. //
  46. // - Asynchronous resolve operations fail with operation_not_supported.
  47. //
  48. // - If a signal_set is used with the io_context, signal_set objects cannot be
  49. // used with any other io_context in the program.
  50. #define BOOST_ASIO_CONCURRENCY_HINT_UNSAFE \
  51. static_cast<int>(BOOST_ASIO_CONCURRENCY_HINT_ID)
  52. // This special concurrency hint disables locking in the reactor I/O. This hint
  53. // has the following restrictions:
  54. //
  55. // - Care must be taken to ensure that run functions on the io_context, and all
  56. // operations on the io_context's associated I/O objects (such as sockets and
  57. // timers), occur in only one thread at a time.
  58. #define BOOST_ASIO_CONCURRENCY_HINT_UNSAFE_IO \
  59. static_cast<int>(BOOST_ASIO_CONCURRENCY_HINT_ID \
  60. | BOOST_ASIO_CONCURRENCY_HINT_LOCKING_SCHEDULER \
  61. | BOOST_ASIO_CONCURRENCY_HINT_LOCKING_REACTOR_REGISTRATION)
  62. // The special concurrency hint provides full thread safety.
  63. #define BOOST_ASIO_CONCURRENCY_HINT_SAFE \
  64. static_cast<int>(BOOST_ASIO_CONCURRENCY_HINT_ID \
  65. | BOOST_ASIO_CONCURRENCY_HINT_LOCKING_SCHEDULER \
  66. | BOOST_ASIO_CONCURRENCY_HINT_LOCKING_REACTOR_REGISTRATION \
  67. | BOOST_ASIO_CONCURRENCY_HINT_LOCKING_REACTOR_IO)
  68. // This #define may be overridden at compile time to specify a program-wide
  69. // default concurrency hint, used by the zero-argument io_context constructor.
  70. #if !defined(BOOST_ASIO_CONCURRENCY_HINT_DEFAULT)
  71. # define BOOST_ASIO_CONCURRENCY_HINT_DEFAULT -1
  72. #endif // !defined(BOOST_ASIO_CONCURRENCY_HINT_DEFAULT)
  73. // This #define may be overridden at compile time to specify a program-wide
  74. // concurrency hint, used by the one-argument io_context constructor when
  75. // passed a value of 1.
  76. #if !defined(BOOST_ASIO_CONCURRENCY_HINT_1)
  77. # define BOOST_ASIO_CONCURRENCY_HINT_1 1
  78. #endif // !defined(BOOST_ASIO_CONCURRENCY_HINT_DEFAULT)
  79. #endif // BOOST_ASIO_DETAIL_CONCURRENCY_HINT_HPP