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_EXECUTOR_SERVICE_HPP
0012 #define BOOST_ASIO_DETAIL_STRAND_EXECUTOR_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/detail/atomic_count.hpp>
0020 #include <boost/asio/detail/executor_op.hpp>
0021 #include <boost/asio/detail/memory.hpp>
0022 #include <boost/asio/detail/mutex.hpp>
0023 #include <boost/asio/detail/op_queue.hpp>
0024 #include <boost/asio/detail/scheduler_operation.hpp>
0025 #include <boost/asio/detail/scoped_ptr.hpp>
0026 #include <boost/asio/detail/type_traits.hpp>
0027 #include <boost/asio/execution.hpp>
0028 #include <boost/asio/execution_context.hpp>
0029
0030 #include <boost/asio/detail/push_options.hpp>
0031
0032 namespace boost {
0033 namespace asio {
0034 namespace detail {
0035
0036
0037 class strand_executor_service
0038 : public execution_context_service_base<strand_executor_service>
0039 {
0040 public:
0041
0042 class strand_impl
0043 {
0044 public:
0045 BOOST_ASIO_DECL ~strand_impl();
0046
0047 private:
0048 friend class strand_executor_service;
0049
0050
0051 mutex* mutex_;
0052
0053
0054
0055
0056 bool locked_;
0057
0058
0059
0060 bool shutdown_;
0061
0062
0063
0064
0065 op_queue<scheduler_operation> waiting_queue_;
0066
0067
0068
0069
0070 op_queue<scheduler_operation> ready_queue_;
0071
0072
0073 strand_impl* next_;
0074 strand_impl* prev_;
0075
0076
0077 strand_executor_service* service_;
0078 };
0079
0080 typedef shared_ptr<strand_impl> implementation_type;
0081
0082
0083 BOOST_ASIO_DECL explicit strand_executor_service(execution_context& context);
0084
0085
0086 BOOST_ASIO_DECL void shutdown();
0087
0088
0089 BOOST_ASIO_DECL implementation_type create_implementation();
0090
0091
0092 template <typename Executor, typename Function>
0093 static void execute(const implementation_type& impl, Executor& ex,
0094 Function&& function,
0095 enable_if_t<
0096 can_query<Executor, execution::allocator_t<void>>::value
0097 >* = 0);
0098
0099
0100 template <typename Executor, typename Function>
0101 static void execute(const implementation_type& impl, Executor& ex,
0102 Function&& function,
0103 enable_if_t<
0104 !can_query<Executor, execution::allocator_t<void>>::value
0105 >* = 0);
0106
0107
0108 template <typename Executor, typename Function, typename Allocator>
0109 static void dispatch(const implementation_type& impl, Executor& ex,
0110 Function&& function, const Allocator& a);
0111
0112
0113 template <typename Executor, typename Function, typename Allocator>
0114 static void post(const implementation_type& impl, Executor& ex,
0115 Function&& function, const Allocator& a);
0116
0117
0118 template <typename Executor, typename Function, typename Allocator>
0119 static void defer(const implementation_type& impl, Executor& ex,
0120 Function&& function, const Allocator& a);
0121
0122
0123 BOOST_ASIO_DECL static bool running_in_this_thread(
0124 const implementation_type& impl);
0125
0126 private:
0127 friend class strand_impl;
0128 template <typename F, typename Allocator> class allocator_binder;
0129 template <typename Executor, typename = void> class invoker;
0130
0131
0132 BOOST_ASIO_DECL static bool enqueue(const implementation_type& impl,
0133 scheduler_operation* op);
0134
0135
0136
0137 BOOST_ASIO_DECL static bool push_waiting_to_ready(implementation_type& impl);
0138
0139
0140 BOOST_ASIO_DECL static void run_ready_handlers(implementation_type& impl);
0141
0142
0143 template <typename Executor, typename Function, typename Allocator>
0144 static void do_execute(const implementation_type& impl, Executor& ex,
0145 Function&& function, const Allocator& a);
0146
0147
0148 mutex mutex_;
0149
0150
0151 enum { num_mutexes = 193 };
0152
0153
0154 scoped_ptr<mutex> mutexes_[num_mutexes];
0155
0156
0157
0158 std::size_t salt_;
0159
0160
0161 strand_impl* impl_list_;
0162 };
0163
0164 }
0165 }
0166 }
0167
0168 #include <boost/asio/detail/pop_options.hpp>
0169
0170 #include <boost/asio/detail/impl/strand_executor_service.hpp>
0171 #if defined(BOOST_ASIO_HEADER_ONLY)
0172 # include <boost/asio/detail/impl/strand_executor_service.ipp>
0173 #endif
0174
0175 #endif