2 // impl/system_context.ipp
3 // ~~~~~~~~~~~~~~~~~~~~~~~
5 // Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
11 #ifndef BOOST_ASIO_IMPL_SYSTEM_CONTEXT_IPP
12 #define BOOST_ASIO_IMPL_SYSTEM_CONTEXT_IPP
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18 #include <boost/asio/detail/config.hpp>
19 #include <boost/asio/system_context.hpp>
21 #include <boost/asio/detail/push_options.hpp>
26 struct system_context::thread_function
28 detail::scheduler* scheduler_;
32 boost::system::error_code ec;
37 system_context::system_context()
38 : scheduler_(use_service<detail::scheduler>(*this))
40 scheduler_.work_started();
42 thread_function f = { &scheduler_ };
43 std::size_t num_threads = detail::thread::hardware_concurrency() * 2;
44 threads_.create_threads(f, num_threads ? num_threads : 2);
47 system_context::~system_context()
49 scheduler_.work_finished();
54 void system_context::stop()
59 bool system_context::stopped() const BOOST_ASIO_NOEXCEPT
61 return scheduler_.stopped();
64 void system_context::join()
66 scheduler_.work_finished();
73 #include <boost/asio/detail/pop_options.hpp>
75 #endif // BOOST_ASIO_IMPL_SYSTEM_CONTEXT_IPP