]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/boost/asio/impl/system_context.ipp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / boost / asio / impl / system_context.ipp
CommitLineData
b32b8144
FG
1//
2// impl/system_context.ipp
3// ~~~~~~~~~~~~~~~~~~~~~~~
4//
92f5a8d4 5// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
b32b8144
FG
6//
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)
9//
10
11#ifndef BOOST_ASIO_IMPL_SYSTEM_CONTEXT_IPP
12#define BOOST_ASIO_IMPL_SYSTEM_CONTEXT_IPP
13
14#if defined(_MSC_VER) && (_MSC_VER >= 1200)
15# pragma once
16#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
17
18#include <boost/asio/detail/config.hpp>
19#include <boost/asio/system_context.hpp>
20
21#include <boost/asio/detail/push_options.hpp>
22
23namespace boost {
24namespace asio {
25
26struct system_context::thread_function
27{
28 detail::scheduler* scheduler_;
29
30 void operator()()
31 {
32 boost::system::error_code ec;
33 scheduler_->run(ec);
34 }
35};
36
37system_context::system_context()
92f5a8d4 38 : scheduler_(add_scheduler(new detail::scheduler(*this, 0, false)))
b32b8144
FG
39{
40 scheduler_.work_started();
41
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);
45}
46
47system_context::~system_context()
48{
49 scheduler_.work_finished();
50 scheduler_.stop();
51 threads_.join();
52}
53
54void system_context::stop()
55{
56 scheduler_.stop();
57}
58
59bool system_context::stopped() const BOOST_ASIO_NOEXCEPT
60{
61 return scheduler_.stopped();
62}
63
64void system_context::join()
65{
66 scheduler_.work_finished();
67 threads_.join();
68}
69
92f5a8d4
TL
70detail::scheduler& system_context::add_scheduler(detail::scheduler* s)
71{
72 detail::scoped_ptr<detail::scheduler> scoped_impl(s);
73 boost::asio::add_service<detail::scheduler>(*this, scoped_impl.get());
74 return *scoped_impl.release();
75}
76
b32b8144
FG
77} // namespace asio
78} // namespace boost
79
80#include <boost/asio/detail/pop_options.hpp>
81
82#endif // BOOST_ASIO_IMPL_SYSTEM_CONTEXT_IPP