123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- #ifndef BOOST_ASIO_DETAIL_STRAND_EXECUTOR_SERVICE_HPP
- #define BOOST_ASIO_DETAIL_STRAND_EXECUTOR_SERVICE_HPP
- #if defined(_MSC_VER) && (_MSC_VER >= 1200)
- # pragma once
- #endif
- #include <boost/asio/detail/config.hpp>
- #include <boost/asio/detail/atomic_count.hpp>
- #include <boost/asio/detail/executor_op.hpp>
- #include <boost/asio/detail/memory.hpp>
- #include <boost/asio/detail/mutex.hpp>
- #include <boost/asio/detail/op_queue.hpp>
- #include <boost/asio/detail/scheduler_operation.hpp>
- #include <boost/asio/detail/scoped_ptr.hpp>
- #include <boost/asio/detail/type_traits.hpp>
- #include <boost/asio/execution.hpp>
- #include <boost/asio/execution_context.hpp>
- #include <boost/asio/detail/push_options.hpp>
- namespace boost {
- namespace asio {
- namespace detail {
- class strand_executor_service
- : public execution_context_service_base<strand_executor_service>
- {
- public:
-
- class strand_impl
- {
- public:
- BOOST_ASIO_DECL ~strand_impl();
- private:
- friend class strand_executor_service;
-
- mutex* mutex_;
-
-
-
- bool locked_;
-
-
- bool shutdown_;
-
-
-
- op_queue<scheduler_operation> waiting_queue_;
-
-
-
- op_queue<scheduler_operation> ready_queue_;
-
- strand_impl* next_;
- strand_impl* prev_;
-
- strand_executor_service* service_;
- };
- typedef shared_ptr<strand_impl> implementation_type;
-
- BOOST_ASIO_DECL explicit strand_executor_service(execution_context& context);
-
- BOOST_ASIO_DECL void shutdown();
-
- BOOST_ASIO_DECL implementation_type create_implementation();
-
- template <typename Executor, typename Function>
- static void execute(const implementation_type& impl, Executor& ex,
- Function&& function,
- enable_if_t<
- can_query<Executor, execution::allocator_t<void>>::value
- >* = 0);
-
- template <typename Executor, typename Function>
- static void execute(const implementation_type& impl, Executor& ex,
- Function&& function,
- enable_if_t<
- !can_query<Executor, execution::allocator_t<void>>::value
- >* = 0);
-
- template <typename Executor, typename Function, typename Allocator>
- static void dispatch(const implementation_type& impl, Executor& ex,
- Function&& function, const Allocator& a);
-
- template <typename Executor, typename Function, typename Allocator>
- static void post(const implementation_type& impl, Executor& ex,
- Function&& function, const Allocator& a);
-
- template <typename Executor, typename Function, typename Allocator>
- static void defer(const implementation_type& impl, Executor& ex,
- Function&& function, const Allocator& a);
-
- BOOST_ASIO_DECL static bool running_in_this_thread(
- const implementation_type& impl);
- private:
- friend class strand_impl;
- template <typename F, typename Allocator> class allocator_binder;
- template <typename Executor, typename = void> class invoker;
-
- BOOST_ASIO_DECL static bool enqueue(const implementation_type& impl,
- scheduler_operation* op);
-
-
- BOOST_ASIO_DECL static bool push_waiting_to_ready(implementation_type& impl);
-
- BOOST_ASIO_DECL static void run_ready_handlers(implementation_type& impl);
-
- template <typename Executor, typename Function, typename Allocator>
- static void do_execute(const implementation_type& impl, Executor& ex,
- Function&& function, const Allocator& a);
-
- mutex mutex_;
-
- enum { num_mutexes = 193 };
-
- scoped_ptr<mutex> mutexes_[num_mutexes];
-
-
- std::size_t salt_;
-
- strand_impl* impl_list_;
- };
- }
- }
- }
- #include <boost/asio/detail/pop_options.hpp>
- #include <boost/asio/detail/impl/strand_executor_service.hpp>
- #if defined(BOOST_ASIO_HEADER_ONLY)
- # include <boost/asio/detail/impl/strand_executor_service.ipp>
- #endif
- #endif
|