Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:28:37

0001 //
0002 // detail/concurrency_hint.hpp
0003 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~
0004 //
0005 // Copyright (c) 2003-2023 Christopher M. Kohlhoff (chris at kohlhoff dot com)
0006 //
0007 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0008 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0009 //
0010 
0011 #ifndef BOOST_ASIO_DETAIL_CONCURRENCY_HINT_HPP
0012 #define BOOST_ASIO_DETAIL_CONCURRENCY_HINT_HPP
0013 
0014 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
0015 # pragma once
0016 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
0017 
0018 #include <boost/asio/detail/config.hpp>
0019 #include <boost/asio/detail/noncopyable.hpp>
0020 
0021 // The concurrency hint ID and mask are used to identify when a "well-known"
0022 // concurrency hint value has been passed to the io_context.
0023 #define BOOST_ASIO_CONCURRENCY_HINT_ID 0xA5100000u
0024 #define BOOST_ASIO_CONCURRENCY_HINT_ID_MASK 0xFFFF0000u
0025 
0026 // If set, this bit indicates that the scheduler should perform locking.
0027 #define BOOST_ASIO_CONCURRENCY_HINT_LOCKING_SCHEDULER 0x1u
0028 
0029 // If set, this bit indicates that the reactor should perform locking when
0030 // managing descriptor registrations.
0031 #define BOOST_ASIO_CONCURRENCY_HINT_LOCKING_REACTOR_REGISTRATION 0x2u
0032 
0033 // If set, this bit indicates that the reactor should perform locking for I/O.
0034 #define BOOST_ASIO_CONCURRENCY_HINT_LOCKING_REACTOR_IO 0x4u
0035 
0036 // Helper macro to determine if we have a special concurrency hint.
0037 #define BOOST_ASIO_CONCURRENCY_HINT_IS_SPECIAL(hint) \
0038   ((static_cast<unsigned>(hint) \
0039     & BOOST_ASIO_CONCURRENCY_HINT_ID_MASK) \
0040       == BOOST_ASIO_CONCURRENCY_HINT_ID)
0041 
0042 // Helper macro to determine if locking is enabled for a given facility.
0043 #define BOOST_ASIO_CONCURRENCY_HINT_IS_LOCKING(facility, hint) \
0044   (((static_cast<unsigned>(hint) \
0045     & (BOOST_ASIO_CONCURRENCY_HINT_ID_MASK \
0046       | BOOST_ASIO_CONCURRENCY_HINT_LOCKING_ ## facility)) \
0047         ^ BOOST_ASIO_CONCURRENCY_HINT_ID) != 0)
0048 
0049 // This special concurrency hint disables locking in both the scheduler and
0050 // reactor I/O. This hint has the following restrictions:
0051 //
0052 // - Care must be taken to ensure that all operations on the io_context and any
0053 //   of its associated I/O objects (such as sockets and timers) occur in only
0054 //   one thread at a time.
0055 //
0056 // - Asynchronous resolve operations fail with operation_not_supported.
0057 //
0058 // - If a signal_set is used with the io_context, signal_set objects cannot be
0059 //   used with any other io_context in the program.
0060 #define BOOST_ASIO_CONCURRENCY_HINT_UNSAFE \
0061   static_cast<int>(BOOST_ASIO_CONCURRENCY_HINT_ID)
0062 
0063 // This special concurrency hint disables locking in the reactor I/O. This hint
0064 // has the following restrictions:
0065 //
0066 // - Care must be taken to ensure that run functions on the io_context, and all
0067 //   operations on the io_context's associated I/O objects (such as sockets and
0068 //   timers), occur in only one thread at a time.
0069 #define BOOST_ASIO_CONCURRENCY_HINT_UNSAFE_IO \
0070   static_cast<int>(BOOST_ASIO_CONCURRENCY_HINT_ID \
0071       | BOOST_ASIO_CONCURRENCY_HINT_LOCKING_SCHEDULER \
0072       | BOOST_ASIO_CONCURRENCY_HINT_LOCKING_REACTOR_REGISTRATION)
0073 
0074 // The special concurrency hint provides full thread safety.
0075 #define BOOST_ASIO_CONCURRENCY_HINT_SAFE \
0076   static_cast<int>(BOOST_ASIO_CONCURRENCY_HINT_ID \
0077       | BOOST_ASIO_CONCURRENCY_HINT_LOCKING_SCHEDULER \
0078       | BOOST_ASIO_CONCURRENCY_HINT_LOCKING_REACTOR_REGISTRATION \
0079       | BOOST_ASIO_CONCURRENCY_HINT_LOCKING_REACTOR_IO)
0080 
0081 // This #define may be overridden at compile time to specify a program-wide
0082 // default concurrency hint, used by the zero-argument io_context constructor.
0083 #if !defined(BOOST_ASIO_CONCURRENCY_HINT_DEFAULT)
0084 # define BOOST_ASIO_CONCURRENCY_HINT_DEFAULT -1
0085 #endif // !defined(BOOST_ASIO_CONCURRENCY_HINT_DEFAULT)
0086 
0087 // This #define may be overridden at compile time to specify a program-wide
0088 // concurrency hint, used by the one-argument io_context constructor when
0089 // passed a value of 1.
0090 #if !defined(BOOST_ASIO_CONCURRENCY_HINT_1)
0091 # define BOOST_ASIO_CONCURRENCY_HINT_1 1
0092 #endif // !defined(BOOST_ASIO_CONCURRENCY_HINT_DEFAULT)
0093 
0094 #endif // BOOST_ASIO_DETAIL_CONCURRENCY_HINT_HPP