123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231 |
- #ifndef BOOST_ASIO_DETAIL_SCHEDULER_HPP
- #define BOOST_ASIO_DETAIL_SCHEDULER_HPP
- #if defined(_MSC_VER) && (_MSC_VER >= 1200)
- # pragma once
- #endif
- #include <boost/asio/detail/config.hpp>
- #include <boost/system/error_code.hpp>
- #include <boost/asio/execution_context.hpp>
- #include <boost/asio/detail/atomic_count.hpp>
- #include <boost/asio/detail/conditionally_enabled_event.hpp>
- #include <boost/asio/detail/conditionally_enabled_mutex.hpp>
- #include <boost/asio/detail/op_queue.hpp>
- #include <boost/asio/detail/reactor_fwd.hpp>
- #include <boost/asio/detail/scheduler_operation.hpp>
- #include <boost/asio/detail/thread.hpp>
- #include <boost/asio/detail/thread_context.hpp>
- #include <boost/asio/detail/push_options.hpp>
- namespace boost {
- namespace asio {
- namespace detail {
- struct scheduler_thread_info;
- class scheduler
- : public execution_context_service_base<scheduler>,
- public thread_context
- {
- public:
- typedef scheduler_operation operation;
-
-
- BOOST_ASIO_DECL scheduler(boost::asio::execution_context& ctx,
- int concurrency_hint = 0, bool own_thread = true);
-
- BOOST_ASIO_DECL ~scheduler();
-
- BOOST_ASIO_DECL void shutdown();
-
- BOOST_ASIO_DECL void init_task();
-
- BOOST_ASIO_DECL std::size_t run(boost::system::error_code& ec);
-
- BOOST_ASIO_DECL std::size_t run_one(boost::system::error_code& ec);
-
- BOOST_ASIO_DECL std::size_t wait_one(
- long usec, boost::system::error_code& ec);
-
- BOOST_ASIO_DECL std::size_t poll(boost::system::error_code& ec);
-
- BOOST_ASIO_DECL std::size_t poll_one(boost::system::error_code& ec);
-
- BOOST_ASIO_DECL void stop();
-
- BOOST_ASIO_DECL bool stopped() const;
-
- BOOST_ASIO_DECL void restart();
-
- void work_started()
- {
- ++outstanding_work_;
- }
-
-
- BOOST_ASIO_DECL void compensating_work_started();
-
- void work_finished()
- {
- if (--outstanding_work_ == 0)
- stop();
- }
-
- BOOST_ASIO_DECL bool can_dispatch();
-
- BOOST_ASIO_DECL void capture_current_exception();
-
-
- BOOST_ASIO_DECL void post_immediate_completion(
- operation* op, bool is_continuation);
-
-
- BOOST_ASIO_DECL void post_immediate_completions(std::size_t n,
- op_queue<operation>& ops, bool is_continuation);
-
-
- BOOST_ASIO_DECL void post_deferred_completion(operation* op);
-
-
- BOOST_ASIO_DECL void post_deferred_completions(op_queue<operation>& ops);
-
-
- BOOST_ASIO_DECL void do_dispatch(operation* op);
-
-
- BOOST_ASIO_DECL void abandon_operations(op_queue<operation>& ops);
-
- int concurrency_hint() const
- {
- return concurrency_hint_;
- }
- private:
-
- typedef conditionally_enabled_mutex mutex;
-
- typedef conditionally_enabled_event event;
-
- typedef scheduler_thread_info thread_info;
-
- BOOST_ASIO_DECL std::size_t do_run_one(mutex::scoped_lock& lock,
- thread_info& this_thread, const boost::system::error_code& ec);
-
- BOOST_ASIO_DECL std::size_t do_wait_one(mutex::scoped_lock& lock,
- thread_info& this_thread, long usec, const boost::system::error_code& ec);
-
- BOOST_ASIO_DECL std::size_t do_poll_one(mutex::scoped_lock& lock,
- thread_info& this_thread, const boost::system::error_code& ec);
-
- BOOST_ASIO_DECL void stop_all_threads(mutex::scoped_lock& lock);
-
- BOOST_ASIO_DECL void wake_one_thread_and_unlock(
- mutex::scoped_lock& lock);
-
- class thread_function;
- friend class thread_function;
-
- struct task_cleanup;
- friend struct task_cleanup;
-
- struct work_cleanup;
- friend struct work_cleanup;
-
- const bool one_thread_;
-
- mutable mutex mutex_;
-
- event wakeup_event_;
-
- reactor* task_;
-
- struct task_operation : operation
- {
- task_operation() : operation(0) {}
- } task_operation_;
-
- bool task_interrupted_;
-
- atomic_count outstanding_work_;
-
- op_queue<operation> op_queue_;
-
- bool stopped_;
-
- bool shutdown_;
-
- const int concurrency_hint_;
-
- boost::asio::detail::thread* thread_;
- };
- }
- }
- }
- #include <boost/asio/detail/pop_options.hpp>
- #if defined(BOOST_ASIO_HEADER_ONLY)
- # include <boost/asio/detail/impl/scheduler.ipp>
- #endif
- #endif
|