File indexing completed on 2025-01-18 09:28:45
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_ASIO_DETAIL_STRAND_SERVICE_HPP
0012 #define BOOST_ASIO_DETAIL_STRAND_SERVICE_HPP
0013
0014 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
0015 # pragma once
0016 #endif
0017
0018 #include <boost/asio/detail/config.hpp>
0019 #include <boost/asio/io_context.hpp>
0020 #include <boost/asio/detail/mutex.hpp>
0021 #include <boost/asio/detail/op_queue.hpp>
0022 #include <boost/asio/detail/operation.hpp>
0023 #include <boost/asio/detail/scoped_ptr.hpp>
0024
0025 #include <boost/asio/detail/push_options.hpp>
0026
0027 namespace boost {
0028 namespace asio {
0029 namespace detail {
0030
0031
0032 class strand_service
0033 : public boost::asio::detail::service_base<strand_service>
0034 {
0035 private:
0036
0037 struct on_do_complete_exit;
0038
0039
0040 struct on_dispatch_exit;
0041
0042 public:
0043
0044
0045 class strand_impl
0046 : public operation
0047 {
0048 public:
0049 strand_impl();
0050
0051 private:
0052
0053 friend class strand_service;
0054 friend struct on_do_complete_exit;
0055 friend struct on_dispatch_exit;
0056
0057
0058 boost::asio::detail::mutex mutex_;
0059
0060
0061
0062
0063 bool locked_;
0064
0065
0066
0067
0068 op_queue<operation> waiting_queue_;
0069
0070
0071
0072
0073 op_queue<operation> ready_queue_;
0074 };
0075
0076 typedef strand_impl* implementation_type;
0077
0078
0079 BOOST_ASIO_DECL explicit strand_service(boost::asio::io_context& io_context);
0080
0081
0082 BOOST_ASIO_DECL void shutdown();
0083
0084
0085 BOOST_ASIO_DECL void construct(implementation_type& impl);
0086
0087
0088 template <typename Handler>
0089 void dispatch(implementation_type& impl, Handler& handler);
0090
0091
0092 template <typename Handler>
0093 void post(implementation_type& impl, Handler& handler);
0094
0095
0096 BOOST_ASIO_DECL bool running_in_this_thread(
0097 const implementation_type& impl) const;
0098
0099 private:
0100
0101 BOOST_ASIO_DECL void do_dispatch(implementation_type& impl, operation* op);
0102
0103
0104 BOOST_ASIO_DECL void do_post(implementation_type& impl,
0105 operation* op, bool is_continuation);
0106
0107 BOOST_ASIO_DECL static void do_complete(void* owner,
0108 operation* base, const boost::system::error_code& ec,
0109 std::size_t bytes_transferred);
0110
0111
0112 io_context& io_context_;
0113
0114
0115 io_context_impl& io_context_impl_;
0116
0117
0118 boost::asio::detail::mutex mutex_;
0119
0120
0121 #if defined(BOOST_ASIO_STRAND_IMPLEMENTATIONS)
0122 enum { num_implementations = BOOST_ASIO_STRAND_IMPLEMENTATIONS };
0123 #else
0124 enum { num_implementations = 193 };
0125 #endif
0126
0127
0128 scoped_ptr<strand_impl> implementations_[num_implementations];
0129
0130
0131
0132 std::size_t salt_;
0133 };
0134
0135 }
0136 }
0137 }
0138
0139 #include <boost/asio/detail/pop_options.hpp>
0140
0141 #include <boost/asio/detail/impl/strand_service.hpp>
0142 #if defined(BOOST_ASIO_HEADER_ONLY)
0143 # include <boost/asio/detail/impl/strand_service.ipp>
0144 #endif
0145
0146 #endif